Skip to content

Commit

Permalink
Merge pull request containers#22245 from giuseppe/do-not-chown-again-…
Browse files Browse the repository at this point in the history
…with-U

container: do not chown to dest target with U
  • Loading branch information
openshift-merge-bot[bot] authored Apr 3, 2024
2 parents 33b60f1 + 519a66c commit 0106e59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 6 additions & 1 deletion libpod/container_internal_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2882,8 +2882,13 @@ func (c *Container) fixVolumePermissions(v *ContainerNamedVolume) error {
return err
}

// Make sure the new volume matches the permissions of the target directory.
// Make sure the new volume matches the permissions of the target directory unless 'U' is
// provided (since the volume was already chowned in this case).
// https://github.com/containers/podman/issues/10188
if slices.Contains(v.Options, "U") {
return nil
}

st, err := os.Lstat(filepath.Join(c.state.Mountpoint, v.Dest))
if err == nil {
if stat, ok := st.Sys().(*syscall.Stat_t); ok {
Expand Down
15 changes: 6 additions & 9 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,6 @@ VOLUME /test/`, ALPINE)
Skip("cannot find mappings for the current user")
}

if os.Getenv("container") != "" {
Skip("Overlay mounts not supported when running in a container")
}
if isRootless() {
if _, err := exec.LookPath("fuse_overlay"); err != nil {
Skip("Fuse-Overlayfs required for rootless overlay mount test")
}
}

mountPath := filepath.Join(podmanTest.TempDir, "secrets")
err = os.Mkdir(mountPath, 0755)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -759,6 +750,12 @@ VOLUME /test/`, ALPINE)
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(ContainSubstring("888:888"))

// test with an existing directory in the image
session = podmanTest.Podman([]string{"run", "--rm", "--user", "881:882", "-v", "NAMED-VOLUME:/mnt:U", ALPINE, "stat", "-c", "%u:%g", "/mnt"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(ContainSubstring("881:882"))

session = podmanTest.Podman([]string{"run", "--rm", "--user", "888:888", "--userns", "auto", "-v", vol, ALPINE, "stat", "-c", "%u:%g", dest})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expand Down

0 comments on commit 0106e59

Please sign in to comment.