diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2020-07-30 22:59:45 +0200 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-07-31 11:45:58 -0400 |
commit | 2d715405182f67937c152d4cd74b282a2e6ca786 (patch) | |
tree | 8165637a26887456238e4f0178b9faf44e76db4b /libpod/container_internal.go | |
parent | 2cc9af369290428ca3d5e96bee5b65262b57a1f7 (diff) | |
download | podman-2d715405182f67937c152d4cd74b282a2e6ca786.tar.gz podman-2d715405182f67937c152d4cd74b282a2e6ca786.tar.bz2 podman-2d715405182f67937c152d4cd74b282a2e6ca786.zip |
volumes: do not recurse when chowning
keep the file ownership when chowning and honor the user namespace
mappings.
Closes: https://github.com/containers/podman/issues/7130
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
<MH: Fixed conflicts from cherry pick>
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index e277a88c5..675311461 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1521,9 +1521,6 @@ func (c *Container) chownVolume(volumeName string) error { return errors.Wrapf(err, "error retrieving named volume %s for container %s", volumeName, c.ID()) } - uid := int(c.config.Spec.Process.User.UID) - gid := int(c.config.Spec.Process.User.GID) - vol.lock.Lock() defer vol.lock.Unlock() @@ -1534,22 +1531,34 @@ func (c *Container) chownVolume(volumeName string) error { if vol.state.NeedsChown { vol.state.NeedsChown = false + + uid := int(c.config.Spec.Process.User.UID) + gid := int(c.config.Spec.Process.User.GID) + + if c.config.IDMappings.UIDMap != nil { + p := idtools.IDPair{ + UID: uid, + GID: gid, + } + mappings := idtools.NewIDMappingsFromMaps(c.config.IDMappings.UIDMap, c.config.IDMappings.GIDMap) + newPair, err := mappings.ToHost(p) + if err != nil { + return errors.Wrapf(err, "error mapping user %d:%d", uid, gid) + } + uid = newPair.UID + gid = newPair.GID + } + vol.state.UIDChowned = uid vol.state.GIDChowned = gid if err := vol.save(); err != nil { return err } - err := filepath.Walk(vol.MountPoint(), func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if err := os.Lchown(path, uid, gid); err != nil { - return err - } - return nil - }) - if err != nil { + + mountPoint := vol.MountPoint() + + if err := os.Lchown(mountPoint, uid, gid); err != nil { return err } } |