Skip to content

Commit

Permalink
Use cleaned destination path for indexing image volumes
Browse files Browse the repository at this point in the history
We use filepath.Clean() to remove trailing slashes to ensure that
when we supercede image mounts with mounts from --volume and
--mount, paths are consistent when we compare. Unfortunately,
while we used the cleaned path for the destination in the mount,
it was accidentally not used to index the maps that we use to
identify what to supercede, so our comparisons might be thrown
off by trailing slashes and similar.

Fixes containers#5219

Signed-off-by: Matthew Heon <[email protected]>
  • Loading branch information
mheon authored and snj33v committed May 31, 2020
1 parent 9a702d0 commit 31cdc13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/spec/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ func (config *CreateConfig) getImageVolumes() (map[string]spec.Mount, map[string

for vol := range config.BuiltinImgVolumes {
cleanDest := filepath.Clean(vol)
logrus.Debugf("Adding image volume at %s", cleanDest)
if config.ImageVolumeType == "tmpfs" {
// Tmpfs image volumes are handled as mounts
mount := spec.Mount{
Expand All @@ -747,13 +748,13 @@ func (config *CreateConfig) getImageVolumes() (map[string]spec.Mount, map[string
Type: TypeTmpfs,
Options: []string{"rprivate", "rw", "nodev", "exec"},
}
mounts[vol] = mount
mounts[cleanDest] = mount
} else {
// Anonymous volumes have no name.
namedVolume := new(libpod.ContainerNamedVolume)
namedVolume.Options = []string{"rprivate", "rw", "nodev", "exec"}
namedVolume.Dest = cleanDest
volumes[vol] = namedVolume
volumes[cleanDest] = namedVolume
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/e2e/run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"github.com/onsi/gomega/gexec"
)

var VolumeTrailingSlashDockerfile = `
FROM alpine:latest
VOLUME /test/`

var _ = Describe("Podman run with volumes", func() {
var (
tempdir string
Expand Down Expand Up @@ -481,4 +485,20 @@ var _ = Describe("Podman run with volumes", func() {
Expect(len(outputArr)).To(Equal(1))
Expect(strings.Contains(outputArr[0], fileName)).To(BeTrue())
})

It("Podman mount over image volume with trailing /", func() {
image := "podman-volume-test:trailing"
podmanTest.BuildImage(VolumeTrailingSlashDockerfile, image, "false")

ctrName := "testCtr"
create := podmanTest.Podman([]string{"create", "-v", "/tmp:/test", "--name", ctrName, image, "ls"})
create.WaitWithDefaultTimeout()
Expect(create.ExitCode()).To(Equal(0))

data := podmanTest.InspectContainer(ctrName)
Expect(len(data)).To(Equal(1))
Expect(len(data[0].Mounts)).To(Equal(1))
Expect(data[0].Mounts[0].Source).To(Equal("/tmp"))
Expect(data[0].Mounts[0].Destination).To(Equal("/test"))
})
})

0 comments on commit 31cdc13

Please sign in to comment.