Commit Graph

130 Commits

Author SHA1 Message Date
Miloslav Trmač 225404ed0f Stop using net/tls.Config.PreferServerCipherSuites
As of Go 1.17 it is deprecated and ignored.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-14 18:40:25 +02:00
Doug Rabson 607cca6b19 Config files should live in /usr/local on FreeBSD
Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-05-10 10:45:49 +01:00
Miloslav Trmač 620ff7cd4f Use strings.NewReader instead of bytes.NewBufferString
Just a micro-optimization: avoid maintaining state for
a read/write buffer, and the allocation inherent in a
string -> []byte conversion.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-22 17:45:34 +02:00
Miloslav Trmač 7152f888b9 Update users of deprecated io/ioutil
Mostly just name changes that should not change behavior,
apart from ioutil.ReadDir -> os.ReadDir avoiding per-item
lstat(2) in some cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 20:46:48 +02:00
Miloslav Trmač 5a4b8a4038 Use url.Redacted() in log output
... to be at least a bit protected against credentials in logs.

I did try to find all uses, but it's possible I have missed some.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Miloslav Trmač fa54b28a4d Modify makeRequestToResolvedURL and makeRequestToResolvedURLOnce to accept an *url.URL
This is, sadly, wasteful, because NewRequestWithContext() only accepts
a string and parses it again, but it gives us more type safety, and simplifies
at least some callers.

Most importantly, this will also allow us to call url.Redacted() for logging.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Miloslav Trmač d2ea8f14dd Update an obsolete comment
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Tycho Andersen 555db17183 docker: less bears :(
Noticed this during the current AWS outage...

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2021-12-15 10:30:03 -07:00
Miloslav Trmač 2d0e1422ad Use http.Method* constants instead of hard-coded strings
... just for the general principle of avoiding hard-coded
copy&pasted data.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-27 20:51:42 +02:00
Miloslav Trmač 0feff83304 Use http.NewRequestWithContext() instead of http.NewRequest().WithContext()
It is marginally more efficient, and more importantly, simpler.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-27 20:51:42 +02:00
divolgin e11e211205 Return an actual error instead of nil when registry returns bad status code
Signed-off-by: divolgin <dmitriy@replicated.com>
2021-07-26 18:30:20 -07:00
Sascha Grunert 16ffe8d903
Remove `GetCredentials` deprecation
We cannot use `GetCredentialsForRef` if we want to retrieve the
credentials for a single registry. This use case is still valid which
makes the deprecation of the API obsolete.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2021-07-21 14:26:07 +02:00
Valentin Rothberg c031c431a2 search: catalog: return full match as first item
When searching via v2/catalog make sure that a full match is returned as
the first item.  The change is motivated by a conversation in a BZ [1]
on the rather undefined nature/semantics of searching images.

While this change does not fix the BZ, it may be a small improvement
when using the v2/catalog endpoint.

[1] bugzilla.redhat.com/show_bug.cgi?id=1976283

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-13 13:47:11 +02:00
Daniel J Walsh 1f79791095
Do not prepend Error on each wrapped error message.
Podman and other tools already add Error: to the front of returned error
message, and this ends up as a stutter.

podman pull fedora.io/fred
Trying to pull fedora.io/fred:latest...
Error: Error initializing image from source docker://fedora.io/fred:latest: invalid character '<' looking for beginning of value

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-07-01 05:01:27 -04:00
Daniel J Walsh cdd6817ed6
Change all references to docker registry to container registry
Will leave references to distribution spec until there is an OCI Spec we
can point at.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-30 15:34:06 -04:00
Sascha Grunert 2cafc0105c
Add support for registry paths in auth.json
This patch adds support for `host[:port]/ns/…repo` to auth.json while
keeping the backwards compatible behavior.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2021-06-30 17:23:59 +02:00
xiaoqing 05fa7577cb fix docker.GetDigest docker.makeRequestToResolvedURL docker.getExternalBlob socket leak 2021-03-19 10:03:33 +01: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 1fc5bea27b
Fix up errors linter is complaining about
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-19 17:03:52 -05:00
Qi Wang 701023dd1a Set default rootless sigstore
Set default rootless sigstore to ~/.local/share/containers/sigstore if the caller is non-root.
Export the func ConfiguredSignatureStorageBase() for Podman image sign implementation.
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-09-18 15:44:24 -04:00
Qi Wang d2e8517486 enable search using pagination
Enable search registry uses the pagination until the search result reaches the limit, instead of returning default 100 limit from registry API.
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1827794

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-25 21:04:57 -04:00
Stuart Hayton f2ab419cb9 Add User-Agent to oauth
like makeRequestToResolvedURLOnce()
Signed-off-by: Stuart Hayton <stuart.hayton@uk.ibm.com>
2020-04-09 14:50:01 +01:00
Stuart Hayton b13d33328d set client_id
Signed-off-by: Stuart Hayton <stuart.hayton@uk.ibm.com>
2020-04-07 02:43:45 +01:00
yihuaf 31d443d577 Support IdentityToken in registry authn
Adding the support for using identitytoken in the .docker/config.json
files. Azure Container Registry is one of the case that uses this.

Signed-off-by: yihuaf <fang.yihua.eric@gmail.com>
2020-03-13 19:08:42 -04:00
Valentin Rothberg 4227aadf4c containers-registries.conf.d: refine semantics
- Only load `.conf` suffixed files
- Enforce v2 format of registries.conf
- Don't recurse into sub-directories
- Rootless support
- Cache key consists of conf and dir path
- Merge `[[registry]]` tables
- Several code clean ups and minor fixes

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-13 11:23:55 +01:00
knqyf263 6b4551b1c6 feat(docker): support docker registry token
Signed-off-by: Teppei Fukuda <knqyf263@gmail.com>
2020-03-12 09:55:28 +02: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
Valentin Rothberg 61096ab725 restrict sizes of inmem processed blobs
Restrict the sizes of blobs which are copied into memory such as the
manifest, the config, signatures, etc.  This will protect consumers of
c/image from rogue or hijacked registries that return too big blobs in
hope to cause an OOM DOS attack.

Note that error message should be improved in a future change to make
sure that it's clear in which code path we hit a limit.

Fixes: CVE-2020-1702
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1792796
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-03 13:38:42 +01:00
Miloslav Trmač cc9b2c8faa Fix up the wording a bit in various places
E.g.
- Capitalize log messages
- Add a bit more context to the log messages
- Don't commit to specific fallback behavior in the API, only say that it may automatically retry.
- Fix some typos

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač d13e4cb6ab Support canceling the 429 retry loop using context.Context
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 0c5134d839 Make parseRetryAfter a top-level function
It does not need to be nested (anymore), and as a top-level
function it's at least possible to write tests for it
(but this PR does not add any).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 74e29f4399 Move the backoff handling parameters to the top of the file
... to make it a bit more obvious that these are tunables

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 2e92a33a7e Use time.Duration instead of an integer number of seconds in the backoff loop
This is more explicit about the units, actually a tiny bit simpler (no floats
involved), and does not enforce whole-second generality in the loop that
does not care.

Remove debugging log entries about falling back to %d seconds instead of
converting them, the caller logs the value immediately afterwards anyway.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 9288cbb15f Separate an initialDelay constant from the delay loop variable
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 257882296b Move the (res, err) variables inside the loop
No need to declare them all the way at the start.

This also shows that parseRetryAfter has been accessing the function-global
variable instead of its parameter, so fix that.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač a7e2aca03b Simplify back-off control flow, part 3
Only have one comparison with numIterations.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 0ddd3582fe Simplify back-off control flow, part 2
Check for the "should we retry at all" condition first, and comment
the conditions (primarily to explain the "stream != nil" part).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač c18a8a175f Simplify back-off control flow, part 1
Do
> if !x { break }
> loop body

instead of
> if x { loop body; continue }
> break

(except for the numIterations-1 case, but in that case there is no difference
between break and continue for our purposes.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 3b7bb983a0 Remove a debugging log entry
We don't really need to dump the full error header at the user.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 864c540f24 Rename the "delay" parameter to parseRetryAfter to "fallbackDelay"
... making its purpose clearer.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 42c52261ea Remove the min() helper
It now has only one user, and the simple if is a bit easier to read.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 1cc8f03ddb Move the maxDelay enforcement out of the nextDelay helper
It has to be enforced on all return paths; it's simpler
to do it in the caller, that way we will never forget, and
we don't need a comment calling attention to the fact that maxDelay
is used.

Then rename nextDelay to, afterwards, more accureate parseRetryAfter.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Miloslav Trmač 75cb5d58cd Re-add some context to unexpected HTTP status errors
... to indicate the operation that failed

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-01-06 17:23:57 +01:00
Ivan Voronchihin 21320ca776 Fix golangci-lint advises
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:31:04 +04: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
Qi Wang 9c14d60bf5 return resp error message
follow https://github.com/containers/image/pull/709
return and wrap http response message to show server-side error message.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-10-24 14:20:06 -04:00
Valentin Rothberg d51a7cabae docker: handle http 429 status codes
Consolidate checking the http-status codes to allow for a more uniform
error handling.  Also treat code 429 (too many requests) as a known
error instead of an invalid status code.

When hitting 429, perform an exponential back off starting a 2 seconds
for at most 5 iterations.  If the http.Response set the `Retry-Header`
then use the provided value or date to compute the delay until the
next attempt.  Note that the maximum delay is 60 seconds.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-10-18 11:47:57 +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
Qi Wang 618003c1a9 add http response to log
fix https://github.com/containers/libpod/issues/3884
Add http response message log to show server-side error message.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-09-27 15:14:25 -04:00
Miloslav Trmač a3d69a4a89 Use the same HTTP client for contacting the bearer token server and the registry
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-08-01 21:41:45 +02:00