Commit Graph

68 Commits

Author SHA1 Message Date
Phil Estes
399c9d8326
Merge pull request #8861 from jedevc/docker-resolver-relevant-error
docker: return most relevant error from docker resolution
2023-10-03 10:40:52 -04:00
Derek McGowan
79772a0dd4
remotes: always try to establish tls connection when tls configured
When a endpoint is configured for http and has a tls configuration,
always try to the tls connection and fallback to http when the tls
connections fails from receiving an http response. This fixes an issue
with default localhost endpoints which get defaulted to http with
insecure tls also configured but are using tls.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-10-02 15:29:11 -07:00
Derek McGowan
508aa3a1ef
Move to use github.com/containerd/log
Add github.com/containerd/log to go.mod

Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-09-22 07:53:23 -07:00
Sebastiaan van Stijn
e2ad5a985e
removes/docker: remove unnecessary conversion (unconvert)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-30 22:35:31 +02:00
Justin Chadwell
b4814a29d4 docker: return most relevant error from docker resolution
Previously, we would return the first non-404 error from a host.

This is logical, however, it can result in confusing errors to the
user:

- e.g. we have an HTTP host, and an HTTPS host.

  If the image does not exist, we return "http: server gave HTTP
  response to HTTPS client". This is technically correct, however, the
  user is easily confused - the most relevant error in this case is the
  404 error.

- e.g. we have a broken HTTP host that returns 5XX errors, and a HTTP
  host with authentication.

  On the request for an image, we return the 5XX error directly.
  However, we have a host later on which returned an authentication
  error which is now hidden from the user.

Note: this *can* be resolved by changing the order of hosts passed in,
however this requires 1. knowing ahead of time which hosts are going to
return certain errors and 2. this is often not desirable, we'd prefer
to use HTTPS if it's available, and only then fallback to HTTP.

To resolve this, we assign each possible error during resolution a
"priority" that marks how far through the image resolution process a
host/path combo got. Then we return the error with the highest priority,
which is much more likely to be the most relevant error to the user.

The ranking of priority then is (from lowest to highest):
- Underlying transport errors (TLS, TCP, etc)
- 404 errors
- Other 4XX/5XX errors
- Manifest rejection (due to max size exceeded)

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-07-26 11:33:50 +01:00
Justin Chadwell
a3404ac422 docker: add missing info log for 4XX/5XX responses
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-07-24 15:28:37 +01:00
Jin Dong
83ff030e4f Change http.Header copy to builtin Clone
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
2023-07-08 05:25:47 -07:00
Jin Dong
cdb153ec92 Resolve docker.NewResolver race condition
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
2023-07-08 05:25:47 -07:00
Sebastiaan van Stijn
52997ea983
remotes/docker: ResolverOptions: fix deprecation comments
Go deprecation comments must be formatted to have an empty comment line before
them. Fix the formatting to make sure linters and editors detect that these
are deprecated.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-01 09:28:12 +02:00
Maksym Pavlenko
06e085c8b5 Add Fields type alias to log package
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2023-02-20 17:29:08 -08:00
Derek McGowan
ba243ffaaf
Merge pull request #7521 from iyear/fix-defer
Fix incorrect defer usage and refactor judgement
2022-12-27 15:50:41 -08:00
Hsing-Yu (David) Chen
d5010a12df docs: Authorizer.Authorize could return ErrUnexpectedStatus
Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
2022-12-08 13:24:48 -08:00
Maksym Pavlenko
14a08721cc Remove OpenTelementry imports from remotes/docker package
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-11-15 17:32:26 -08:00
Luca Comellini
b829e6f2d3
Bump OpenTelemetry to v1.11.1
Signed-off-by: Luca Comellini <luca.com@gmail.com>
2022-11-10 22:15:10 -08:00
Swagat Bora
7def13dde3 Add a thin wrapper around otel Span object
Signed-off-by: Swagat Bora <sbora@amazon.com>
2022-11-11 01:28:27 +00:00
Swagat Bora
3b87d46ce2 Add tracing spans in CRI image service and pull.go
Signed-off-by: Swagat Bora <sbora@amazon.com>

Add spans around image unpack operations
Use image.ref to denote image name and image.id for the image config digest
Add top-level spand and record errors in the CRI instrumentation service
2022-11-03 17:03:43 +00:00
iyear
7afe6d92dc Fix incorrect defer usage and refactor judgement
Signed-off-by: iyear <ljyngup@gmail.com>
2022-10-17 13:38:14 +08:00
Iceber Gu
3cfde732e1 remotes/docker/config: Skipping TLS verification for localhost
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2022-09-13 17:40:23 +08:00
Akihiro Suda
42584167b7
Officially deprecate Schema 1
Schema 1 has been substantially deprecated since circa. 2017 in favor of Schema 2 introduced in Docker 1.10 (Feb 2016)
and its successor OCI Image Spec v1, but we have not officially deprecated Schema 1.

One of the reasons was that Quay did not support Schema 2 so far, but it is reported that Quay has been
supporting Schema 2 since Feb 2020 (moby/buildkit issue 409).

This PR deprecates pulling Schema 1 images but the feature will not be removed before containerd 2.0.
Pushing Schema 1 images was never implemented in containerd (and its consumers such as BuildKit).

Docker/Moby already disabled pushing Schema 1 images in Docker 20.10 (moby/moby PR 41295),
but Docker/Moby has not yet disabled pulling Schema 1 as containerd has not yet deprecated Schema 1.
(See the comments in moby/moby PR 42300.)
Docker/Moby is expected to disable pulling Schema 1 images in future after this deprecation.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-05-02 19:08:38 +09:00
W3QKR2T
b90c466c38 Add ErrUnexpectedStatus to resolver
Signed-off-by: Fabian Hoffmann <fabian.hoffmann@posteo.de>
2022-03-04 10:46:39 +01:00
Shengjing Zhu
f4f41296c2 Replace golang.org/x/net/context with std library
Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2022-02-22 02:27:05 +08:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
Eng Zer Jun
50da673592
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-09-21 09:50:38 +08:00
Derek McGowan
dbccd0d357
Merge pull request #5275 from haslersn/fix-4531
Try next mirror in case of non-404 errors, too
2021-05-19 07:57:57 -07:00
Derek McGowan
b1d4140a22
Update docker resolver to authorize redirects
Allows redirects to be authorized if authorization is provided
for the redirected to host. The authorization will always go
to the redirect and never to the referrer.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2021-05-14 12:16:24 -07:00
Sebastian Hasler
c0e2f4b5d2 Try next mirror in case of non-404 errors, too
Signed-off-by: Sebastian Hasler <sebastian.hasler@gmx.net>
2021-04-15 12:04:07 +02:00
Mike Brown
d21fe46250 adds log for each failed host and status not found on host
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2021-04-14 13:23:22 -05:00
Paul "TBBle" Hampson
785ac3ab71 Ensure request.header is never nil
Header.Clone() will return `nil` if called on a nil object.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-01-13 05:46:50 +11:00
Phil Estes
9db6aa625d
Merge pull request #4302 from songjiayang/update-docker-resolver
Refactor dockerResolver with resolveDockerBase helper
2021-01-12 11:15:06 -05:00
Tonis Tiigi
bf323c5bdd docker: avoid concurrent map access panic
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-12-15 22:26:26 -08:00
ktock
4b882eb93a Export repository scope helper functions
`docker.Authorizer` requires library clients to configure scope via context.
It is helpful for the clients to use the helper (currently private) functions
for generating scope string and to use that function with the combination of
other scope-related ones (e.g. `docker.WithScope`).

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2020-10-06 10:49:01 +09:00
songjiayang
5867c88832 Refactor dockerResolver to make code simple
1.add resolveDockerBase helper
2.dockerBase header copy with header.Clone()

Signed-off-by: songjiayang <songjiayang@jd.com>
2020-09-14 11:38:05 +08:00
Derek McGowan
a7b2304f69
Merge pull request #4445 from tonistiigi/auth-refactor
docker: split private token helper functions to reusable pkg
2020-08-25 12:25:23 -07:00
Derek McGowan
adeba792f1
Add namespace query parameter for registry proxying
Proxy registries are designed to serve content from upstreams.
However, the proxy hostname will usually not match the hostname
of the upstream, requiring the proxy to only use a single
upstream or use its own pattern matching to determine the upstream.
To solve this issue, the client will pass along the namespace which
is being used for the request, allowing mirrors to easily map
to multiple upstreams. This query parameter can safely be ignored
if multiple upstreams are not supported.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2020-08-03 09:32:44 -07:00
Tonis Tiigi
957bcb3dff docker: split private token helper functions to reusable pkg
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-08-02 22:50:46 -07:00
Derek McGowan
3dd8242a67
Add host specific headers
Allows configuring headers per registry host

Signed-off-by: Derek McGowan <derek@mcg.dev>
2020-06-01 18:27:41 -07:00
Sebastiaan van Stijn
dc92ad6520
Replace errors.Cause() with errors.Is()
Dependencies may be switching to use the new `%w` formatting
option to wrap errors; switching to use `errors.Is()` makes
sure that we are still able to unwrap the error and detect the
underlying cause.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-08 14:36:45 +02:00
Alex Price
a022c21819 Improve host fallback behaviour in docker remote
This commit improves the fallback behaviour when resolving and
fetching images with multiple hosts. If an error is encountered
when resolving and fetching images, and more than one host is being
used, we will try the same operation on the next host. The error
from the first host is preserved so that if all hosts fail, we can
display the error from the first host.

fixes #3850

Signed-off-by: Alex Price <aprice@atlassian.com>
2019-12-13 11:42:32 +11:00
Derek McGowan
394db03f15
Fix all media types in Accept header to match RFC
Fixes the media type to align with Accept HTTP header
RFC which specifies glob syntax */*

See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-09-26 14:48:42 -07:00
Derek McGowan
c965a6c4da
Prevent push by tag for sub-manifests
When pushing a manifest list, all manifests should be pushed by digest
and only the final manifest pushed by tag. The Pusher was preventing
this by mistakenly disallowing objects to contain a digest. When objects
have a digest, only push tags associated with that digest.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-07-31 15:19:44 -07:00
Derek McGowan
518be1cb07
Fix bug in setting request body
Go documentation says
`Use of GetBody still requires setting Body`.
This change ensures the body is always set in
addition to GetBody. This fixes a bug where
sometimes the body is nil.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-07-18 11:21:51 -07:00
Derek McGowan
0b29c9c371
Update resolver to handle endpoint configuration
Adds support for registry mirrors
Adds support for multiple pull endpoints
Adds capabilities to limit trust in public mirrors
Fixes user agent header missing


Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-07-16 11:28:23 -07:00
Konstantin Maksimov
3d3dbc8fbf Handle RequestTimeout and TooManyRequests
Retry 5 times in case of StatusRequestTimeout StatusTooManyRequests
This fixes the issue #2680 "Make content fetch retry more robust"

Signed-off-by: Konstantin Maksimov <kmaksimov@gmail.com>
2019-07-01 19:19:40 +03:00
Derek McGowan
bb00872800
Add user agent header to all requests
Currently the user agent is only being used on the initial
resolve request, then switching to the default user agent.
This ensures the correct user agent is always used. There is
a larger fix in progress which does this is a cleaner way, but
the scope of this change is fixing the user agent issue.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-06-11 22:57:58 +08:00
msg555
ee902afa5f Compute manifest metadata when not provided.
This closes #3238

Signed-off-by: msg555 <msg555@gmail.com>
2019-05-01 00:53:16 -04:00
Derek McGowan
b8631c750c
Merge pull request #2751 from Charliekenney23/add-useragent-resolver-option
Add custom headers resolver option
2018-11-20 10:51:10 -08:00
Charles Kenney
068880ff16 Add custom headers option to dockerResolver
Signed-off-by: Charles Kenney <charlesc.kenney@gmail.com>
2018-10-31 19:42:42 -04:00
Charles Kenney
7c85d873a0 fix typo in ResolverOptions.Credentials documentation
Signed-off-by: Charles Kenney <charlesc.kenney@gmail.com>
2018-10-31 11:06:28 -04:00
Derek McGowan
a6198b7692
Update resolver code
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-09-28 14:32:23 -07:00
Lantao Liu
c8a8a49584 Support specifying host in resolver.
Signed-off-by: Lantao Liu <lantaol@google.com>
2018-07-09 18:26:02 -07:00