Skip to content

Commit

Permalink
Merge pull request containers#10905 from matejvasek/fix-mount
Browse files Browse the repository at this point in the history
fix: uid/gid for volume mounted to existing dir
  • Loading branch information
openshift-merge-robot authored Jul 12, 2021
2 parents f49fd06 + 6cac65c commit 561ef85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,11 @@ func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
// https://github.com/containers/podman/issues/10188
st, err := os.Lstat(filepath.Join(c.state.Mountpoint, v.Dest))
if err == nil {
if stat, ok := st.Sys().(*syscall.Stat_t); ok {
if err := os.Lchown(mountPoint, int(stat.Uid), int(stat.Gid)); err != nil {
return err
}
}
if err := os.Chmod(mountPoint, st.Mode()|0111); err != nil {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions test/python/docker/compat/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from docker import DockerClient, errors
from docker.models.containers import Container
from docker.models.images import Image

from test.python.docker import Podman
from test.python.docker.compat import common, constant
Expand Down Expand Up @@ -237,3 +238,16 @@ def test_copy_to_container(self):
if ctr is not None:
ctr.stop()
ctr.remove()

def test_mount_preexisting_dir(self):
dockerfile = (B'FROM quay.io/libpod/alpine:latest\n'
B'USER root\n'
B'RUN mkdir -p /workspace\n'
B'RUN chown 1042:1043 /workspace')
img: Image
img, out = self.client.images.build(fileobj=io.BytesIO(dockerfile))
ctr: Container = self.client.containers.create(image=img.id, detach=True, command="top",
volumes=["test_mount_preexisting_dir_vol:/workspace"])
ctr.start()
ret, out = ctr.exec_run(["stat", "-c", "%u:%g", "/workspace"])
self.assertTrue(out.startswith(b'1042:1043'), "assert correct uid/gid")

0 comments on commit 561ef85

Please sign in to comment.