Commit Graph
290 Commits
Author SHA1 Message Date
沈陵 f61de08644 fix bug that using invalid token to retry fetching layer
Signed-off-by: frankyang <yyb196@gmail.com>
2024-04-11 14:19:18 +08:00
Kohei Tokunaga 18f4ad5ee0 remote: Fix HTTPFallback fails when pushing manifest
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2024-04-08 15:40:54 +09:00
Justin Chadwell 52a1402df6 copy: prevent potential deadlock if close before fully written
We also need an additional check to avoid setting both the error and
response which can create a race where they can arrive in the receiving
thread in either order.

If we hit an error, we don't need to send the response.

> There is a condition where the registry (unexpectedly, not to spec)
> returns 201 or 204 on the put before the body is fully written. I would
> expect that the http library would issue close and could fall into a
> deadlock here. We could just read respC and call setResponse. In that
> case ErrClosedPipe would get returned and Commit shouldn't be called
> anyway.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-04 12:59:45 +00:00
Justin Chadwell 8727463862 copy: setError should imply Close
If sending two messages from goroutine X:

	a <- 1
	b <- 2

And receiving them in goroutine Y:

	select {
	case <- a:
	case <- b:
	}

Either branch of the select can trigger first - so when we call
.setError and .Close next to each other, we don't know whether the done
channel will close first or the error channel will receive first - so
sometimes, we get an incorrect error message.

We resolve this by not sending both signals - instead, we can have
.setError *imply* .Close, by having the pushWriter call .Close on
itself, after receiving an error.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-04 12:59:45 +00:00
Justin Chadwell 0465472ed3 pushWriter: refactor reset pipe logic into separate function
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-04 12:58:52 +00:00
Justin Chadwell 2577207cc0 copy: improve error detection from closed pipes
If we get io.ErrClosedPipe in pushWriter.Write, there are three possible
scenarios:

- The request has failed, we need to attempt a reset, so we can expect a
  new pipe incoming on pipeC.
- The request has failed, we don't need to attempt a reset, so we can
  expect an incoming error on errC.
- Something else externally has called Close, so we can expect the done
  channel to be closed.

This patch ensures that we block for as long as possible (while still
handling each of the above cases, so we avoid hanging), to make sure
that we properly return an appropriate error message each time.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-04 12:58:52 +00:00
Justin Chadwell d081da86bf copy: check if writer was closed before setting a pipe
If Close is called externally before a request is attempted, then we
will accidentally attempt to send to a closed channel, causing a panic.

To avoid this, we can check to see if Close has been called, using a
done channel. If this channel is ever done, we drop any incoming errors,
requests or pipes - we don't need them, since we're done.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-04 12:58:52 +00:00
Justin Chadwell 2a25c085b2 copy: remove wrapping io.NopCloser from push writer pipe
io.Pipe produces a PipeReader and a PipeWriter - a close on the write
side, causes an error on both the read and write sides, while a close on
the read side causes an error on only the read side. Previously, we
explicitly prohibited closing from the read side.

However, http.Request.Body requires that "calling Close should unblock a
Read waiting for input". Our reader will not do this - calling close
becomes a no-op. This can cause a deadlock because client.Do may never
terminate in some circumstances.

We need the Reader side to close its side of the pipe as well, which it
already does using the go standard library - otherwise, we can hang
forever, writing to a pipe that will never be closed.

Allowing the requester to close the body should be safe - we never reuse
the same reader between requests, as the result of body() will never be
reused by the guarantees of the standard library.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-04 12:58:51 +00:00
Kohei Tokunaga b16ca72b2e Bump up golangci-lint to v1.54.2
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
(cherry picked from commit 6e2c915a44)
Signed-off-by: Akhil Mohan <akhil.mohan@broadcom.com>
2024-03-01 14:46:21 +05:30
Derek McGowan f8f659e66c Add HTTP client update function to tracing library
Signed-off-by: Derek McGowan <derek@mcg.dev>
(cherry picked from commit 8203bb9977)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-12-06 11:46:12 -08:00
Milas Bowman 807ddd658b fix(tracing): use latest version of semconv
All components need to use a consistent `semconv` version or OTel
will emit errors about "cannot merge resource due to conflicting Schema URL".

Switch to the appropriate semconv version, which requires dropping
usage of `httpconv`. Instead, the upstream HTTP client hooks are
used directly. (The lower-level functions are no longer exported by
OTel.)

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
(cherry picked from commit ad3b806a4f)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-12-06 11:46:12 -08:00
Paweł Gronowski 4464fde129 push: always inherit distribution sources from parent
Propagate parent distribution source labels to each of its children even
if they're not missing. This allows to cross-repo mount blobs when the
child content has different distribution source label from its
parent manifest/index. This could happen when different parts of image
were fetched from different sources.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-12-01 08:03:51 +00:00
Wei Fu 2068061289 remotes/docker: close connection if no more data
Close connection if no more data. It's to fix false alert filed by image
pull progress.

```
dst = OpenWriter (--> Content Store)

src = Fetch
        Open (--> Registry)
        Mark it as active request

Copy(dst, src) (--> Keep updating total received bytes)

   ^
   |  (Active Request > 0, but total received bytes won't be updated)
   v

defer src.Close()
content.Commit(dst)
```

Before migrating to transfer service, CRI plugin doesn't limit global
concurrent downloads for ImagePulls. Each ImagePull requests have 3 concurrent
goroutines to download blob and 1 goroutine to unpack blob. Like ext4
filesystem [1][1], the fsync from content.Commit may sync unrelated dirty pages
into disk. The host is running under IO pressure, and then the content.Commit
will take long time and block other goroutines. If httpreadseeker
doesn't close the connection after io.EOF, this connection will be
considered as active. The pull progress reporter reports there is no
bytes transfered and cancels the ImagePull.

The original 1-minute timeout[2][2] is from kubelet settting. Since CRI-plugin
can't limit the total concurrent downloads, this patch is to update 1-minute
to 5-minutes to prevent from unexpected cancel.

[1]: https://lwn.net/Articles/842385/
[2]: https://github.com/kubernetes/kubernetes/blob/release-1.23/pkg/kubelet/config/flags.go#L45-L48

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-11-21 23:31:42 +00:00
Derek McGowan 68abc543b1 Check scheme and host of request on push redirect
When the HTTP fallback is used, the scheme changes from HTTPS to HTTP
which can cause a mismatch on redirect, causing the authorizer to get
stripped out. Since the redirect host must match the redirect host in
this case, credentials are only sent to the same origin host that
returned the redirect.

This fixes an issue for a push getting a 401 unauthorized on the PUT
request even though credentials are available.

Signed-off-by: Derek McGowan <derek@mcg.dev>
(cherry picked from commit 466ee870d5)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-10-25 21:35:29 -07:00
Derek McGowan 35c7634e33 Avoid TLS fallback when protocol is not ambiguous
The TLS fallback should only be used when the protocol is ambiguous due
to provided TLS configurations and defaulting to http. Do not add TLS
configurations when defaulting to http. When the port is 80 or will be
defaulted to 80, there is no protocol ambiguity and TLS fallback should
not be used.

Signed-off-by: Derek McGowan <derek@mcg.dev>
(cherry picked from commit d48ceb6065)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-10-25 21:35:28 -07:00
Derek McGowan 6cd2cc4a8f remotes: add handling for missing basic auth credentials
When a credential handler is provided but no basic auth credentials
are provided, handle the error specifically rather than treating
the credentials as not implemented. This allows a clearer error to
be provided to users rather than a confusing not implemented error
or generic unauthorized error.

Add unit tests for the basic auth case.

Signed-off-by: Derek McGowan <derek@mcg.dev>
(cherry picked from commit 51c9ffe468)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-10-13 16:51:30 -07:00
Phil Estes 72e02001f2 Merge pull request #9193 from vvoland/remotes-docker-mounted-fix-1.7
[release 1.7] remotes/docker: Fix MountedFrom prefixed with target repository
2023-10-04 13:59:08 -04:00
Paweł Gronowski 7df492a95c remotes/docker: Fix MountedFrom prefixed with target repository
`MountedFrom` was prefixed with the whole target repository instead of
just the registry hostname.

Also adjust the test cases to use the registry hostname.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit 859c2651e5)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-10-04 10:07:33 +02:00
Derek McGowan 7779ce64e5 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>
(cherry picked from commit 79772a0dd4)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-10-03 09:35:07 -07:00
Paweł Gronowski 8cd2d33c2a [release/1.7] remotes/docker: Add MountedFrom and Exists push status
This makes it possible to check whether content didn't actually need to
be pushed to the remote registry and was cross-repo mounted or already
existed.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit dfc7590d5a)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-09-14 16:34:10 +02:00
Derek McGowan 5ebf05d97e push: inherit distribution sources from parent
When a blob does not exist locally, rather than erroring on info
lookup, inherit the parent distribution sources. Push is able
to succeed even if the blob does not exist locally when a cross
repository mount is done. This is a common operation pushing a
multi-platform image to the same registry but different namespace.

Signed-off-by: Derek McGowan <derek@mcg.dev>
(cherry picked from commit 20f79300cf)
Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-09-11 10:17:36 -07:00
Sebastiaan van Stijn df76aaede4 removes/docker: remove unnecessary conversion (unconvert)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e2ad5a985e)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-24 00:28:13 +02:00
Jin Dong 898eca21e3 Change http.Header copy to builtin Clone
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
(cherry picked from commit 83ff030e4f)
Signed-off-by: Jin Dong <jin.dong@databricks.com>
2023-07-10 12:30:22 -07:00
Jin Dong fa2efc406f Resolve docker.NewResolver race condition
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
(cherry picked from commit cdb153ec92)
Signed-off-by: Jin Dong <jin.dong@databricks.com>
2023-07-10 12:30:11 -07:00
Sebastiaan van Stijn eeda70fb04 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>
(cherry picked from commit 52997ea983)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-06-01 09:31:34 +02:00
Paweł Gronowski dd3eedf3c3 labels: Add LabelDistributionSource
Add a public const for "containerd.io/distribution.source" in `labels`
package and replace hardcoded usages.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2023-03-08 10:01:58 +01:00
Tony Fang 47305392c6 Add configuration options to local transfer service
Signed-off-by: Tony Fang <nhfang@amazon.com>
2023-02-25 03:40:06 +00:00
Fu Wei 8cb00f45c9 Merge pull request #8143 from mxpv/log
Add Fields type alias to log package
2023-02-21 10:22:23 +08: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
Akihiro Suda 8bf975b4fa lint: silence "type HostFileConfig is unused (unused)"
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-02-16 03:50:22 +09:00
Fu Wei 218b1a335e Merge pull request #8076 from cpuguy83/use_data_in_descriptor
fetch: Use data from descriptor when available.
2023-02-10 15:50:17 +08:00
Fish-pro 76a62e52ae Use http constants instead of string
Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
2023-02-10 14:01:48 +08:00
Brian Goff 13652e081e fetch: Use data from descriptor when available.
OCI added support for a `data` field in a descriptor.
This field is expected to contain the content being pointed to by the
descriptor.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-02-10 01:12:40 +00:00
Justin Chadwell 9f6058d029 pushWriter: correctly propagate errors
In the refactor from 926b9c72f6, the error
handling was substantially reworked, and changed the types of errors
returned.

Notably, in the case of a network error, instead of propogating the
error through to return from pushWriter.Write (as previously), it would
be propagated through to pushWriter.Commit - however, this is too late,
since we've already closed the io.Pipe by the time we would have reached
this function. Therefore, we get the generic error message  "io:
read/write on closed pipe" for *every network error*.

This patch corrects this behavior to ensure that the correct error
object is always returned as early as possible, by checking the error
result after writing and detecting a closed pipe.

Additionally, we do some additional hardening - specifically we prevent
falling through when resetting the content or detecting errors, and
update the tests to explicitly check for the ErrReset message.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-01-24 11:37:41 +00:00
Akihiro Suda 4adf3fb3af Merge pull request #7906 from Iceber/use_label_uncompressed
Use the const labels.LabelUncompressed
2023-01-04 01:04:20 +09:00
Iceber Gu 778e8f2af4 Use the const labels.LabelUncompressed
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2023-01-03 18:29:21 +08:00
Wei Fu 6b7e237fc7 chore: use go fix to cleanup old +build buildtag
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2022-12-29 14:25:14 +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
Brian Goff 840a657ebc Change PushContent to require only Provider
Before this required a full content.Store so that it could annotate
distribution sources.
With this change PushContent can be used with just a content.Provider.
If the content.Provider is also a content.Manager then distribution
sources will be updated accordingly.

This allows people to use this function with a significantly
implementation.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2022-12-06 17:33:33 +00:00
Phil Estes 5d4276cc34 Merge pull request #7525 from thaJeztah/remove_deprecated_stubs
remove some (aliases for) deprecated functions
2022-12-06 11:49:18 -05:00
Derek McGowan 9ae92f16e0 Improve push handler ordering
Allow manifest uploads to happen in parallel and defer
manifest list and index until end.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2022-11-30 12:56:55 -08:00
Derek McGowan 81afd9c36e Add progress
Signed-off-by: Derek McGowan <derek@mcg.dev>

Update progress to reference parents

Signed-off-by: Derek McGowan <derek@mcg.dev>

Update Progress logic

Signed-off-by: Derek McGowan <derek@mcg.dev>
2022-11-30 12:56:52 -08:00
Sebastiaan van Stijn f0ce2f6d36 remotes/docker: remove deprecated NewAuthorizer alias
This was deprecated since containerd v1.3.0.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-20 22:27:21 +01: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
Derek McGowan 31bb8fef7e Merge pull request #7460 from AkihiroSuda/fetch-by-digest
remotes: add `FetcherByDigest` for fetching blobs without foreknown descriptors (useful for general-purpose CAS)
2022-11-04 15:20:29 -07:00
Kazuyoshi Kato e306680f44 Merge pull request #7607 from jess-sol/main
Support default hosts.toml configuration
2022-11-04 10:22:00 -07:00
Akihiro Suda dfd6a3aa6e remotes: add FetcherByDigest for fetching blobs without foreknown descriptors
Fetching blobs without foreknown descriptors is useful for using a registry as a general-purpose CAS.

Related: `oras blob fetch` (ORAS v0.15.0)

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-11-04 11:41:07 +09:00