diff options
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/libpod/container.go b/libpod/container.go index 454fe43ac..18f3ca5ae 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -28,6 +28,7 @@ import ( "github.com/pkg/errors" "github.com/projectatomic/libpod/libpod/driver" crioAnnotations "github.com/projectatomic/libpod/pkg/annotations" + "github.com/projectatomic/libpod/pkg/chrootuser" "github.com/sirupsen/logrus" "github.com/ulule/deepcopier" "golang.org/x/sys/unix" @@ -153,7 +154,8 @@ type ContainerConfig struct { SharedNamespaceMap map[string]string `json:"sharedNamespaces"` // Time container was created CreatedTime time.Time `json:"createdTime"` - + // User/GID to use within the container + User string `json:"user"` // TODO save log location here and pass into OCI code // TODO allow overriding of log path } @@ -440,7 +442,6 @@ func newContainer(rspec *spec.Spec, lockDir string) (*Container, error) { ctr.config.Spec = new(spec.Spec) deepcopier.Copy(rspec).To(ctr.config.Spec) - ctr.config.CreatedTime = time.Now() // Path our lock file will reside at @@ -614,6 +615,20 @@ func (c *Container) Init() (err error) { g.AddBindMount(runDirResolv, "/etc/resolv.conf", []string{"rw"}) // Bind mount hosts g.AddBindMount(runDirHosts, "/etc/hosts", []string{"rw"}) + + if c.config.User != "" { + if !c.state.Mounted { + return errors.Wrapf(ErrCtrStateInvalid, "container %s must be mounted in order to translate User field", c.ID()) + } + uid, gid, err := chrootuser.GetUser(c.state.Mountpoint, c.config.User) + if err != nil { + return err + } + // User and Group must go together + g.SetProcessUID(uid) + g.SetProcessGID(gid) + } + c.runningSpec = g.Spec() c.runningSpec.Root.Path = c.state.Mountpoint c.runningSpec.Annotations[crioAnnotations.Created] = c.config.CreatedTime.Format(time.RFC3339Nano) @@ -1078,7 +1093,7 @@ func (c *Container) mountStorage() (err error) { } } - mountPoint, err := c.runtime.storageService.StartContainer(c.ID()) + mountPoint, err := c.runtime.storageService.MountContainerImage(c.ID()) if err != nil { return errors.Wrapf(err, "error mounting storage for container %s", c.ID()) } @@ -1124,7 +1139,7 @@ func (c *Container) cleanupStorage() error { } // Also unmount storage - if err := c.runtime.storageService.StopContainer(c.ID()); err != nil { + if err := c.runtime.storageService.UnmountContainerImage(c.ID()); err != nil { return errors.Wrapf(err, "error unmounting container %s root filesystem", c.ID()) } |