Commit Graph

30 Commits

Author SHA1 Message Date
Miloslav Trmač 4dd6f6eeb7 Don't silently ignore errors determining size in TryReuseBlob
When looking for inexact matches, this will cause the matches to be skipped.
When checking for an exact match, this will cause an upload failure;
we don't have any other way to handle pre-existing blobs on the destination.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-03-11 20:10:11 +01:00
Miloslav Trmač 9b43674741 Remove unnecessary fields from bearerToken
These fields need to exist when parsing JSON; but we can just
record the outcome of processing them.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-09 22:32:31 +02:00
Miloslav Trmač 1b7daaf858 Add tests for bearerToken.expirationTime
That's the value that really matters, not the inputs;
and we will remove the inputs from bearerToken.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-09 22:32:31 +02:00
Miloslav Trmač dc3703be47 Make bearerToken.Token private
No need to make it a public field now.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-09 22:32:31 +02:00
Miloslav Trmač c132a171c7 Beautify a test of newBearerTokenFromHTTPResponseBody
Remove an unnecessary cast. Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-09 22:32:31 +02:00
Miloslav Trmač b9806105bb Turn newBearerTokenFromJSON into newBearerTokenFromHTTPResponseBody
... so that we have more context for error reporting.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-06-20 18:13:57 +02:00
Miloslav Trmač b47e339cea Refactor tests of newBearerTokenFromJSONBlob
Make them table-driven where possible. Use testify.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-06-20 18:13:57 +02:00
Miloslav Trmač 23d7e70104 Recognize "manifest unknown" errors reported by Harbor
... per data in https://github.com/containers/image/issues/2203 .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-16 18:19:56 +02:00
Miloslav Trmač 489cf6391f Exit early if we don't get a HTTP response at all
The idea of a StatusTooManyRequests retry loop,
or the needsRetryWithUpdatedScope logic,
only makes sense if we do get a response; on other errors,
we can exit immediately. So do that, and simplify the
code.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-05 18:50:28 +02:00
Miloslav Trmač 91536efe43 UNTESTED: Log warnings on a Warning: header
... as now requested by distribution-spec.

Untested apart from the added parser unit test.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-08-10 19:49:43 +02:00
Miloslav Trmač 25f9cea5c8 Close http.Response.Body
golangci-lint linter: bodyclose

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:15:45 +01:00
Miloslav Trmač 9352751cab Move the docker client User-Agent value to a shared subpackage
... to be also used by Fulcio.

Note that the atomic: transport uses a skopeo/... user agent,
we don't care to change that.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-01-11 11:23:59 +01:00
Miloslav Trmač 524ce57987 Recognize invalid error responses of registry.redhat.io
... when checking for missing images.

In particular, this is necessary for use-sigstore-attachments not to
cause failures when pulling from registry.redhat.io.

Red Hat internal reference: RITM1310318

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-13 22:21:34 +02:00
Miloslav Trmač 771e320b34 Add a test for isManifestUnknownError
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Ralf Haferkamp 3ce7f05c93
docker_client: Handle "invalid_scope" errors
By default docker_client just uses the auth challenges from the /v2/
ping request to request a Bearer Token. For some requests (e.g. for
/v2/_catalog on some registries) this might not be sufficient and return a
a HTTP Unauthorized Error with the "www-authenticate" header including
an "insufficient_scope" error. In that case the client will now retry
the request and fetch a new token with updated challenges to have the
"scope" matching for what the endpoint needs.

This fixes https://github.com/containers/image/issues/1478

Signed-off-by: Ralf Haferkamp <rhafer@suse.com>
Signed-off-by: Ralf Haferkamp <ralf@h4kamp.de>
Signed-off-by: Dan Čermák <dcermak@suse.com>
Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Co-authored-by: Miloslav Trmač <mitr@redhat.com>
Co-authored-by: Ralf Haferkamp <ralf@h4kamp.de>
2022-08-30 09:02:36 +02:00
Josh Soref 111bf164be Spelling
* about
* appropriate
* busybox
* candidate
* candidates
* certificate
* config
* configuration
* containers
* decompression
* directory
* does-not/match
* does/not/exist
* doesnot
* doesnotexist
* exemplary
* garbage
* gzipped
* identify
* initially
* kubernetes
* length
* marshaling
* maximum
* mybetaproduct
* overridden
* parameter
* permissive
* policyconfiguration
* protocols
* reference
* referenceable
* requirement
* response
* simultaneously
* slashes
* subobject
* successfully
* this
* uncompressed
* unmarshaled
* unmarshaler
* unmarshaling it
* unmarshaller
* valid

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2021-03-23 14:37:37 -04:00
Jon Johnson 340d6099a9 Set a default User-Agent if unset
Currently, the User-Agent defaults to a golang default of either:

Go-http-client/1.1
Go-http-client/2.0

This makes it rather difficult to distinguish this client from any other
random golang program in registry logs.

Instead, set the default User-Agent to:

containers/$VERSION (github.com/containers/image)

Signed-off-by: Jon Johnson <jonjohnson@google.com>
2021-01-20 17:06:23 -08:00
Daniel J Walsh 5ee42a1f9d Add $HOME/.config/containers/certs.d to perHostCertDirPath
We want to allow users to store certs in their homedir when running in rootless mode.
We want rootless podman and rootless buildah to add $HOME/.config/containers/certs.d
to the search path for certificates by default.

Currently there is no way for a non privileged user to get certs without being root on
the system or specify the certs dir on ever call.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-04 13:43:53 +01:00
Miloslav Trmač 8d21d1f112 Clean up various imports
... primarily so that imports of packages that aren't in the
standard library are all in one section.

Also correct the package in tarball/doc.go example (without verifying
the code works).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:36:44 +02:00
Miloslav Trmač 7d9cde7252 Update to major version v5
> gomove github.com/containers/image/v4 github.com/containers/image/v5
+ a manual edit of go.mod

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:27:45 +02:00
Miloslav Trmač e568c94ef3 Correctly use a c/image/v4 module namespace
... so that major-version-aware Go module import
(as opposed to vX.Y.Z+incompatible, which does not allow different
packages to use different versions) works right.

Also requires adding some more GO111MODULE=on options to Makefile.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-03 22:54:27 +02:00
W. Trevor King 5299d353a4 pkg/docker/config: Bring auth tests from docker/docker_client_test
Shifted a number of auth-getting unit tests from docker_client_test.go
into config_test.go, since they only excercise config.go logic.
They'd been in their previous location since landing in d30079fd (Be
benevolent to .docker/config.json file, 2016-09-20, #96).

Signed-off-by: W. Trevor King <wking@tremily.us>
2019-02-27 14:38:36 -08:00
Mike Lundy 369c44212b Put context.Context arguments on almost everything
- Network IO paths should react to cancels now.
- File IO paths generally still won't.
- `SystemContext` objects have been renamed to `sys` to leave `ctx`
  available for the stdlib context objects.

Signed-off-by: Mike Lundy <mike@fluffypenguin.org>
2018-04-07 04:34:51 -07:00
umohnani8 bca26783cc Add /etc/containers/certs.d as default certs directory
Adding /etc/containers/certs.d as another default certs directory
The code will first check /etc/containers/certs.d for the certificates
and if not found at this path it will fall back to /etc/docker/certs.dir

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-02-05 12:23:07 -05:00
Tom Godkin c2b9a9b31a Make token parsing compatible with Docker's Token Authentication Specification
See: https://docs.docker.com/registry/spec/auth/token/

Signed-off-by: Ed King <eking@pivotal.io>
Signed-off-by: Will Martin <wmartin@pivotal.io>
Signed-off-by: Julia Nedialkova <julianedialkova@hotmail.com>
2018-01-18 17:28:26 +02:00
umohnani8 f28367e1ae Add docker/config package to containers/image/pkg
This package is used in authenticating a user for kpod login
and can be used for authentication in kpod push, pull etc.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2017-10-09 21:56:49 -04:00
Miloslav Trmač 3aeae04bfd Add types.SystemContext.DockerPerHostCertDirPath, defaulting to /etc/docker/certs.d
This will make /etc/docker/certs.d/$host[:$port], notably RHEL CDN
certificates, work by default.

types.SystemContext.DockerCertPath, if defined, overrides and disables
DockerPerHostCertDirPath.  We now always look into _some_ (exactly one)
directory.  (This also forces us to explicitly override the default path
in tests because in Travis /etc/docker has mode 0700, causing spurious failures.)

(See also the added comment about handling docker.io in certs.d.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

i
2017-05-27 23:19:30 +02:00
Nalin Dahyabhai 346966324a Add support for containers/storage
Add containers/storage as a backend type called 'storage'.

The image's blobs are stored either as storage layers (if they look like
archived layers) or (alongside the manifest and signatures) as named big
data items associated with the image.

Inspection data and record-keeping (so that we can remember which blobs
were layers and which weren't) are encoded as a JSON object which is
stored in the storage image's metadata field.

When importing blobs, layer IDs are generated by concatenating the
parent's layer ID (if there is one) with the hex string representation
of the expected digest of the content blob, if one is known.  If there
is no expected digest, the ID is randomly generated.

If we find ourselves importing a layer with the same ID as a layer that
we already have, we digest the incoming stream and compare it to the
cached digest of the already-present layer, and return an error only if
they don't match.  If an expected blob digest is provided, the actual
digest of the blob is compared with it, and if they don't match, an
error is returned.

If we find ourselves importing a blob more than once, we track the IDs
of each of the resulting layers.

If we find ourselves importing an image that wants to be tagged with a
name that is already in use, the name is then assigned to the new image
and the old image remains otherwise unmodified.  If that incoming image
claims to have the same ID as an image which we already have, the import
will fail.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2016-12-13 12:19:39 -05:00
Antonio Murdaca 98d6c0073a
types,docker: add DockerAuthConfig
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-07 17:06:19 +02:00
Michal Minář d30079fd26
Be benevolent to .docker/config.json file
Docker can store auth entries with schema prefix or even path suffix.
See an example:

    {
        "auths": {
            "10.3.10.88:5000": {
                ...
            },
            "http://10.3.10.88:5000/v2/": {
                ...
            },
            "https://10.3.10.88:5000": {
                ...
            },
            "https://index.docker.io/v1/": {
                ...
            }
        }
    }

The entries were created using command `docker login` of upstream Docker
1.12. Let's normalize the auth keys before trying to match against
hostname.

Signed-off-by: Michal Minář <miminar@redhat.com>
2016-10-06 15:05:54 +02:00