From 2a047e994ad1ca9087fe2c441b1cece2fce4f466 Mon Sep 17 00:00:00 2001 From: Adam Wolfe Gordon Date: Tue, 2 Jun 2020 15:25:22 -0600 Subject: [PATCH] manifests: Return UNSUPPORTED when deleting manifests by tag The OCI distribution spec allows implementations to support deleting manifests by tag, but also permits returning the `UNSUPPORTED` error code for such requests. docker/distribution has never supported deleting manifests by tag, but previously returned `DIGEST_INVALID`. The `Tag` and `Digest` fields of the `manifestHandler` are already correctly populated based on which kind of reference was given in the request URL. Return `UNSUPPORTED` if the `Tag` field is populated. Signed-off-by: Adam Wolfe Gordon --- registry/handlers/manifests.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/registry/handlers/manifests.go b/registry/handlers/manifests.go index 6f2f51789..1fb17813c 100644 --- a/registry/handlers/manifests.go +++ b/registry/handlers/manifests.go @@ -15,11 +15,11 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" "github.com/docker/distribution/registry/auth" "github.com/gorilla/handlers" "github.com/opencontainers/go-digest" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" ) // These constants determine which architecture and OS to choose from a @@ -485,6 +485,11 @@ func (imh *manifestHandler) applyResourcePolicy(manifest distribution.Manifest) func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Request) { dcontext.GetLogger(imh).Debug("DeleteImageManifest") + if imh.Tag != "" { + imh.Errors = append(imh.Errors, errcode.ErrorCodeUnsupported) + return + } + manifests, err := imh.Repository.Manifests(imh) if err != nil { imh.Errors = append(imh.Errors, err)