2015-02-11 02:25:40 +01:00
|
|
|
package handlers
|
2014-11-11 03:57:38 +01:00
|
|
|
|
|
|
|
import (
|
2015-07-30 03:18:50 +02:00
|
|
|
"bytes"
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
"fmt"
|
2019-02-21 23:07:57 +01:00
|
|
|
"mime"
|
2014-11-11 03:57:38 +01:00
|
|
|
"net/http"
|
2016-06-11 01:34:08 +02:00
|
|
|
"strings"
|
2014-11-11 03:57:38 +01:00
|
|
|
|
2020-08-24 13:18:39 +02:00
|
|
|
"github.com/distribution/distribution/v3"
|
|
|
|
dcontext "github.com/distribution/distribution/v3/context"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/manifestlist"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/ocischema"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/schema1"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/schema2"
|
|
|
|
"github.com/distribution/distribution/v3/reference"
|
|
|
|
"github.com/distribution/distribution/v3/registry/api/errcode"
|
|
|
|
v2 "github.com/distribution/distribution/v3/registry/api/v2"
|
|
|
|
"github.com/distribution/distribution/v3/registry/auth"
|
2014-11-11 03:57:38 +01:00
|
|
|
"github.com/gorilla/handlers"
|
2016-12-17 01:28:34 +01:00
|
|
|
"github.com/opencontainers/go-digest"
|
2019-10-09 14:02:21 +02:00
|
|
|
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
2014-11-11 03:57:38 +01:00
|
|
|
)
|
|
|
|
|
2015-12-18 02:32:11 +01:00
|
|
|
// These constants determine which architecture and OS to choose from a
|
|
|
|
// manifest list when downconverting it to a schema1 manifest.
|
|
|
|
const (
|
2017-07-07 01:01:26 +02:00
|
|
|
defaultArch = "amd64"
|
|
|
|
defaultOS = "linux"
|
|
|
|
maxManifestBodySize = 4 << 20
|
2017-07-18 23:20:37 +02:00
|
|
|
imageClass = "image"
|
2015-12-18 02:32:11 +01:00
|
|
|
)
|
|
|
|
|
2017-07-20 19:48:46 +02:00
|
|
|
type storageType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
manifestSchema1 storageType = iota // 0
|
|
|
|
manifestSchema2 // 1
|
|
|
|
manifestlistSchema // 2
|
|
|
|
ociSchema // 3
|
|
|
|
ociImageIndexSchema // 4
|
|
|
|
numStorageTypes // 5
|
|
|
|
)
|
|
|
|
|
2017-01-11 00:16:45 +01:00
|
|
|
// manifestDispatcher takes the request context and builds the
|
|
|
|
// appropriate handler for handling manifest requests.
|
|
|
|
func manifestDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|
|
|
manifestHandler := &manifestHandler{
|
2014-11-11 03:57:38 +01:00
|
|
|
Context: ctx,
|
2015-02-27 00:47:04 +01:00
|
|
|
}
|
|
|
|
reference := getReference(ctx)
|
2016-12-16 00:07:42 +01:00
|
|
|
dgst, err := digest.Parse(reference)
|
2015-02-27 00:47:04 +01:00
|
|
|
if err != nil {
|
|
|
|
// We just have a tag
|
2017-01-11 00:16:45 +01:00
|
|
|
manifestHandler.Tag = reference
|
2015-02-27 00:47:04 +01:00
|
|
|
} else {
|
2017-01-11 00:16:45 +01:00
|
|
|
manifestHandler.Digest = dgst
|
2014-11-11 03:57:38 +01:00
|
|
|
}
|
|
|
|
|
2015-08-07 03:02:43 +02:00
|
|
|
mhandler := handlers.MethodHandler{
|
2017-01-11 00:16:45 +01:00
|
|
|
"GET": http.HandlerFunc(manifestHandler.GetManifest),
|
|
|
|
"HEAD": http.HandlerFunc(manifestHandler.GetManifest),
|
2014-11-11 03:57:38 +01:00
|
|
|
}
|
2015-08-07 03:02:43 +02:00
|
|
|
|
|
|
|
if !ctx.readOnly {
|
2017-01-11 00:16:45 +01:00
|
|
|
mhandler["PUT"] = http.HandlerFunc(manifestHandler.PutManifest)
|
|
|
|
mhandler["DELETE"] = http.HandlerFunc(manifestHandler.DeleteManifest)
|
2015-08-07 03:02:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return mhandler
|
2014-11-11 03:57:38 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 00:16:45 +01:00
|
|
|
// manifestHandler handles http operations on image manifests.
|
|
|
|
type manifestHandler struct {
|
2014-11-11 03:57:38 +01:00
|
|
|
*Context
|
|
|
|
|
2015-02-27 00:47:04 +01:00
|
|
|
// One of tag or digest gets set, depending on what is present in context.
|
|
|
|
Tag string
|
|
|
|
Digest digest.Digest
|
2014-11-11 03:57:38 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 00:16:45 +01:00
|
|
|
// GetManifest fetches the image manifest from the storage backend, if it exists.
|
|
|
|
func (imh *manifestHandler) GetManifest(w http.ResponseWriter, r *http.Request) {
|
2017-08-12 00:31:16 +02:00
|
|
|
dcontext.GetLogger(imh).Debug("GetImageManifest")
|
2015-06-15 19:39:34 +02:00
|
|
|
manifests, err := imh.Repository.Manifests(imh)
|
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, err)
|
|
|
|
return
|
|
|
|
}
|
2017-07-20 19:48:46 +02:00
|
|
|
var supports [numStorageTypes]bool
|
|
|
|
|
2016-11-17 19:28:05 +01:00
|
|
|
// this parsing of Accept headers is not quite as full-featured as godoc.org's parser, but we don't care about "q=" values
|
|
|
|
// https://github.com/golang/gddo/blob/e91d4165076d7474d20abda83f92d15c7ebc3e81/httputil/header/header.go#L165-L202
|
|
|
|
for _, acceptHeader := range r.Header["Accept"] {
|
|
|
|
// r.Header[...] is a slice in case the request contains the same header more than once
|
|
|
|
// if the header isn't set, we'll get the zero value, which "range" will handle gracefully
|
|
|
|
|
|
|
|
// we need to split each header value on "," to get the full list of "Accept" values (per RFC 2616)
|
|
|
|
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
|
|
|
for _, mediaType := range strings.Split(acceptHeader, ",") {
|
2019-02-21 23:07:57 +01:00
|
|
|
if mediaType, _, err = mime.ParseMediaType(mediaType); err != nil {
|
|
|
|
continue
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if mediaType == schema2.MediaTypeManifest {
|
2017-07-20 19:48:46 +02:00
|
|
|
supports[manifestSchema2] = true
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
|
|
|
if mediaType == manifestlist.MediaTypeManifestList {
|
2017-07-20 19:48:46 +02:00
|
|
|
supports[manifestlistSchema] = true
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
2017-07-11 21:19:47 +02:00
|
|
|
if mediaType == v1.MediaTypeImageManifest {
|
2017-07-20 19:48:46 +02:00
|
|
|
supports[ociSchema] = true
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
2017-07-11 21:19:47 +02:00
|
|
|
if mediaType == v1.MediaTypeImageIndex {
|
2017-07-20 19:48:46 +02:00
|
|
|
supports[ociImageIndexSchema] = true
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-27 00:47:04 +01:00
|
|
|
|
|
|
|
if imh.Tag != "" {
|
2015-08-21 06:50:15 +02:00
|
|
|
tags := imh.Repository.Tags(imh)
|
2017-07-21 03:44:02 +02:00
|
|
|
desc, err := tags.Get(imh, imh.Tag)
|
2015-08-21 06:50:15 +02:00
|
|
|
if err != nil {
|
2017-01-11 21:10:16 +01:00
|
|
|
if _, ok := err.(distribution.ErrTagUnknown); ok {
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown.WithDetail(err))
|
|
|
|
} else {
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
|
|
|
}
|
2015-06-19 01:56:05 +02:00
|
|
|
return
|
|
|
|
}
|
2015-08-21 06:50:15 +02:00
|
|
|
imh.Digest = desc.Digest
|
|
|
|
}
|
|
|
|
|
|
|
|
if etagMatch(r, imh.Digest.String()) {
|
|
|
|
w.WriteHeader(http.StatusNotModified)
|
|
|
|
return
|
2015-02-27 00:47:04 +01:00
|
|
|
}
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
|
2016-03-18 23:30:47 +01:00
|
|
|
var options []distribution.ManifestServiceOption
|
|
|
|
if imh.Tag != "" {
|
2017-07-18 23:20:37 +02:00
|
|
|
options = append(options, distribution.WithTag(imh.Tag))
|
2016-03-18 23:30:47 +01:00
|
|
|
}
|
2017-07-21 03:44:02 +02:00
|
|
|
manifest, err := manifests.Get(imh, imh.Digest, options...)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
if err != nil {
|
2017-01-11 21:10:16 +01:00
|
|
|
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))
|
|
|
|
}
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
return
|
|
|
|
}
|
2017-07-20 19:48:46 +02:00
|
|
|
// determine the type of the returned manifest
|
|
|
|
manifestType := manifestSchema1
|
2016-11-17 19:28:05 +01:00
|
|
|
schema2Manifest, isSchema2 := manifest.(*schema2.DeserializedManifest)
|
|
|
|
manifestList, isManifestList := manifest.(*manifestlist.DeserializedManifestList)
|
2017-07-20 19:48:46 +02:00
|
|
|
if isSchema2 {
|
|
|
|
manifestType = manifestSchema2
|
|
|
|
} else if _, isOCImanifest := manifest.(*ocischema.DeserializedManifest); isOCImanifest {
|
|
|
|
manifestType = ociSchema
|
|
|
|
} else if isManifestList {
|
|
|
|
if manifestList.MediaType == manifestlist.MediaTypeManifestList {
|
|
|
|
manifestType = manifestlistSchema
|
|
|
|
} else if manifestList.MediaType == v1.MediaTypeImageIndex {
|
|
|
|
manifestType = ociImageIndexSchema
|
|
|
|
}
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
2017-07-20 19:48:46 +02:00
|
|
|
|
|
|
|
if manifestType == ociSchema && !supports[ociSchema] {
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown.WithMessage("OCI manifest found, but accept header does not support OCI manifests"))
|
2016-11-17 19:28:05 +01:00
|
|
|
return
|
|
|
|
}
|
2017-07-20 19:48:46 +02:00
|
|
|
if manifestType == ociImageIndexSchema && !supports[ociImageIndexSchema] {
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown.WithMessage("OCI index found, but accept header does not support OCI indexes"))
|
2016-11-17 19:28:05 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// Only rewrite schema2 manifests when they are being fetched by tag.
|
|
|
|
// If they are being fetched by digest, we can't return something not
|
|
|
|
// matching the digest.
|
2017-07-20 19:48:46 +02:00
|
|
|
if imh.Tag != "" && manifestType == manifestSchema2 && !supports[manifestSchema2] {
|
2016-11-17 19:28:05 +01:00
|
|
|
// Rewrite manifest in schema1 format
|
2017-09-01 04:14:40 +02:00
|
|
|
dcontext.GetLogger(imh).Infof("rewriting manifest %s in schema1 format to support old client", imh.Digest.String())
|
2016-11-17 19:28:05 +01:00
|
|
|
|
|
|
|
manifest, err = imh.convertSchema2Manifest(schema2Manifest)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-07-20 19:48:46 +02:00
|
|
|
} else if imh.Tag != "" && manifestType == manifestlistSchema && !supports[manifestlistSchema] {
|
2016-11-17 19:28:05 +01:00
|
|
|
// Rewrite manifest in schema1 format
|
2017-09-01 04:14:40 +02:00
|
|
|
dcontext.GetLogger(imh).Infof("rewriting manifest list %s in schema1 format to support old client", imh.Digest.String())
|
2016-11-17 19:28:05 +01:00
|
|
|
|
|
|
|
// 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 necessary, convert the image manifest
|
2017-07-20 19:48:46 +02:00
|
|
|
if schema2Manifest, isSchema2 := manifest.(*schema2.DeserializedManifest); isSchema2 && !supports[manifestSchema2] {
|
2016-11-17 19:28:05 +01:00
|
|
|
manifest, err = imh.convertSchema2Manifest(schema2Manifest)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
imh.Digest = manifestDigest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ct, p, err := manifest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", ct)
|
|
|
|
w.Header().Set("Content-Length", fmt.Sprint(len(p)))
|
|
|
|
w.Header().Set("Docker-Content-Digest", imh.Digest.String())
|
|
|
|
w.Header().Set("Etag", fmt.Sprintf(`"%s"`, imh.Digest))
|
|
|
|
w.Write(p)
|
|
|
|
}
|
|
|
|
|
2017-01-11 00:16:45 +01:00
|
|
|
func (imh *manifestHandler) convertSchema2Manifest(schema2Manifest *schema2.DeserializedManifest) (distribution.Manifest, error) {
|
2015-12-18 02:32:11 +01:00
|
|
|
targetDescriptor := schema2Manifest.Target()
|
|
|
|
blobs := imh.Repository.Blobs(imh)
|
|
|
|
configJSON, err := blobs.Get(imh, targetDescriptor.Digest)
|
|
|
|
if err != nil {
|
2017-01-11 21:10:16 +01:00
|
|
|
if err == distribution.ErrBlobUnknown {
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err))
|
|
|
|
} else {
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
|
|
|
}
|
2015-12-18 02:32:11 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-02-01 22:47:34 +01:00
|
|
|
ref := imh.Repository.Named()
|
2015-12-15 23:35:23 +01:00
|
|
|
|
|
|
|
if imh.Tag != "" {
|
2016-02-01 22:47:34 +01:00
|
|
|
ref, err = reference.WithTag(ref, imh.Tag)
|
2015-12-15 23:35:23 +01:00
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeTagInvalid.WithDetail(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder := schema1.NewConfigManifestBuilder(imh.Repository.Blobs(imh), imh.Context.App.trustKey, ref, configJSON)
|
2016-10-13 02:20:27 +02:00
|
|
|
for _, d := range schema2Manifest.Layers {
|
2017-07-21 03:44:02 +02:00
|
|
|
if err := builder.AppendReference(d); err != nil {
|
2015-12-18 02:32:11 +01:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
manifest, err := builder.Build(imh)
|
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-02-10 03:28:43 +01:00
|
|
|
imh.Digest = digest.FromBytes(manifest.(*schema1.SignedManifest).Canonical)
|
2015-12-18 02:32:11 +01:00
|
|
|
|
|
|
|
return manifest, nil
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:56:05 +02:00
|
|
|
func etagMatch(r *http.Request, etag string) bool {
|
|
|
|
for _, headerVal := range r.Header["If-None-Match"] {
|
2015-07-24 08:03:13 +02:00
|
|
|
if headerVal == etag || headerVal == fmt.Sprintf(`"%s"`, etag) { // allow quoted or unquoted
|
2015-06-19 01:56:05 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-01-11 00:16:45 +01:00
|
|
|
// PutManifest validates and stores a manifest in the registry.
|
|
|
|
func (imh *manifestHandler) PutManifest(w http.ResponseWriter, r *http.Request) {
|
2017-08-12 00:31:16 +02:00
|
|
|
dcontext.GetLogger(imh).Debug("PutImageManifest")
|
2015-06-15 19:39:34 +02:00
|
|
|
manifests, err := imh.Repository.Manifests(imh)
|
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-30 03:18:50 +02:00
|
|
|
var jsonBuf bytes.Buffer
|
2017-08-12 00:31:16 +02:00
|
|
|
if err := copyFullPayload(imh, w, r, &jsonBuf, maxManifestBodySize, "image manifest PUT"); err != nil {
|
2015-07-30 03:18:50 +02:00
|
|
|
// copyFullPayload reports the error if necessary
|
2017-07-07 01:01:26 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err.Error()))
|
2015-07-27 19:00:00 +02:00
|
|
|
return
|
|
|
|
}
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
|
2015-08-21 06:50:15 +02:00
|
|
|
mediaType := r.Header.Get("Content-Type")
|
|
|
|
manifest, desc, err := distribution.UnmarshalManifest(mediaType, jsonBuf.Bytes())
|
2015-02-27 00:47:04 +01:00
|
|
|
if err != nil {
|
2015-08-21 06:50:15 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestInvalid.WithDetail(err))
|
2015-02-27 00:47:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-08-21 06:50:15 +02:00
|
|
|
if imh.Digest != "" {
|
|
|
|
if desc.Digest != imh.Digest {
|
2017-08-12 00:31:16 +02:00
|
|
|
dcontext.GetLogger(imh).Errorf("payload digest does match: %q != %q", desc.Digest, imh.Digest)
|
2015-06-03 15:52:39 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeDigestInvalid)
|
2015-02-27 00:47:04 +01:00
|
|
|
return
|
|
|
|
}
|
2015-08-21 06:50:15 +02:00
|
|
|
} else if imh.Tag != "" {
|
|
|
|
imh.Digest = desc.Digest
|
2015-02-27 00:47:04 +01:00
|
|
|
} else {
|
2015-06-03 15:52:39 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeTagInvalid.WithDetail("no tag or digest specified"))
|
2015-02-27 00:47:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-11 21:19:47 +02:00
|
|
|
isAnOCIManifest := mediaType == v1.MediaTypeImageManifest || mediaType == v1.MediaTypeImageIndex
|
2016-11-17 19:28:05 +01:00
|
|
|
|
|
|
|
if isAnOCIManifest {
|
2017-09-01 04:14:40 +02:00
|
|
|
dcontext.GetLogger(imh).Debug("Putting an OCI Manifest!")
|
2016-11-17 19:28:05 +01:00
|
|
|
} else {
|
2017-09-01 04:14:40 +02:00
|
|
|
dcontext.GetLogger(imh).Debug("Putting a Docker Manifest!")
|
2016-11-17 19:28:05 +01:00
|
|
|
}
|
|
|
|
|
2016-03-18 23:30:47 +01:00
|
|
|
var options []distribution.ManifestServiceOption
|
|
|
|
if imh.Tag != "" {
|
2017-07-18 23:20:37 +02:00
|
|
|
options = append(options, distribution.WithTag(imh.Tag))
|
2016-03-18 23:30:47 +01:00
|
|
|
}
|
2016-11-22 01:36:36 +01:00
|
|
|
|
2017-07-21 03:44:02 +02:00
|
|
|
if err := imh.applyResourcePolicy(manifest); err != nil {
|
2016-11-22 01:36:36 +01:00
|
|
|
imh.Errors = append(imh.Errors, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-03-18 23:30:47 +01:00
|
|
|
_, err = manifests.Put(imh, manifest, options...)
|
2015-08-21 06:50:15 +02:00
|
|
|
if err != nil {
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
// TODO(stevvooe): These error handling switches really need to be
|
|
|
|
// handled by an app global mapper.
|
2015-08-11 20:00:30 +02:00
|
|
|
if err == distribution.ErrUnsupported {
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnsupported)
|
|
|
|
return
|
|
|
|
}
|
2016-02-18 19:37:03 +01:00
|
|
|
if err == distribution.ErrAccessDenied {
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeDenied)
|
|
|
|
return
|
|
|
|
}
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
switch err := err.(type) {
|
2015-02-13 22:59:50 +01:00
|
|
|
case distribution.ErrManifestVerification:
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
for _, verificationError := range err {
|
|
|
|
switch verificationError := verificationError.(type) {
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 09:10:29 +02:00
|
|
|
case distribution.ErrManifestBlobUnknown:
|
2015-09-15 06:12:33 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestBlobUnknown.WithDetail(verificationError.Digest))
|
2015-12-01 22:26:37 +01:00
|
|
|
case distribution.ErrManifestNameInvalid:
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeNameInvalid.WithDetail(err))
|
2015-02-13 22:59:50 +01:00
|
|
|
case distribution.ErrManifestUnverified:
|
2015-06-03 15:52:39 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnverified)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
default:
|
|
|
|
if verificationError == digest.ErrDigestInvalidFormat {
|
2015-06-03 15:52:39 +02:00
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeDigestInvalid)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
} else {
|
2015-06-03 15:52:39 +02:00
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown, verificationError)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 23:34:24 +02:00
|
|
|
case errcode.Error:
|
|
|
|
imh.Errors = append(imh.Errors, err)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
default:
|
2015-06-03 15:52:39 +02:00
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 21:16:58 +01:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2015-02-04 03:27:40 +01:00
|
|
|
|
2015-08-21 06:50:15 +02:00
|
|
|
// Tag this manifest
|
|
|
|
if imh.Tag != "" {
|
|
|
|
tags := imh.Repository.Tags(imh)
|
2017-07-18 23:20:37 +02:00
|
|
|
err = tags.Tag(imh, imh.Tag, desc)
|
2015-08-21 06:50:15 +02:00
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-02-27 00:47:04 +01:00
|
|
|
// Construct a canonical url for the uploaded manifest.
|
2016-02-01 22:47:34 +01:00
|
|
|
ref, err := reference.WithDigest(imh.Repository.Named(), imh.Digest)
|
2015-12-16 01:43:13 +01:00
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
location, err := imh.urlBuilder.BuildManifestURL(ref)
|
2015-02-27 00:47:04 +01:00
|
|
|
if err != nil {
|
|
|
|
// NOTE(stevvooe): Given the behavior above, this absurdly unlikely to
|
|
|
|
// happen. We'll log the error here but proceed as if it worked. Worst
|
|
|
|
// case, we set an empty location header.
|
2017-08-12 00:31:16 +02:00
|
|
|
dcontext.GetLogger(imh).Errorf("error building manifest url from digest: %v", err)
|
2015-02-27 00:47:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Location", location)
|
|
|
|
w.Header().Set("Docker-Content-Digest", imh.Digest.String())
|
2015-07-24 19:42:02 +02:00
|
|
|
w.WriteHeader(http.StatusCreated)
|
2016-11-17 19:28:05 +01:00
|
|
|
|
2017-09-01 04:14:40 +02:00
|
|
|
dcontext.GetLogger(imh).Debug("Succeeded in putting manifest!")
|
2014-11-11 03:57:38 +01:00
|
|
|
}
|
|
|
|
|
2016-11-22 01:36:36 +01:00
|
|
|
// applyResourcePolicy checks whether the resource class matches what has
|
|
|
|
// been authorized and allowed by the policy configuration.
|
2017-01-11 00:16:45 +01:00
|
|
|
func (imh *manifestHandler) applyResourcePolicy(manifest distribution.Manifest) error {
|
2016-11-22 01:36:36 +01:00
|
|
|
allowedClasses := imh.App.Config.Policy.Repository.Classes
|
|
|
|
if len(allowedClasses) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var class string
|
|
|
|
switch m := manifest.(type) {
|
|
|
|
case *schema1.SignedManifest:
|
2017-07-18 23:20:37 +02:00
|
|
|
class = imageClass
|
2016-11-22 01:36:36 +01:00
|
|
|
case *schema2.DeserializedManifest:
|
|
|
|
switch m.Config.MediaType {
|
2016-12-15 01:17:20 +01:00
|
|
|
case schema2.MediaTypeImageConfig:
|
2017-07-18 23:20:37 +02:00
|
|
|
class = imageClass
|
2016-11-22 01:36:36 +01:00
|
|
|
case schema2.MediaTypePluginConfig:
|
|
|
|
class = "plugin"
|
|
|
|
default:
|
2017-07-19 20:29:10 +02:00
|
|
|
return errcode.ErrorCodeDenied.WithMessage("unknown manifest class for " + m.Config.MediaType)
|
2016-11-22 01:36:36 +01:00
|
|
|
}
|
2017-07-11 21:19:47 +02:00
|
|
|
case *ocischema.DeserializedManifest:
|
|
|
|
switch m.Config.MediaType {
|
|
|
|
case v1.MediaTypeImageConfig:
|
2017-07-18 23:20:37 +02:00
|
|
|
class = imageClass
|
2017-07-11 21:19:47 +02:00
|
|
|
default:
|
2017-07-19 20:29:10 +02:00
|
|
|
return errcode.ErrorCodeDenied.WithMessage("unknown manifest class for " + m.Config.MediaType)
|
2017-07-11 21:19:47 +02:00
|
|
|
}
|
2016-11-22 01:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if class == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if class is allowed in registry
|
|
|
|
var allowedClass bool
|
|
|
|
for _, c := range allowedClasses {
|
|
|
|
if class == c {
|
|
|
|
allowedClass = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !allowedClass {
|
2017-07-19 20:29:10 +02:00
|
|
|
return errcode.ErrorCodeDenied.WithMessage(fmt.Sprintf("registry does not allow %s manifest", class))
|
2016-11-22 01:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resources := auth.AuthorizedResources(imh)
|
|
|
|
n := imh.Repository.Named().Name()
|
|
|
|
|
|
|
|
var foundResource bool
|
|
|
|
for _, r := range resources {
|
|
|
|
if r.Name == n {
|
|
|
|
if r.Class == "" {
|
2017-07-18 23:20:37 +02:00
|
|
|
r.Class = imageClass
|
2016-11-22 01:36:36 +01:00
|
|
|
}
|
|
|
|
if r.Class == class {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
foundResource = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// resource was found but no matching class was found
|
|
|
|
if foundResource {
|
2017-07-19 20:29:10 +02:00
|
|
|
return errcode.ErrorCodeDenied.WithMessage(fmt.Sprintf("repository not authorized for %s manifest", class))
|
2016-11-22 01:36:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-11 00:16:45 +01:00
|
|
|
// DeleteManifest removes the manifest with the given digest from the registry.
|
|
|
|
func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Request) {
|
2017-08-12 00:31:16 +02:00
|
|
|
dcontext.GetLogger(imh).Debug("DeleteImageManifest")
|
2015-02-27 00:47:04 +01:00
|
|
|
|
2015-05-27 19:52:22 +02:00
|
|
|
manifests, err := imh.Repository.Manifests(imh)
|
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-08-21 06:50:15 +02:00
|
|
|
err = manifests.Delete(imh, imh.Digest)
|
2015-05-27 19:52:22 +02:00
|
|
|
if err != nil {
|
|
|
|
switch err {
|
|
|
|
case digest.ErrDigestUnsupported:
|
|
|
|
case digest.ErrDigestInvalidFormat:
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeDigestInvalid)
|
|
|
|
return
|
|
|
|
case distribution.ErrBlobUnknown:
|
|
|
|
imh.Errors = append(imh.Errors, v2.ErrorCodeManifestUnknown)
|
|
|
|
return
|
|
|
|
case distribution.ErrUnsupported:
|
2015-08-07 01:25:08 +02:00
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnsupported)
|
2015-08-11 20:00:30 +02:00
|
|
|
return
|
2015-05-27 19:52:22 +02:00
|
|
|
default:
|
|
|
|
imh.Errors = append(imh.Errors, errcode.ErrorCodeUnknown)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 20:22:40 +01:00
|
|
|
tagService := imh.Repository.Tags(imh)
|
|
|
|
referencedTags, err := tagService.Lookup(imh, distribution.Descriptor{Digest: imh.Digest})
|
|
|
|
if err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tag := range referencedTags {
|
|
|
|
if err := tagService.Untag(imh, tag); err != nil {
|
|
|
|
imh.Errors = append(imh.Errors, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 19:52:22 +02:00
|
|
|
w.WriteHeader(http.StatusAccepted)
|
2015-02-27 00:47:04 +01:00
|
|
|
}
|