Commit Graph

69 Commits

Author SHA1 Message Date
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
Hironori Shiina 784a067462 Use authfile in options to search image
An authfile path set by `podman search --authfile` is passed in
`SearchOptions`. This fix uses this authfile for accessing
registries.

Signed-off-by: Hironori Shiina <shiina.hironori@jp.fujitsu.com>
2021-07-29 15:09:00 -04:00
Daniel J Walsh db09996f90 Merge pull request #687 from nalind/locker-for-image
Add libimage/manifests.LockerForImage()
2021-07-26 10:59:08 -04:00
Nalin Dahyabhai 73ed145c72 Add and use libimage.Runtime.imageIDsForManifest()
When copying images into local storage, parse the manifest of the copied
image and then look up the IDs of the matching image.

There's a short period of time, between when we copy the image into
local storage and when we subsequently go to look for it using the name
that we specified for it when we copied it, when the name we wanted to
assign to the image could have been assigned to another image by another
process.

The manifest that we copied as part of the image that we copied will
still be in the right image regardless, and we can use that to find the
image's ID, and from there fill out our own Image structure that we
return to our caller.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-07-23 15:09:28 -04:00
Nalin Dahyabhai 054c4db996 Add libimage/manifests.LockerForImage()
Add a LockerForImage() function that allocates and returns a file-based
lock for an image record that we're using to hold a manifest list.
Without some locking mechanism, two processes that wish to update a list
at roughly the same time can't do so without risk of accidentally
discarding one or the other set of changes.

Multiple processes that merely want to read the list can already safely
do so; only cases with multiple writers that need to bother with using
this function.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-07-23 13:12:17 -04: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 cbacc0b621 libimage: report all removed images
Fix a bug where not all removed images were actually reported as such.
A regression test will be added to Podman.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-20 11:17:11 +02:00
Valentin Rothberg 53289d5ab2 libruntime: layer tree: handle empty images
Handle images without physical layers when constructing the layer tree
and store them in a dedicated slice that can later on be consulted when
computing parent/child relations.

Such "empty" images can be built with, for instance, with the following
Dockerfile:

```
FROM scratch
ENV test1=test1
ENV test2=test2
```

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-20 11:00:21 +02:00
Valentin Rothberg e983ccadc6 refine dangling filters
As discussed in github.com/containers/podman/issues/10832 the definition
of a "dangling" image in Podman has historically been incorrect.  While
the Docker docs describe a dangling image as an image without a tag, and
Podman implemented the filters as such, Docker actually implemented the
filters for images without a tag and without children.

Refine the dangling filters and hence `IsDangling()` to only return true
if an image is untagged and has no children.

Also correct the comments of `IsIntermediate()`.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-20 10:50:46 +02:00
Nalin Dahyabhai ef742512d4 libimage.RuntimeFromStore(): stop overriding the BlobInfoCache location
When it was first introduced, the blob info cache's location didn't
change from the system-wide default location when we were running in
rootless mode, so we started setting its location ourselves to avoid
triggering permissions errors when updating it.

The image library has since started taking into account that it was
running in rootless mode, but its hardwired default isn't the same as
the one we were setting, so we ended up creating a second cache file.

Stop doing that.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-07-19 14:52:47 -04:00
Valentin Rothberg d21d026d55 pull with custom platform: handle "localhost/"
Commit 37f6e92ece enforced the pull policy to "always" when a custom
platform was specified.  The reason for always pulling is that many
multi-arch images are broken; wrong configs, wrong platforms, etc.

We cannot perform reliable platform checks.  While we may to have to
revisit this strategy in the future, it is more important to keep
existing workloads running; a bit between a rock and hard place.

This change complements commit 37f6e92ecef5: if attempt to pull an image
that resolves to "localhost/", set the pull policy "newer" instead of
"always" such that the image may be used instead of erroring out.
Ultimately to preserve previous behavior.

Context: containers/podman/issues/10914
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-16 15:01:40 +02:00
Valentin Rothberg f6c449a257 libimage: image tree: fix nil deref
(*Image)Tree() hit a nil deref when traversing the children of an image
without a physical layer.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-09 15:11:04 +02:00
OpenShift Merge Robot cb13a4a484 Merge pull request #664 from vrothberg/arch-arch
libimage: LookupImage: remove IgnorePlatform option
2021-07-07 05:45:08 -04:00
Valentin Rothberg 1360dbce52 libimage: import: fix tags
When importing, first create the image and tag it afterwards.  This also
makes sure that an imported image *without* a tag is correctly listed as
"<none>".  Previously, such images were tagged as
"docker.io/library/sha256:$ID" (inherited from older Podman code).

Context: containers/podman/issues/10854
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-06 14:42:50 +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 cfa6dfa4bc libimage: force internal image lookups to ignore arch
Stop the whack-a-mole selectively patching multi-arch issues by forcing
all internal image lookups to ignore the platform.

In retrospect, the `IgnorePlatform` options for image lookups was a
mistake and I will remove it soon but for now, let's just patch
something we can backport to the v0.38 branch.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-01 14:40:55 +02:00
OpenShift Merge Robot 7a3358e1f4 Merge pull request #655 from vrothberg/events-fix
libimage: events: deferred write
2021-06-30 05:21:22 -04:00
Valentin Rothberg 17e5b89608 libimage: events: deferred write
Some users rely on events being written *after* the operation ran.
Hence, defer all event writes.

Context: containers/podman/issues/10812
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-30 10:35:08 +02:00
Valentin Rothberg 37f6e92ece pull: custom platform: do not use local image name
Do not use the name of the locally resolved image when pulling an image
with a custom platform.  As we recently re-discovered [1], many
multi-arch images in the wild do not adhere to the OCI image spec and
either declare custom or simply wrong platforms (arch, os, variant).

To address such wrong images, we enforce the pull-always policy whenever
a custom arch, os or variant is specified.  We have to do that since we
cannot reliably perform platform matches to any image we would find in
the local containers storage.

To complete the fix, we need to ignore any local image and not use the
locally resolved name which we usually have to do (see [2]).

Let's assume we have a local image "localhost/foo" (arch=amd64).  If we
perform a `pull --arch=arm64`, we would not attempt to be pulling
`localhost/foo` but use the ordinary short-name resolution and look for
a matching alias or walk the unqualified-search registries.

In other words: short-name resolution of multi-arch images is prone to
errors but we should continue supporting images in the wild.

[1] containers/podman/issues/10682
[2] containers/buildah/issues/2904

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-27 13:05:08 +02:00
Valentin Rothberg fa1504c98a libimage: `(*Runtime).SystemContext()`
Add a method to the libimage runtime to access (a copy of) its
types.SystemContext.  That can be helpful for callers which may need to
access the system context.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-24 10:41:25 +02:00
Valentin Rothberg 14a61632be libimage: pull: override even --pull=never with custom platform
As it turned out in Podman CI (containers/podman/pull/10739), the policy
is overridden via --arch/os/platform/variant even when the policy is set
to never.

While I think this is a bug, it is a separate one and must tackled
separately.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-21 17:31:02 +02:00
Valentin Rothberg 2925b3a149 libimage: pull: enforce pull policy for custom platforms
Enforce the pull policy to always if a custom platform is requested by
the user.  Some images ship with invalid platforms which we must
pessimistically assume, see containers/podman/issues/10682.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-21 12:42:07 +02:00
Valentin Rothberg 9edbd96e52 libimage: pull: ignore platform for local image lookup
We must ignore the platform of a local image when doing lookups.  Some
images set an incorrect or even invalid platform (see
containers/podman/issues/10682).  Doing the lookup while ignoring the
platform checks prevents redundantly downloading the same image.

Note that this has the consequence that a `--pull-never --arch=hurz` may
chose a local image of another architecture.  However, I estimate the
benefit of continuing to allow potentially invalid images higher than
not running them (and breaking workloads).

The changes required to touch the corrupted checks.  I used the occasion
to make the corrupted checks a bit cheaper.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-21 10:02:59 +02:00
OpenShift Merge Robot 110bf078bc Merge pull request #622 from vrothberg/platform
libimage: lookup images by custom platform
2021-06-18 05:32:48 -04:00
Valentin Rothberg da2875b837 libimage: force remove: only untag on multi tag image
When removing an image by name, do not remove the image and all its
tags, even if force is set.  Instead, just untag the specified name.

Note: adjust the load test to preserve the order in the untagged field.

Also vendor in the latest HEAD in containers/image to fix a bug revealed
in Podman CI.

Context: containers/podman/issues/10685
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-17 15:46:14 +02:00
Daniel J Walsh e2264b5823 Set BigFilesTemporaryDir to GetEnv(TMPDIR) if set or /var/tmp
Currently if the caller does not specify the BigFilesTemporaryDir,
Podman and Buildah users expect this to default TMPDIR environment
variable or /var/tmp if not set.

Moving to libimage caused a regression in this functionality.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-16 10:53:59 -04: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 58b2d6164a libimage: fix Exists
Commit 7f038138c3 introduced a regression to Exists() which would
return an error if the image does not exist.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-10 16:49:30 +02:00
Valentin Rothberg 7f038138c3 libmage: Exists: catch corrupted images
While various execution paths in libimage already handle corrupted
images, `(*Runtime).Exists()` did not and would list an image to exist
in the storage even if it is corrupted.

Some corruptions can only be detected when accessing the individual
data.  A reliable way of accessing such data is to inspect an image.
Hence, an image will only be listed to exist if a) it has been found
and b) can be inspected.  If the inspection fails, the image will be
reported to not exists but without an error.  That allows for users
of libimage to properly recover and repull.

Further, add a new unit tests that forces a data corruption and
gradually recovers from it.

Podman will now behave as follows:
```
$ ./bin/podman run -d --rm nginx ls
ERRO[0000] Image nginx exists in local storage but may be corrupted: layer not known
ERRO[0000] Looking up nginx in local storage: layer not known
Resolved "nginx" as an alias (/home/vrothberg/.cache/containers/short-name-aliases.conf)
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob 596b1d696923 skipped: already exists
Copying blob 30afc0b18f67 skipped: already exists
Copying blob febe5bd23e98 skipped: already exists
Copying blob 69692152171a skipped: already exists
Copying blob 8283eee92e2f skipped: already exists
Copying blob 351ad75a6cfa done
Copying config d1a364dc54 done
Writing manifest to image destination
Storing signatures
56b65883c3c32b67277bcc173bd9f26c27cbbdbc6d3aacf6c552be796eb7a337
```

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-10 10:50:57 +02:00
Valentin Rothberg 7700a470bf libimage: pull: turn image-lookup errors non-fatal
An image can be corrupted if, for instance, a pull or build operation is
killed (e.g., during commit).  In such cases, an image may be listed
even if a layer is missing.

Over time, Podman and Buildah have made various execution paths more
robust to handle such cases gracefully and/or give the users some help
in trying to resolve the issue.  So far, the recommended way was to
remove the corrupted image from storage and then pull it.

The linked Bugzilla issue raised the desire to simplify the recovery by
allowing to pull an image even if the local counterpart is corrupted.
This is especially important for installer scenarios, where users may
restart the installer which would attempt to pull the image again.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1966872
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-06-09 14:24:57 +02:00
cdoern 8c89f85147 fixed comments
Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
2021-06-08 08:49:15 -04:00
OpenShift Merge Robot e66ec81ea0 Merge pull request #582 from vrothberg/pull-short-names
pull: don't resolve short names on explicit docker:// reference
2021-05-26 17:36:21 +02:00
Valentin Rothberg aaf30e7cbd pull: don't resolve short names on explicit docker:// reference
Fixes: containers/common#581
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-26 17:15:40 +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
OpenShift Merge Robot d4d8c0a428 Merge pull request #571 from vrothberg/libimage-comments
libimage: add some comments
2021-05-24 22:16:57 +02:00
Valentin Rothberg 62dfe774ab libimage: add some comments
Add some comments in the code that I found worth elaborating on while
rereading the code.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-21 12:54:33 +02:00
Valentin Rothberg 04d1881aec libimage: add more image tests
Add unit tests for exercising all kinds of function of an `Image`
object.

Also remove an unused, redundant (and incomplete) `MountPoint` function.
`Mountpoint` is used by Podman instead.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-21 09:55:05 +02:00
Valentin Rothberg 8f1802e329 libimage: lookup: tolerate corrupted image
Recent changes in the image-lookup logic will, in many cases, yield a
check whether an image is a manifest list.  This had caused a regression
in Podman's test/system/330-corrupt-images.bats system tests where we're
attempting to delete a corrupted image with a missing manifest.  Since
the manifest is missing, the manifest list check fails.

To make the image lookups more tolerant towards this specific error
case, we need to ignore the error but emit a warning, similar to what
we're already doing in the parent-child checks.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-19 10:03:18 +02:00
Valentin Rothberg 92095e0dbe libimage: fix manifest list lookup
Commit 724e7c92b5 fixed an issue when pushing images from of a
platform different than the current machine.  That required to disable
the platform matching logic when looking up the image before pushing it.
It also required some restructuring of the code such that manifest lists
are resolved and their instances looked up.

The restructuring in turn introduced a regression when looking up bare
manifest lists.  To fix the regression and keep the code simple,
introduce an internal field in the LookupImageOptions that indicates
whether we're looking up a bare manifest list or not.

Now we have clearer separation of concerns between looking up images or
manfifests and whether the looked up image needs to match the current
platform or not.

Add some unit tests exercising the manifest-list code to make sure we're
not regressing again.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-18 14:53:37 +02:00
OpenShift Merge Robot 23ccbdb6c0 Merge pull request #557 from vrothberg/libimage-push
libimage: push: ignore image platform
2021-05-17 13:33:22 -04:00
OpenShift Merge Robot 2c98419f94 Merge pull request #551 from vrothberg/libimage-tests
libimage: add save tests
2021-05-17 13:31:22 -04:00
Daniel J Walsh fe7d00419f Merge pull request #552 from vrothberg/libimage-import-tests
libimage: add import test
2021-05-17 13:29:49 -04:00
Nalin Dahyabhai 301b52a846 libimage/Image.HasDifferentDigest: handle manifest lists
When comparing the digests of a local image and a remote image, we've
been reading the manifest from the remote image using NewImage(), which
may or may not return a list, and have been comparing the digest of that
manifest to only one of the local image's manifests.

Start checking if the remote reference points to a manifest list, and if
it is, find the image in the list that we'd choose to pull, and use its
manifest digest for the comparison.

When looking up the digest of the local image to compare to the remote
image, consider them to be the same image if any of the manifests in the
image record has the same digest as the remote manifest, which is now
known to not be a list.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-05-17 10:26:24 -04:00
Valentin Rothberg 724e7c92b5 libimage: push: ignore image platform
When pushing an image, make sure to ignore the platform of the image to
push exactly what the user wishes to.  Add a test to make sure we're not
regressing in the future.

To preserve previous behaviour with respect to attempting to push a
manifest list, move the platform check below resolving to a manifest
list.

Fixes: #containers/podman/issues/10344
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-17 10:28:10 +02:00
Valentin Rothberg e43f58b1b0 libimage: add import test
Add a unit test exercising image import.  It is not extensive but will
do the work of catching regressions.  More tests to increase coverage
can be added later.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-14 15:21:46 +02:00
Valentin Rothberg 9c6c0eab43 libimage: add save tests
Add save tests.  Also fix a bug when saving a single image but with
multiple tags.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-14 12:21:52 +02:00
OpenShift Merge Robot 27e6d9f505 Merge pull request #543 from vrothberg/push-tests
libimage: add push tests
2021-05-11 10:38:09 -04:00
Valentin Rothberg 4b08220b63 libimage: add push tests
Add tests for exercising pushing images to various transports and
attempt to pull from the destinations.

Fix an error determining the storage reference and image name when
pushing to containers-storage.

Fix a bug in `RemoveImages`: leaving `names` empty and specifying no
filters should remove *all* images.

Please note that the tests are currently not exercising pushing to a
registry.  That requires a local registry but since CI is currently
running inside a container, we cannot do much just yet.  Once CI runs
in another environment, I will go back and extend the tests.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-11 13:01:04 +02:00
OpenShift Merge Robot d5f62c395d Merge pull request #540 from vrothberg/fix-pull
libimage: fix pull from dir
2021-05-10 10:05:55 -04:00
Valentin Rothberg e15c1163db libimage: fix pull from dir
The recent refactoring introduced a bug yielding a pull from the dir
transport a NOP.  I will soon add unit tests for that.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-10 14:55:32 +02:00