overlay,mount: convert lowerdir to absolute path for overlay mounts of path

When mounting paths as overlay mounts we end up passing source as is to
lowerdir options, resolve all relative paths in such cases for overlay
mounts.

Closes: https://github.com/containers/podman/issues/14797

Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
Aditya R
2022-07-01 13:49:28 +05:30
parent 01beba3667
commit d6678adc92
2 changed files with 16 additions and 1 deletions
pkg/specgen
test/e2e

@ -139,7 +139,13 @@ func GenVolumeMounts(volumeFlag []string) (map[string]spec.Mount, map[string]*Na
// This is a overlay volume // This is a overlay volume
newOverlayVol := new(OverlayVolume) newOverlayVol := new(OverlayVolume)
newOverlayVol.Destination = dest newOverlayVol.Destination = dest
newOverlayVol.Source = src // convert src to absolute path so we don't end up passing
// relative values as lowerdir for overlay mounts
source, err := filepath.Abs(src)
if err != nil {
return nil, nil, nil, errors.Wrapf(err, "failed while resolving absolute path for source %v for overlay mount", src)
}
newOverlayVol.Source = source
newOverlayVol.Options = options newOverlayVol.Options = options
if _, ok := overlayVolumes[newOverlayVol.Destination]; ok { if _, ok := overlayVolumes[newOverlayVol.Destination]; ok {

@ -678,6 +678,15 @@ VOLUME /test/`, ALPINE)
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
// Test overlay mount when lowerdir is relative path.
f, err = os.Create("hello")
Expect(err).To(BeNil(), "os.Create")
f.Close()
session = podmanTest.Podman([]string{"run", "--rm", "-v", ".:/app:O", ALPINE, "ls", "/app"})
session.WaitWithDefaultTimeout()
Expect(session.OutputToString()).To(ContainSubstring("hello"))
Expect(session).Should(Exit(0))
// Make sure modifications in container do not show up on host // Make sure modifications in container do not show up on host
session = podmanTest.Podman([]string{"run", "--rm", "-v", volumeFlag, ALPINE, "touch", "/run/test/container"}) session = podmanTest.Podman([]string{"run", "--rm", "-v", volumeFlag, ALPINE, "touch", "/run/test/container"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()