Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20.10 backport] distribution: checkSupportedMediaType: allow additional media-types #44569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions distribution/pull_v2.go
Expand Up @@ -620,14 +620,12 @@ func (p *v2Puller) pullSchema1(ctx context.Context, ref reference.Reference, unv
}

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) {
// The should either be an exact match, or have a valid prefix
// we append a "." when matching prefixes to exclude "false positives";
// for example, we don't want to match "application/vnd.oci.images_are_fun_yolo".
if lowerMt == mt || strings.HasPrefix(lowerMt, mt+".") {
return nil
}
}
Expand Down
16 changes: 16 additions & 0 deletions distribution/registry.go
Expand Up @@ -19,6 +19,22 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

// supportedMediaTypes represents acceptable media-type(-prefixes)
// we use this list to prevent obscure errors when trying to pull
// OCI artifacts.
var supportedMediaTypes = []string{
// valid prefixes
"application/vnd.oci.image",
"application/vnd.docker",

// these types may occur on old images, and are copied from
// ImageTypes below.
"application/octet-stream",
"application/json",
"text/html",
"",
}

// ImageTypes represents the schema2 config types for images
var ImageTypes = []string{
schema2.MediaTypeImageConfig,
Expand Down