Commit Graph

82 Commits

Author SHA1 Message Date
flouthoc 8e2888e726 copier: modify newCopier for golangci-lint
Fix linter error
```
Error: libimage/copier.go:180:51: `(*Runtime).newCopier` - `reportResolvedReference` always receives `nil` (unparam)
```

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-03-20 13:38:06 -07:00
flouthoc 2146c492dc pull,load: use *Image instead of re-resolving via name
Following commit fixes a `race` condition in `libimage` because in `Pull(`
after performing `copy` from remote sources it agains attempts to resolve
image via `LookupImage`, any operation between `copy` and `LookupImage` can remove
`name` from the recently pulled image. Causing race in builds.

This issue was discoverd while working on PR https://github.com/containers/buildah/pull/5971
```
buildah build -t test --jobs=2 --skip-unused-stages=false .
```

Containerfile
```
FROM quay.io/jitesoft/alpine
RUN arch
FROM --platform=linux/arm64 quay.io/jitesoft/alpine AS foreign
```

Following commit also addresses the commit 88f60eeeb3
by performing the neccessary refactor.

No functional change in public exposed API, exisiting tests should pass as-is.
[NO NEW TESTS NEEDED]

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-03-20 13:37:59 -07:00
Miloslav Trmač f05e2cf05e Reliably return the correct image ID from pull
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-11-05 19:42:11 +01:00
Miloslav Trmač d90a20404b Improve image ID lookup for pulled images
- Use the image's repo, not just the digest, to be more precise
  when zstd:chunked ambiguities are involved
- Remove the multi-platform lookup code, it is never used

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:13:44 +02:00
Miloslav Trmač 7daccce4dc Only return one image ID (/name?) from copySingleImageFromRegistry
... because we now never return more than one.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:13:44 +02:00
Miloslav Trmač 810971b184 Only return one image ID from imagesIDForManifest
There's no benefit in returning multiple matches;
we ideally want to return exactly the image we pulled,
but even if that were hard, returning multiple guesses
is not what the user asked for.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:10:53 +02:00
Miloslav Trmač 486404691b Don't fall back if imagesIDsForManifest fails
If we can't find the image we have just pulled by digest, the image
was probably already removed, and returning candidate.Value
could only possibly point at a _different_ image with the same
tag.

Instead, fail immediately.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:10:53 +02:00
Miloslav Trmač 88f60eeeb3 Add a FIXME about unstable name lookups
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 22:10:53 +02:00
Brent Baude 3c70899eda Export Copier to support OCI artifacts
To support OCI artifacts in Podman, we need to export the Copier type
and create an exported constructor (NewCopier).  Additionally, the
actual copy and close methods are now exported.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-23 12:31:57 -05:00
Brent Baude 39e5b339ec Revert "Export portions of Copier"
This reverts commit 76e87a92ce.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-23 09:58:53 -05:00
Brent Baude 76e87a92ce Export portions of Copier
To support artifact handling, we need to export some of the methods for
copier. The Copy and Close method have been exported.  In addition, a
new constructor that is exported was created so we could introduce a
different SystemContext for artifacts.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-09-19 13:32:10 -05:00
Colin Walters 3de8d66026 libimage: Add err context for normalizeTaggedDigestedString
Before, here's what happens if you forget a `-v` in your bind mount for example:

```
$ podman run /dev:/dev docker.io/busybox echo hello
Error: invalid reference format
$
```

After:

```
$ podman run /dev:/dev docker.io/busybox echo hello
Error: parsing reference "/dev:/dev": invalid reference format
```

This error prefixing is common in other callers.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-04-26 08:43:35 -04:00
Nalin Dahyabhai 2f0cf99f30 Add a libimage.Runtime.LoadReference for loading images
Add a LoadReference() method, for when we already know what format the
local image should be treated as, and we don't have the patience for
Load()'s guessing at it.

Teach libimage.Runtime.copyFromDefault() about the docker transport.
It's already required at build-time because it's directly referenced
elsewhere in the same file.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-03-25 09:40:54 -04:00
Paul Holzinger d240865a45 lint: update golangci-lint to v1.56.2
Adds a couple of new linters with many new warnings:
- perfsprint (fixed in code, excluded for tests)
- revive (fix the problems, disabled the dot import check as we use it
  for ginkgo)
- inamedparam (disabled because it is opinionated)
- testifylint (great linter but we have like 1000+ issues that I have no
  time fixing now)

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-05 18:10:32 +01:00
Daniel J Walsh b956dbdefa Report error events on pull failures
Fixes: https://github.com/containers/podman/issues/21458

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-29 11:32:41 -05:00
Daniel J Walsh b39e81e0e2 Default Pull/Push to use containers.conf Retry, RetryDelay
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-22 08:13:45 -05:00
Oleksandr Redko 2c6e273d55 linters: enable contextcheck
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-06 20:28:57 +02:00
openshift-merge-bot[bot] ce424557dd Merge pull request #1781 from alexandear/fix-typos-across-repo
Fix typos across repo; extend codespell config
2024-01-04 11:12:20 +00:00
Oleksandr Redko 3cc2a76ae9 Fix typos across repo; extend codespell config
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 23:38:47 +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 ab8db10408 linters: enable whitespace
Not changing the world but useful hygiene.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-01 11:14:23 +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 91b87d2bde libimage: pull: increase timeout running under systemd
Set the `EXTEND_TIMEOUT_USEC` over DBUS when pulling an image from a
registry and when running under systemd.  This will prevent a frequent
issue when running Quadlets and exceeding the default systemd start
timeout of 90 seconds when pulling the image takes too long.

Fixes: containers/podman/issues/18353
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-23 14:38:11 +02:00
Valentin Rothberg 5524133c26 libimage: harden lookup by digest
When looking up an image by digest, make sure that the entire repository
of the specified value is considered.  Previously, both the repository
and the tag have been ignored and we looked for _some_ image with a
matching digest.

As outlined in #1248, Docker stopped ignoring the repository with
version v20.10.20 (Oct '22) which is a compelling reason to do the same.

To be clear, previously `something@digest` would look for any image with
`digest` while `something` is entirely ignored.  With this change, both
`something` and `digest` must match the image.

This change breaks two e2e tests in Podman CI which relied on the
previous behavior.  There is a risk of breaking users but there is a
strong security argument to perform this change:  if the repository does
not match the (previously) returned issue, there is a fair chance of a
user error.

Fixes: containers/common#1248
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-30 10:09:48 +02:00
Daniel J Walsh 252b3036f5 When using additional stores, report id only once
Currently if you setup additional stores and pull the same
image that exists in additionalstore, podman ends up reporting
the ID twice.

Fixes: https://github.com/containers/podman/issues/18647

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-06-12 13:58:44 -04:00
Valentin Rothberg 0b3cfa2466 libimage: pull events: set input name
Set the input name in the names of pull events.  Otherwise, we'll loose
the transport information which also breaks Podman's system tests.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-02-21 10:15:42 +01:00
Valentin Rothberg 77a316f43d libimage: make sure all events have an ID
Make sure that all image events have an ID. I noticed that some (e.g.,
pull) did not include the ID which is confusing and renders the events
less useful.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-02-13 13:58:18 +01: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
Mikhail Khachayants 95faf07a1a Fix empty system context when copy image from oci-archive transport
Images runtime used the OCI archive transport with an empty system context,
so such environment variables from user like TMDDIR were ignored.

Signed-off-by: Mikhail Khachayants <tyler92@inbox.ru>
2022-10-10 13:59:59 +03:00
Daniel J Walsh a5698c8b06 Fix stutters
Podman adds an Error: to every error message. So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-08-27 08:05:03 -04:00
Sascha Grunert 426d69c00f Switch to golang native error wrapping
`github.com/pkg/errors` is deprecated since quite some time so we now
use the native error wrapping for more idiomatic golang.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-12 10:54:07 +02:00
Valentin Rothberg fa2e6ee0bf libimage: normalize platforms correctly
Use containerd's platform package for platform checks. While the OCI
image spec requires the platform values to conform with GOOS and GOARCH
definitions of Go' runtime package, the values of uname are used by
convention.  Supporting these values silences annoying false-positive
warnings.

Fixes: #containers/podman/issues/14669
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-06-28 13:44:02 +02:00
Valentin Rothberg a06ba9fc05 libimage: image lookup: check platform
Check the platform when looking up images locally.  When the user
requested a custom platform and a local image doesn't match, the
image will be discarded.  Otherwise a warning will be emitted.

Also refactor the code to make it more maintainable in the future.

Fixes: containers/podman/issues/12682
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-31 16:59:11 +02:00
Valentin Rothberg 4156e574f5 libimage: pull: warn if platforms do not match
Warn when the platform of a pulled image does not match the
user-specified platform.  The checks are only performed if the user
requested a custom platform.

Do not error out and warn only since there are many images in the wild
that claim to be of another architecture.  An error would break existing
workloads; we did that once and had to revert immediately.

Fixes: containers/podman/issues/14293
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-30 14:25:58 +02:00
Valentin Rothberg 61ffc5a08a libimage: pull: remove TODO
While in theory it would be optimal if the shortnames package returned
such an error, there is no need for it in practice since others error
sources such as an invalid input name would already error out before.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-25 11:10:09 +02:00
Valentin Rothberg 4422f38959 libimage: load: close reader
Close the reader of an Docker archive to make sure that artifacts in
TMPDIR are removed.

Closes: github.com/containers/podman/issues/14287
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-19 17:08:48 +02:00
Paul Holzinger 63d80d9e2d enable prealloc and makezero linters
Wherever possible slices should be allocated with the correct capacity to
avoid unnecessary memory allocations.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-05-09 14:39:51 +02: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 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
Valentin Rothberg c08c28e17c load: support buildkit archives
Archives generated with buildkit have some kind of "hybrid" layout which
is the same for OCI and Docker archives.  OCI ones ship with a
manifest.json but set the image's reference in the index.json but in a
custom annotation and not the one the OCI image spec wants.  Archives
in the Docker format set the reference in `RepoTags` of the
manifest.json.

To support these archives, simply look for the custom containerd
annotation *and* change the order back to give OCI archives precedence.

Fixes: containers/podman/issues/12560
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-12-10 13:24:05 +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 cbb69a9e64 libimage: Pull: fix logs
Exchange two debug logs in the pull-never policy.  Those were probably
not moved along with the code and could lead to confusions when reading
debug logs.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-10-08 10:34:48 +02:00
Valentin Rothberg 6dcfb65360 (*libimage.Image).HasDifferentDigest: add authentication
Allow for passing down credentials when comparing a local image with a
remote one.  The linked BZ relates to a regression in `podman auto-update`
but while reading the code I noticed it's also impacting pull policies.

BZ: bugzilla.redhat.com/show_bug.cgi?id=2000943
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-09-20 10:44:12 +02:00
Valentin Rothberg f1f1300c77 pull: fallthrough for registry parsing errors
Pull is a bit of an "one size fits all" API to keep complexity away from
callers and hide everything behind the interface.

Commit 369aaa4178 recently altered the error reporting to when pulling
fromt the `docker-daemon` transport which in turn caused a regression in
Buildah CI when pulling `docker:latest`.  Such an input would cause a
parsing error in the `docker:`.

Fix the regression by relaxing the stricter error reporting introduced
by commit 369aaa4178 and make an exception for the `docker:`
transport.  Note that invalid input would still be caught a couple of
lines below.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-02 09:14:43 +02:00