Commit Graph

30 Commits

Author SHA1 Message Date
Miloslav Trmač 5228c3119a 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č b823785517 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č b5730106fe 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č a8154ae93c 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č 71f79feb7e 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č 6a9adcb344 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č 7d03fd7fa7 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č 5e98ea38e7 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č d2558fe261 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č 1c2476e949 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č 786e2397a9 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č 7064578c93 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č e3ebf5ca77 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č 910eec8903 Add a test for isManifestUnknownError
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-12 21:48:04 +02:00
Ralf Haferkamp 58f6905ca4 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 051f89b66e 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 489a0c7fba 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 2333d84cca 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č a41e351b5d 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č 4899cbee3c 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č 637b5b35a8 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 a50522cde7 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 e18b1afd (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 77d0263114 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 36b5e57a46 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 8a9e67c6e0 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 f7fc8d5c3e 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č 95746cf60e 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 c80844b1c5 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 8584ac26d6 types,docker: add DockerAuthConfig
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-07 17:06:19 +02:00
Michal Minář e18b1afd04 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