summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiaan van Stijn <thaJeztah@users.noreply.github.com>2022-11-03 22:27:37 +0100
committerGitHub <noreply@github.com>2022-11-03 22:27:37 +0100
commite24277883f65a4bb2ff4180e64243abc0e2647ba (patch)
tree80aa86b600a3981230e7ae47d37040be647b0fcb
parent4b79d9078a66e39e0b92e8e33b28e31d0fe7c354 (diff)
parent07e84005ace3430be900bea14fdd176b9ac895b0 (diff)
downloaddocker-e24277883f65a4bb2ff4180e64243abc0e2647ba.tar.gz
Merge pull request #44405 from vvoland/oci-artifacts-error-2206
[22.06 backport] distribution: Error when pulling OCI artifacts
-rw-r--r--distribution/errors.go17
-rw-r--r--distribution/pull_v2.go23
2 files changed, 39 insertions, 1 deletions
diff --git a/distribution/errors.go b/distribution/errors.go
index fa1e2214eb..d0de8d9e19 100644
--- a/distribution/errors.go
+++ b/distribution/errors.go
@@ -63,6 +63,19 @@ func (e notFoundError) Cause() error {
return e.cause
}
+// unsupportedMediaTypeError is an error issued when attempted
+// to pull unsupported content.
+type unsupportedMediaTypeError struct {
+ MediaType string
+}
+
+func (e unsupportedMediaTypeError) InvalidParameter() {}
+
+// Error returns the error string for unsupportedMediaTypeError.
+func (e unsupportedMediaTypeError) Error() string {
+ return "unsupported media type " + e.MediaType
+}
+
// translatePullError is used to convert an error from a registry pull
// operation to an error representing the entire pull operation. Any error
// information which is not used by the returned error gets output to
@@ -124,6 +137,8 @@ func continueOnError(err error, mirrorEndpoint bool) bool {
// Failures from a mirror endpoint should result in fallback to the
// canonical repo.
return mirrorEndpoint
+ case unsupportedMediaTypeError:
+ return false
case error:
return !strings.Contains(err.Error(), strings.ToLower(syscall.ESRCH.Error()))
}
@@ -153,7 +168,7 @@ func retryOnError(err error) error {
return xfer.DoNotRetry{Err: v.Err}
}
return retryOnError(v.Err)
- case *client.UnexpectedHTTPResponseError:
+ case *client.UnexpectedHTTPResponseError, unsupportedMediaTypeError:
return xfer.DoNotRetry{Err: err}
case error:
if err == distribution.ErrBlobUnknown {
diff --git a/distribution/pull_v2.go b/distribution/pull_v2.go
index 2af5251fd5..420a5af436 100644
--- a/distribution/pull_v2.go
+++ b/distribution/pull_v2.go
@@ -7,6 +7,7 @@ import (
"io"
"os"
"runtime"
+ "strings"
"time"
"github.com/containerd/containerd/log"
@@ -606,6 +607,21 @@ func (p *puller) pullSchema1(ctx context.Context, ref reference.Reference, unver
return imageID, manifestDigest, nil
}
+func checkSupportedMediaType(mediaType string) error {
+ supportedMediaTypes := []string{
+ "application/vnd.oci.image.",
+ "application/vnd.docker.",
+ }
+
+ lowerMt := strings.ToLower(mediaType)
+ for _, mt := range supportedMediaTypes {
+ if strings.HasPrefix(lowerMt, mt) {
+ return nil
+ }
+ }
+ return unsupportedMediaTypeError{MediaType: mediaType}
+}
+
func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Descriptor, layers []distribution.Descriptor, platform *specs.Platform) (id digest.Digest, err error) {
if _, err := p.config.ImageStore.Get(ctx, target.Digest); err == nil {
// If the image already exists locally, no need to pull
@@ -613,6 +629,10 @@ func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Desc
return target.Digest, nil
}
+ if err := checkSupportedMediaType(target.MediaType); err != nil {
+ return "", err
+ }
+
var descriptors []xfer.DownloadDescriptor
// Note that the order of this loop is in the direction of bottom-most
@@ -621,6 +641,9 @@ func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Desc
if err := d.Digest.Validate(); err != nil {
return "", errors.Wrapf(err, "could not validate layer digest %q", d.Digest)
}
+ if err := checkSupportedMediaType(d.MediaType); err != nil {
+ return "", err
+ }
layerDescriptor := &layerDescriptor{
digest: d.Digest,
repo: p.repo,