Commit Graph

25 Commits

Author SHA1 Message Date
Paul Holzinger 79e7aadc50 libimage tests: try to avoid docker.io images
These images can and will change at any time and thus can break our CI
without any external changes which is very bad. The TestPush test is
failing because it expects two not one image as it converts from docker
to oci on push. However the upstream docker.io/library/alpine was
switched to an oci image thus the test started failing as the local
storage now has the same id and just stores two different tags for the
same image.

Switch to our own controlled quay.io images where possible. This is
neither complete nor do I fully understand the tests here. I did a quick
search and replace and will see what works or not.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-19 18:50:55 +01:00
tomsweeneyredhat 5d8d956a5b Update a test per c/image pull 2408
Update the libimage/pull_test.go file, changing quote in one line

Based on https://github.com/containers/image/pull/2408 from @mtrmac

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
2024-05-22 18:33:24 -04:00
Oleksandr Redko a1db72dfa0 Simplify tests by testing.TempDir instead of os.MkdirTemp
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-05 22:54:51 +02:00
Oleksandr Redko ba4c7c98bb chore: remove outdated build constraints
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 22:56:00 +02:00
Paul Holzinger 92c98a7323 libimage: add !remote tag
To prevent the podman remote client from using libimage which causes a
lot of bloat due the c/image and c/storage dependencies add the
`!remote` tag.

This will cause a hard compile time failure if the remote client ends up
pulling in libimage.

Fixes #1702

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-23 15:14:43 +02:00
Valentin Rothberg 02a72eb33e libimage: preserve optional name when pulling from OCI transport
When pulling from an OCI source, make sure to preseve the optional name.
For instance, a `podman pull oci:/tmp/foo:quay.io/foo/bar:latest` should
pull the image and name it `quay.io/foo/bar:latest`.

While at it, also fix a bug when pulling an OCI without the optional
name.  Previously, we used the path to name the image which will error
in most cases due to invalid characters (e.g., capital ones).  Hence,
apply the same trick as for the `dir` transport and generate a sha.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-30 09:19:42 +02:00
Valentin Rothberg 0519b0b94a Revert "libimage: pull: do not enforce pull if local image matches"
This reverts commit 5fbcfb4f68 as it
caused a nasty flake on Buildah [1]

[1] https://github.com/containers/buildah/pull/4527

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-01-18 15:08:53 +01:00
Valentin Rothberg 5fbcfb4f68 libimage: pull: do not enforce pull if local image matches
I verified that the test fails without the code changes.

Fixes: podman/issues/17063
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-01-11 14:55:02 +01:00
Kir Kolyshkin b951b72412 Gofumpt the code
gofumpt is a stricter version of gofmt, basically making the code more
readable, and fixing the gocritic's octalLiterar warnings like this one:

	pkg/util/util_supported.go:26:17: octalLiteral: use new octal literal style, 0o722 (gocritic)
		return (perm & 0722) == 0700
			       ^

Generated by gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-04-09 16:50:11 -07:00
Valentin Rothberg 80d883a8d7 libimage: image lookup: fix ID vs short name
When looking up an image by a short name that prefixes another image's
ID, the one matching the short name should be returned.

This means that we need to do a final lookup in the storage with the
specified name (without normalization) to continue matching short IDs.

Since it's common that users of libimage (e.g., Buildah) internally
refer to images by full ID, let's make sure that we check for that
first.  This way, we'll match full IDs on first lookup and keep the
expected performance.

Note that a name starting with `sha2556:` must be followed by a 64-byte
hex value; something we didn't check for before.

Fixes: containers/podman/issues/12761
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-02-24 14:42:37 +01:00
Valentin Rothberg 18ad7e4f77 libimage: tests: redirect docker.io to GCR mirror
Unfortunately, it the table was commented out, so it was a NOP.
Fix one test where the image being pulled was not present on
the GCR mirror.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-02-24 14:41:56 +01:00
Valentin Rothberg 8ba7e55c56 libimage: pull: platform checks for non-local platform
After containers/podman/issues/10682, we decided to always re-pull
images of non-local platforms and match *any* local image. Over time, we
refined this logic to not *always* pull the image but only if there is a
*newer* one. This has slightly changed the semantics and requires to
perform platform checks when looking up a local image. Otherwise, bogus
values would match a local image and mistakenly return it.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-12 10:15:09 +01:00
OpenShift Merge Robot e4d8d9ba27 Merge pull request #880 from vrothberg/platform-pull-policy
libimage: refine pull-policy enforcement for custom platforms
2022-01-10 17:53:09 +01:00
Valentin Rothberg e369277804 libimage: refine pull-policy enforcement for custom platforms
When pulling down an image with a user-specified custom platform, we
try to make sure that user gets what they are asking for.  An inherent
issue with multi-arch images is that there are many images in the wild
which do not get the platform right (see containers/podman/issues/10682).
That means we need to pessimistically assume that the local image is
wrong and pull the "correct" one down from the registry; in the worst case
that is redundant work but we have a guarantee of correctness.

Motivated by containers/podman/issues/12707 I had another look at the
code and found some space for optimizations.  Previously, we enforced
the pull policy to "always" but that may be too aggressive since we may
be running in an airgapped environment and the local image is correct.

With this change, we enforce the pull policy to "newer" which makes
errors non-fatal in case a local image has been found; this seems like a
good middleground between making sure we are serving the "correct" image
and user friendliness.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-10 16:27:10 +01:00
Valentin Rothberg 95872a5d60 pull: fix pulling from dir transport
Path-based transports may contain characters that are invalid for a
reference.  In such cases, we should pessimistically generate an ID
and not attempt to look at the (possibly path-based) string within the
transport.

This fixes an error when running `podman run dir:/tmp/CapitalChar` and
will prevent the same issue for the upcoming SIF transport.

Extend the tests to make sure we're not going to regress in the future.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-10 13:34:36 +01:00
Paul Holzinger 9255c2eec0 Revert "pull: fix pulling from dir transport"
This reverts commit 913fe2c9cb.

Both podman and buildah CI are failing because of this change. Since
Valentin is out and I need to get my network changes merged I want to
revert this for now.

Example failure from buildah test:
```
[+2471s] not ok 507 pull-from-local-directory
[+2471s] # (from function `assert' in file ./helpers.bash, line 342,
[+2471s] #  from function `expect_output' in file ./helpers.bash, line 369,
[+2471s] #  in test file ./pull.bats, line 89)
[+2471s] #   `expect_output --substring "localhost${TESTDIR}/buildahtest:latest"' failed
[+2471s] # /var/tmp/go/src/github.com/containers/buildah/tests /var/tmp/go/src/github.com/containers/buildah/tests
[+2471s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah pull --signature-policy /var/tmp/go/src/github.com/containers/buildah/tests/./policy.json alpine
[+2471s] # Resolved "alpine" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
[+2471s] # Trying to pull docker.io/library/alpine:latest...
[+2471s] # Getting image source signatures
[+2471s] # Copying blob sha256:9d16cba9fb961d1aafec9542f2bf7cb64acfc55245f9e4eb5abecd4cdc38d749
[+2471s] # Copying blob sha256:9d16cba9fb961d1aafec9542f2bf7cb64acfc55245f9e4eb5abecd4cdc38d749
[+2471s] # Copying config sha256:961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
[+2471s] # Writing manifest to image destination
[+2471s] # Storing signatures
[+2471s] # 961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
[+2471s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah push --signature-policy /var/tmp/go/src/github.com/containers/buildah/tests/./policy.json docker.io/library/alpine:latest dir:/var/tmp/buildah_tests.c47drl/buildahtest
[+2471s] # Getting image source signatures
[+2471s] # Copying blob sha256:03901b4a2ea88eeaad62dbe59b072b28b6efa00491962b8741081c5df50c65e0
[+2471s] # Copying config sha256:961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
[+2471s] # Writing manifest to image destination
[+2471s] # Storing signatures
[+2471s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah rmi alpine
[+2471s] # untagged: docker.io/library/alpine:latest
[+2471s] # 961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
[+2471s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah pull --signature-policy /var/tmp/go/src/github.com/containers/buildah/tests/./policy.json dir:/var/tmp/buildah_tests.c47drl/buildahtest
[+2471s] # Getting image source signatures
[+2471s] # Copying blob sha256:f3ac2f9422602f687109cc39270c47da673c6a61b5ca4958bc232adbc65912e7
[+2471s] # Copying config sha256:961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
[+2471s] # Writing manifest to image destination
[+2471s] # Storing signatures
[+2471s] # 961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4
[+2471s] # $ /var/tmp/go/src/github.com/containers/buildah/tests/./../bin/buildah images --format {{.Name}}:{{.Tag}}
[+2471s] # <none>:<none>
[+2471s] # #/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
[+2471s] # #|     FAIL: buildah images --format {{.Name}}:{{.Tag}}
[+2471s] # #| expected: =~ 'localhost/var/tmp/buildah_tests.c47drl/buildahtest:latest'
[+2471s] # #|   actual:    '<none>:<none>'
[+2471s] # #\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-07 14:18:32 +01:00
Valentin Rothberg 281201d87d libimage: normalize platform
Buildah, containers and probably other container engines are normalizing
the platform parameters to support common values.  For instance, "x86_64"
is normalized to the OCI conformant "amd64".

Use the same normalization when copying images and looking up local
images.  Also add some debug logs to facilitate future debugging.

Fixes: containers/podman/issues/12680
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-12-23 13:09:03 +01:00
Valentin Rothberg 913fe2c9cb pull: fix pulling from dir transport
Path-based transports may contain characters that are invalid for a
reference.  In such cases, we should pessimistically generate an ID
and not attempt to look at the (possibly path-based) string within the
transport.

This fixes an error when running `podman run dir:/tmp/CapitalChar` and
will prevent the same issue for the upcoming SIF transport.

Extend the tests to make sure we're not going to regress in the future.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-12-20 14:55:36 +01:00
Daniel J Walsh 1cb44dc5a1 If we tell system to never pull we should not pull
Fixes: https://github.com/containers/buildah/issues/3596

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-30 15:00:17 -05:00
Valentin Rothberg a5f253cddf libimage: enforce "latest" tag when looking up images
Make sure to enforce the "latest" tag when looking up images in the
local storage.  Also make sure that digested short-names are subject
to the extended digest lookups.

Context: containers/podman/issues/11964
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-11-22 15:19:38 +01:00
Valentin Rothberg 369aaa4178 libimage: pull: normalize docker-daemon
Normalize images pulled from the docker-daemon transport to docker.io
and not to localhost.  That preserves previous behavior of Podman.

Also fix a parsing bug in the pull code that was revealed while testing
the changes; parsing errors should be returned if there is a matching
transport without falling through to pulling the input string as an
image from a registry.

Context: containers/podman/issues/10998
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-21 13:48:58 +02:00
Valentin Rothberg 0d5e8e5bac libimage: LookupImage: remove IgnorePlatform option
When writing LookupImage, I thought that it's a good idea to always
attempt to match an image against the local (or requested) platform.
The use case I had in mind is multi-arch support:

`$ podman run image` should only match `image` if it matches the local
platform.  We may have previously pulled `image` for another
architecture.

The core criteria for these checks is that images set their platform
(arch/os/variant) correctly.  As it turned out that is not the case.
We recently performed a number of fixes to better support multi-arch
images and this change should put the last nail in the coffin.

Hence, entirely remove the `IgnorePlatform` option and only perform
platform matches if the arch, os or variant is specified explicitly via
the LookupImageOptions or the runtime's system context (as Buildah likes
to do it).

Note that this is a breaking change, so I need to update Buildah and
Podman.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-02 14:14:56 +02:00
Valentin Rothberg eb9abbf94a libimage: lookup images by custom platform
Allow for looking up images via customizable arch, os and variant.
This prevents `podman run --arch=xxx` from redundantly pulling down the
image if needed.

Context: containers/podman/issues/10648
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-11 16:27:52 +02:00
Valentin Rothberg a56cf8556e support tag@digest notation
For the sake of Docker compatibility, support the tag@digest notation.
In that case, the tag is stripped off the reference and the digest is
the sole source of truth.

Add a number of tests to make sure we're behaving as expected.

Context: containers/podman/issues/6721
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-26 16:39:03 +02:00
Valentin Rothberg 3b721f41df libimage: add unit tests
This adds tests pulling and a framwork that can be used to add more
tests in the future.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-06 15:41:33 +02:00