Skip to content

Commit

Permalink
image lookup: do not match *any* tags
Browse files Browse the repository at this point in the history
For reasons buried in the history of Podman, looking up an untagged
image would match *any* tag of matching image.  For instance,
looking up `centos` would match a local image `centos:foobar`.
Docker only looks for `centos:latest`.

Fix: containers#11964
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Oct 19, 2021
1 parent 0144f46 commit fb34c47
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 87 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ require (
k8s.io/api v0.22.2
k8s.io/apimachinery v0.22.2
)

replace github.com/containers/common => github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ github.com/containernetworking/plugins v1.0.1 h1:wwCfYbTCj5FC0EJgyzyjTXmqysOiJE9
github.com/containernetworking/plugins v1.0.1/go.mod h1:QHCfGpaTwYTbbH+nZXKVTxNBDZcxSOplJT5ico8/FLE=
github.com/containers/buildah v1.23.1 h1:Tpc9DsRuU+0Oofewpxb6OJVNQjCu7yloN/obUqzfDTY=
github.com/containers/buildah v1.23.1/go.mod h1:4WnrN0yrA7ab0ppgunixu2WM1rlD2rG8QLJAKbEkZlQ=
github.com/containers/common v0.44.2/go.mod h1:7sdP4vmI5Bm6FPFxb3lvAh1Iktb6tiO1MzjUzhxdoGo=
github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e h1:lYazDued7KBcMq5IJzRIbX47SSLRg/yYxvM/P9LaVhE=
github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e/go.mod h1:ggZks97KCmjBcHvNTCyLc17SqdjSYoeexW7rnRt9H9Y=
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
github.com/containers/image/v5 v5.16.0/go.mod h1:XgTpfAPLRGOd1XYyCU5cISFr777bLmOerCSpt/v7+Q4=
Expand Down Expand Up @@ -934,6 +931,8 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA=
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76 h1:VrvL2rOhSVEKrYiqiK70hctsW52u4Bmqe0VelCmeMrg=
github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76/go.mod h1:Wr/HeT/HRMT82u9IwMurz32UPFRwguWgwvJYKJuHlN8=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
Expand Down
8 changes: 4 additions & 4 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ t GET libpod/images/json 200 \
iid=$(jq -r '.[0].Id' <<<"$output")

t GET libpod/images/$iid/exists 204
t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/exists 204
t GET libpod/images/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME/exists 204
t GET libpod/images/${iid}abcdef/exists 404 \
.cause="failed to find image ${iid}abcdef"

Expand Down Expand Up @@ -62,7 +62,7 @@ t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a
# Display the image history
t GET libpod/images/nonesuch/history 404

for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME; do
t GET libpod/images/$i/history 200 \
.[0].Id=$iid \
.[0].Created~[0-9]\\{10\\} \
Expand All @@ -74,9 +74,9 @@ done
# Export an image on the local
t GET libpod/images/nonesuch/get 404
t GET libpod/images/$iid/get?format=foo 500
t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/get?compress=bar 400
t GET libpod/images/$PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME/get?compress=bar 400

for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_USER/$PODMAN_TEST_IMAGE_NAME; do
t GET "libpod/images/$i/get" 200 '[POSIX tar archive]'
t GET "libpod/images/$i/get?compress=true" 200 '[POSIX tar archive]'
t GET "libpod/images/$i/get?compress=false" 200 '[POSIX tar archive]'
Expand Down
38 changes: 22 additions & 16 deletions test/e2e/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("Podman pull", func() {
found, _ := session.ErrorGrepString(expectedError)
Expect(found).To(Equal(true))

session = podmanTest.Podman([]string{"rmi", "busybox", "alpine", "testdigest_v2s2", "quay.io/libpod/cirros"})
session = podmanTest.Podman([]string{"rmi", "busybox:musl", "alpine", "alpine:latest", "libpod/cirros", "quay.io/libpod/testdigest_v2s2@sha256:755f4d90b3716e2bf57060d249e2cd61c9ac089b1233465c5c2cb2d7ee550fdb"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})
Expand All @@ -64,7 +64,7 @@ var _ = Describe("Podman pull", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"rmi", "testdigest_v2s2:20200210"})
session = podmanTest.Podman([]string{"rmi", "libpod/testdigest_v2s2:20200210"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})
Expand All @@ -74,7 +74,7 @@ var _ = Describe("Podman pull", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"rmi", "testdigest_v2s2"})
session = podmanTest.Podman([]string{"rmi", "libpod/testdigest_v2s2"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})
Expand Down Expand Up @@ -104,7 +104,13 @@ var _ = Describe("Podman pull", func() {
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"rmi", "testdigest_v2s2"})
// Pulling by digest yields a <none> tag. Hence, the short name
// won't resolve.
session = podmanTest.Podman([]string{"rmi", "libpod/testdigest_v2s2"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(1))

session = podmanTest.Podman([]string{"rmi", "quay.io/libpod/testdigest_v2s2@sha256:755f4d90b3716e2bf57060d249e2cd61c9ac089b1233465c5c2cb2d7ee550fdb"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})
Expand Down Expand Up @@ -257,17 +263,17 @@ var _ = Describe("Podman pull", func() {

podmanTest.AddImageToRWStore(cirros)
tarfn := filepath.Join(podmanTest.TempDir, "cirros.tar")
session := podmanTest.Podman([]string{"save", "-o", tarfn, "cirros"})
session := podmanTest.Podman([]string{"save", "-o", tarfn, "libpod/cirros"})
session.WaitWithDefaultTimeout()

Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"rmi", "cirros"})

session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:%s", tarfn)})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"rmi", "cirros"})
session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

Expand Down Expand Up @@ -320,17 +326,17 @@ var _ = Describe("Podman pull", func() {

podmanTest.AddImageToRWStore(cirros)
tarfn := filepath.Join(podmanTest.TempDir, "oci-cirrus.tar")
session := podmanTest.Podman([]string{"save", "--format", "oci-archive", "-o", tarfn, "cirros"})
session := podmanTest.Podman([]string{"save", "--format", "oci-archive", "-o", tarfn, "libpod/cirros"})
session.WaitWithDefaultTimeout()

Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"rmi", "cirros"})

session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"pull", fmt.Sprintf("oci-archive:%s", tarfn)})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"rmi", "cirros"})
session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})
Expand All @@ -343,10 +349,10 @@ var _ = Describe("Podman pull", func() {
os.MkdirAll(dirpath, os.ModePerm)
imgPath := fmt.Sprintf("dir:%s", dirpath)

session := podmanTest.Podman([]string{"push", "cirros", imgPath})
session := podmanTest.Podman([]string{"push", "libpod/cirros", imgPath})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"rmi", "cirros"})
session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"pull", imgPath})
Expand All @@ -366,10 +372,10 @@ var _ = Describe("Podman pull", func() {
os.MkdirAll(dirpath, os.ModePerm)
imgPath := fmt.Sprintf("oci:%s", dirpath)

session := podmanTest.Podman([]string{"push", "cirros", imgPath})
session := podmanTest.Podman([]string{"push", "libpod/cirros", imgPath})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"rmi", "cirros"})
session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
session = podmanTest.Podman([]string{"pull", imgPath})
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/rmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ var _ = Describe("Podman rmi", func() {
podmanTest.AddImageToRWStore(cirros)
session := podmanTest.Podman([]string{"rmi", "cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session).Should(Exit(1))
Expect(session.ErrorToString()).To(Equal("Error: cirros: image not known"))

session = podmanTest.Podman([]string{"rmi", "libpod/cirros"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
})

It("podman rmi all images", func() {
Expand Down Expand Up @@ -99,7 +103,7 @@ var _ = Describe("Podman rmi", func() {
Expect(setup).Should(Exit(0))
cirrosId := setup.OutputToString()

session := podmanTest.Podman([]string{"tag", "cirros", "foo:bar", "foo"})
session := podmanTest.Podman([]string{"tag", "libpod/cirros", "foo:bar", "foo"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

Expand Down
2 changes: 1 addition & 1 deletion test/python/docker/compat/constant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ALPINE = "quay.io/libpod/alpine:latest"
ALPINE_SHORTNAME = "alpine"
ALPINE_SHORTNAME = "libpod/alpine"
ALPINE_TARBALL = "alpine.tar"
BB = "quay.io/libpod/busybox:latest"
NGINX = "quay.io/libpod/alpine_nginx:latest"
Expand Down
8 changes: 4 additions & 4 deletions test/python/docker/compat/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def tearDownClass(cls):

def test_create_container(self):
# Run a container with detach mode
self.client.containers.create(image="alpine", detach=True)
self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True)
self.assertEqual(len(self.client.containers.list(all=True)), 2)

def test_create_network(self):
net = self.client.networks.create("testNetwork", driver="bridge")
ctnr = self.client.containers.create(image="alpine", detach=True)
ctnr = self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True)

# TODO fix when ready
# This test will not work until all connect|disconnect
Expand Down Expand Up @@ -188,7 +188,7 @@ def test_unpause_container(self):

def test_list_container(self):
# Add container and validate the count
self.client.containers.create(image="alpine", detach=True)
self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True)
containers = self.client.containers.list(all=True)
self.assertEqual(len(containers), 2)

Expand All @@ -209,7 +209,7 @@ def test_copy_to_container(self):
ctr: Optional[Container] = None
try:
test_file_content = b"Hello World!"
ctr = self.client.containers.create(image="alpine", detach=True, command="top")
ctr = self.client.containers.create(image=constant.ALPINE_SHORTNAME, detach=True, command="top")
ctr.start()

buff: IO[bytes] = io.BytesIO()
Expand Down
72 changes: 18 additions & 54 deletions vendor/github.com/containers/common/libimage/runtime.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/containers/common/libimage/search.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/containers/common/pkg/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ github.com/containers/buildah/pkg/rusage
github.com/containers/buildah/pkg/sshagent
github.com/containers/buildah/pkg/util
github.com/containers/buildah/util
# github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e
# github.com/containers/common v0.46.1-0.20211008123044-d846f5aaec0e => github.com/vrothberg/common v0.0.3-0.20211018125314-1039100afe76
github.com/containers/common/libimage
github.com/containers/common/libimage/manifests
github.com/containers/common/pkg/apparmor
Expand Down

0 comments on commit fb34c47

Please sign in to comment.