From 40c56bf1b6fb7715d05286742753e8c32ffafaba Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Thu, 17 Aug 2023 20:57:02 +0100 Subject: [PATCH] Keep returning image for default arch to old clients fetching lists This puts back the original flow where old clients are fetching manifest lists schema1 images where we want to try returning some image for the default architecture. This was incorrectly removed by one of the previous commits. Signed-off-by: Milos Gajdos --- registry/handlers/manifests.go | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/registry/handlers/manifests.go b/registry/handlers/manifests.go index ac297b630..e5815f3d0 100644 --- a/registry/handlers/manifests.go +++ b/registry/handlers/manifests.go @@ -23,6 +23,8 @@ import ( ) const ( + defaultArch = "amd64" + defaultOS = "linux" maxManifestBodySize = 4 << 20 imageClass = "image" ) @@ -166,6 +168,43 @@ func (imh *manifestHandler) GetManifest(w http.ResponseWriter, r *http.Request) return } + if imh.Tag != "" && manifestType == manifestlistSchema && !supports[manifestlistSchema] { + // Rewrite manifest in schema1 format + dcontext.GetLogger(imh).Infof("rewriting manifest list %s in schema1 format to support old client", imh.Digest.String()) + + // Find the image manifest corresponding to the default + // platform + var manifestDigest digest.Digest + for _, manifestDescriptor := range manifestList.Manifests { + if manifestDescriptor.Platform.Architecture == defaultArch && manifestDescriptor.Platform.OS == defaultOS { + manifestDigest = manifestDescriptor.Digest + break + } + } + + if manifestDigest == "" { + imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown) + return + } + + manifest, err = manifests.Get(imh, manifestDigest) + if err != nil { + if _, ok := err.(distribution.ErrManifestUnknownRevision); ok { + imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown.WithDetail(err)) + } else { + imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err)) + } + return + } + + if _, isSchema2 := manifest.(*schema2.DeserializedManifest); isSchema2 && !supports[manifestSchema2] { + imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithMessage("Schema 2 manifest not supported by client")) + return + } else { + imh.Digest = manifestDigest + } + } + ct, p, err := manifest.Payload() if err != nil { return