Browse Source

Merge pull request #46492 from rumpl/c8d-tag-digest-name

c8d: Refuse images with digest algo when tagging
Sebastiaan van Stijn 1 year ago
parent
commit
a1833d8b4d
1 changed files with 6 additions and 0 deletions
  1. 6 0
      api/server/router/image/image_routes.go

+ 6 - 0
api/server/router/image/image_routes.go

@@ -24,6 +24,7 @@ import (
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/progress"
 	"github.com/docker/docker/pkg/streamformatter"
+	"github.com/opencontainers/go-digest"
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
 	"github.com/pkg/errors"
 )
@@ -415,6 +416,11 @@ func (ir *imageRouter) postImagesTag(ctx context.Context, w http.ResponseWriter,
 		return errdefs.InvalidParameter(err)
 	}
 
+	refName := reference.FamiliarName(ref)
+	if refName == string(digest.Canonical) {
+		return errdefs.InvalidParameter(errors.New("refusing to create an ambiguous tag using digest algorithm as name"))
+	}
+
 	img, err := ir.backend.GetImage(ctx, vars["name"], opts.GetImageOpts{})
 	if err != nil {
 		return errdefs.NotFound(err)