2020-10-30 19:47:06 +00:00
|
|
|
package distribution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2021-11-12 01:45:40 +00:00
|
|
|
"fmt"
|
2020-10-30 19:47:06 +00:00
|
|
|
"io"
|
disable pulling legacy image formats by default
This patch disables pulling legacy (schema1 and schema 2, version 1) images by
default.
A `DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE` environment-variable is
introduced to allow re-enabling this feature, aligning with the environment
variable used in containerd 2.0 (`CONTAINERD_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE`).
With this patch, attempts to pull a legacy image produces an error:
With graphdrivers:
docker pull docker:1.0
1.0: Pulling from library/docker
[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
With the containerd image store enabled, output is slightly different
as it returns the error before printing the `1.0: pulling ...`:
docker pull docker:1.0
Error response from daemon: [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
Using the "distribution" endpoint to resolve the digest for an image also
produces an error:
curl -v --unix-socket /var/run/docker.sock http://foo/distribution/docker.io/library/docker:1.0/json
* Trying /var/run/docker.sock:0...
* Connected to foo (/var/run/docker.sock) port 80 (#0)
> GET /distribution/docker.io/library/docker:1.0/json HTTP/1.1
> Host: foo
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Api-Version: 1.45
< Content-Type: application/json
< Docker-Experimental: false
< Ostype: linux
< Server: Docker/dev (linux)
< Date: Tue, 27 Feb 2024 16:09:42 GMT
< Content-Length: 354
<
{"message":"[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/"}
* Connection #0 to host foo left intact
Starting the daemon with the `DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE`
env-var set to a non-empty value allows pulling the image;
docker pull docker:1.0
[DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
b0a0e6710d13: Already exists
d193ad713811: Already exists
ba7268c3149b: Already exists
c862d82a67a2: Already exists
Digest: sha256:5e7081837926c7a40e58881bbebc52044a95a62a2ea52fb240db3fc539212fe5
Status: Image is up to date for docker:1.0
docker.io/library/docker:1.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-02-27 16:30:46 +00:00
|
|
|
"os"
|
2022-03-22 20:22:57 +00:00
|
|
|
"strings"
|
2020-10-30 19:47:06 +00:00
|
|
|
|
|
|
|
"github.com/containerd/containerd/content"
|
2023-04-08 17:30:33 +00:00
|
|
|
cerrdefs "github.com/containerd/containerd/errdefs"
|
2020-10-30 19:47:06 +00:00
|
|
|
"github.com/containerd/containerd/remotes"
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
2023-08-30 16:31:46 +00:00
|
|
|
"github.com/distribution/reference"
|
2020-10-30 19:47:06 +00:00
|
|
|
"github.com/docker/distribution"
|
2021-11-12 01:45:40 +00:00
|
|
|
"github.com/docker/distribution/manifest/manifestlist"
|
2020-10-30 19:47:06 +00:00
|
|
|
"github.com/docker/distribution/manifest/schema1"
|
2021-11-12 01:45:40 +00:00
|
|
|
"github.com/docker/distribution/manifest/schema2"
|
2022-03-22 20:22:57 +00:00
|
|
|
"github.com/docker/docker/registry"
|
2022-03-04 13:49:42 +00:00
|
|
|
"github.com/opencontainers/go-digest"
|
2023-05-08 09:57:52 +00:00
|
|
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
2020-10-30 19:47:06 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2022-03-22 20:22:57 +00:00
|
|
|
// labelDistributionSource describes the source blob comes from.
|
|
|
|
const labelDistributionSource = "containerd.io/distribution.source"
|
|
|
|
|
2020-10-30 19:47:06 +00:00
|
|
|
// This is used by manifestStore to pare down the requirements to implement a
|
|
|
|
// full distribution.ManifestService, since `Get` is all we use here.
|
|
|
|
type manifestGetter interface {
|
|
|
|
Get(ctx context.Context, dgst digest.Digest, options ...distribution.ManifestServiceOption) (distribution.Manifest, error)
|
2022-03-22 20:22:57 +00:00
|
|
|
Exists(ctx context.Context, dgst digest.Digest) (bool, error)
|
2020-10-30 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type manifestStore struct {
|
|
|
|
local ContentStore
|
|
|
|
remote manifestGetter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContentStore is the interface used to persist registry blobs
|
|
|
|
//
|
|
|
|
// Currently this is only used to persist manifests and manifest lists.
|
|
|
|
// It is exported because `distribution.Pull` takes one as an argument.
|
|
|
|
type ContentStore interface {
|
|
|
|
content.Ingester
|
|
|
|
content.Provider
|
|
|
|
Info(ctx context.Context, dgst digest.Digest) (content.Info, error)
|
|
|
|
Abort(ctx context.Context, ref string) error
|
2022-03-22 20:22:57 +00:00
|
|
|
Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeDistributionSourceLabel(ref reference.Named) (string, string) {
|
|
|
|
domain := reference.Domain(ref)
|
|
|
|
if domain == "" {
|
|
|
|
domain = registry.DefaultNamespace
|
|
|
|
}
|
|
|
|
repo := reference.Path(ref)
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s.%s", labelDistributionSource, domain), repo
|
2020-10-30 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-22 20:22:57 +00:00
|
|
|
// Taken from https://github.com/containerd/containerd/blob/e079e4a155c86f07bbd602fe6753ecacc78198c2/remotes/docker/handler.go#L84-L108
|
|
|
|
func appendDistributionSourceLabel(originLabel, repo string) string {
|
|
|
|
repos := []string{}
|
|
|
|
if originLabel != "" {
|
|
|
|
repos = strings.Split(originLabel, ",")
|
|
|
|
}
|
|
|
|
repos = append(repos, repo)
|
|
|
|
|
|
|
|
// use empty string to present duplicate items
|
|
|
|
for i := 1; i < len(repos); i++ {
|
|
|
|
tmp, j := repos[i], i-1
|
|
|
|
for ; j >= 0 && repos[j] >= tmp; j-- {
|
|
|
|
if repos[j] == tmp {
|
|
|
|
tmp = ""
|
|
|
|
}
|
|
|
|
repos[j+1] = repos[j]
|
|
|
|
}
|
|
|
|
repos[j+1] = tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
i := 0
|
|
|
|
for ; i < len(repos) && repos[i] == ""; i++ {
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Join(repos[i:], ",")
|
|
|
|
}
|
|
|
|
|
|
|
|
func hasDistributionSource(label, repo string) bool {
|
|
|
|
sources := strings.Split(label, ",")
|
|
|
|
for _, s := range sources {
|
|
|
|
if s == repo {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func (m *manifestStore) getLocal(ctx context.Context, desc ocispec.Descriptor, ref reference.Named) (distribution.Manifest, error) {
|
2020-10-30 19:47:06 +00:00
|
|
|
ra, err := m.local.ReaderAt(ctx, desc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error getting content store reader")
|
|
|
|
}
|
|
|
|
defer ra.Close()
|
|
|
|
|
2022-03-22 20:22:57 +00:00
|
|
|
distKey, distRepo := makeDistributionSourceLabel(ref)
|
|
|
|
info, err := m.local.Info(ctx, desc.Digest)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error getting content info")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := ref.(reference.Canonical); ok {
|
|
|
|
// Since this is specified by digest...
|
|
|
|
// We know we have the content locally, we need to check if we've seen this content at the specified repository before.
|
|
|
|
// If we have, we can just return the manifest from the local content store.
|
|
|
|
// If we haven't, we need to check the remote repository to see if it has the content, otherwise we can end up returning
|
|
|
|
// a manifest that has never even existed in the remote before.
|
|
|
|
if !hasDistributionSource(info.Labels[distKey], distRepo) {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).WithField("ref", ref).Debug("found manifest but no mataching source repo is listed, checking with remote")
|
2022-03-22 20:22:57 +00:00
|
|
|
exists, err := m.remote.Exists(ctx, desc.Digest)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error checking if remote exists")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !exists {
|
2023-04-08 17:30:33 +00:00
|
|
|
return nil, errors.Wrapf(cerrdefs.ErrNotFound, "manifest %v not found", desc.Digest)
|
2022-03-22 20:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the distribution sources since we now know the content exists in the remote.
|
|
|
|
if info.Labels == nil {
|
|
|
|
info.Labels = map[string]string{}
|
|
|
|
}
|
|
|
|
info.Labels[distKey] = appendDistributionSourceLabel(info.Labels[distKey], distRepo)
|
|
|
|
if _, err := m.local.Update(ctx, info, "labels."+distKey); err != nil {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(ctx).WithError(err).WithField("ref", ref).Warn("Could not update content distribution source")
|
2022-03-22 20:22:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 19:47:06 +00:00
|
|
|
r := io.NewSectionReader(ra, 0, ra.Size())
|
2021-08-24 10:10:50 +00:00
|
|
|
data, err := io.ReadAll(r)
|
2020-10-30 19:47:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error reading manifest from content store")
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest, _, err := distribution.UnmarshalManifest(desc.MediaType, data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error unmarshaling manifest from content store")
|
|
|
|
}
|
2022-03-22 20:22:57 +00:00
|
|
|
|
2020-10-30 19:47:06 +00:00
|
|
|
return manifest, nil
|
|
|
|
}
|
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func (m *manifestStore) getMediaType(ctx context.Context, desc ocispec.Descriptor) (string, error) {
|
2020-10-30 19:47:06 +00:00
|
|
|
ra, err := m.local.ReaderAt(ctx, desc)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "error getting reader to detect media type")
|
|
|
|
}
|
|
|
|
defer ra.Close()
|
|
|
|
|
|
|
|
mt, err := detectManifestMediaType(ra)
|
|
|
|
if err != nil {
|
|
|
|
return "", errors.Wrap(err, "error detecting media type")
|
|
|
|
}
|
|
|
|
return mt, nil
|
|
|
|
}
|
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func (m *manifestStore) Get(ctx context.Context, desc ocispec.Descriptor, ref reference.Named) (distribution.Manifest, error) {
|
2020-10-30 19:47:06 +00:00
|
|
|
l := log.G(ctx)
|
|
|
|
|
|
|
|
if desc.MediaType == "" {
|
|
|
|
// When pulling by digest we will not have the media type on the
|
|
|
|
// descriptor since we have not made a request to the registry yet
|
|
|
|
//
|
|
|
|
// We already have the digest, so we only lookup locally... by digest.
|
|
|
|
//
|
|
|
|
// Let's try to detect the media type so we can have a good ref key
|
|
|
|
// here. We may not even have the content locally, and this is fine, but
|
|
|
|
// if we do we should determine that.
|
|
|
|
mt, err := m.getMediaType(ctx, desc)
|
2023-04-08 17:30:33 +00:00
|
|
|
if err != nil && !cerrdefs.IsNotFound(err) {
|
2020-10-30 19:47:06 +00:00
|
|
|
l.WithError(err).Warn("Error looking up media type of content")
|
|
|
|
}
|
|
|
|
desc.MediaType = mt
|
|
|
|
}
|
|
|
|
|
|
|
|
key := remotes.MakeRefKey(ctx, desc)
|
|
|
|
|
|
|
|
// Here we open a writer to the requested content. This both gives us a
|
|
|
|
// reference to write to if indeed we need to persist it and increments the
|
|
|
|
// ref count on the content.
|
|
|
|
w, err := m.local.Writer(ctx, content.WithDescriptor(desc), content.WithRef(key))
|
|
|
|
if err != nil {
|
2023-04-08 17:30:33 +00:00
|
|
|
if cerrdefs.IsAlreadyExists(err) {
|
2020-10-30 19:47:06 +00:00
|
|
|
var manifest distribution.Manifest
|
2022-03-22 20:22:57 +00:00
|
|
|
if manifest, err = m.getLocal(ctx, desc, ref); err == nil {
|
2020-10-30 19:47:06 +00:00
|
|
|
return manifest, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// always fallback to the remote if there is an error with the local store
|
|
|
|
}
|
|
|
|
if w != nil {
|
|
|
|
defer w.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
l.WithError(err).Debug("Fetching manifest from remote")
|
|
|
|
|
|
|
|
manifest, err := m.remote.Get(ctx, desc.Digest)
|
|
|
|
if err != nil {
|
|
|
|
if err := m.local.Abort(ctx, key); err != nil {
|
|
|
|
l.WithError(err).Warn("Error while attempting to abort content ingest")
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if w != nil {
|
|
|
|
// if `w` is nil here, something happened with the content store, so don't bother trying to persist.
|
2022-03-22 20:22:57 +00:00
|
|
|
if err := m.Put(ctx, manifest, desc, w, ref); err != nil {
|
2020-10-30 19:47:06 +00:00
|
|
|
if err := m.local.Abort(ctx, key); err != nil {
|
|
|
|
l.WithError(err).Warn("error aborting content ingest")
|
|
|
|
}
|
|
|
|
l.WithError(err).Warn("Error persisting manifest")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return manifest, nil
|
|
|
|
}
|
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func (m *manifestStore) Put(ctx context.Context, manifest distribution.Manifest, desc ocispec.Descriptor, w content.Writer, ref reference.Named) error {
|
2020-10-30 19:47:06 +00:00
|
|
|
mt, payload, err := manifest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
desc.Size = int64(len(payload))
|
|
|
|
desc.MediaType = mt
|
|
|
|
|
|
|
|
if _, err = w.Write(payload); err != nil {
|
|
|
|
return errors.Wrap(err, "error writing manifest to content store")
|
|
|
|
}
|
|
|
|
|
2022-03-22 20:22:57 +00:00
|
|
|
distKey, distSource := makeDistributionSourceLabel(ref)
|
|
|
|
if err := w.Commit(ctx, desc.Size, desc.Digest, content.WithLabels(map[string]string{
|
|
|
|
distKey: distSource,
|
|
|
|
})); err != nil {
|
2020-10-30 19:47:06 +00:00
|
|
|
return errors.Wrap(err, "error committing manifest to content store")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func detectManifestMediaType(ra content.ReaderAt) (string, error) {
|
|
|
|
dt := make([]byte, ra.Size())
|
|
|
|
if _, err := ra.ReadAt(dt, 0); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return detectManifestBlobMediaType(dt)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is used when the manifest store does not know the media type of a sha it
|
|
|
|
// was told to get. This would currently only happen when pulling by digest.
|
|
|
|
// The media type is needed so the blob can be unmarshalled properly.
|
|
|
|
func detectManifestBlobMediaType(dt []byte) (string, error) {
|
|
|
|
var mfst struct {
|
|
|
|
MediaType string `json:"mediaType"`
|
2021-11-12 01:45:40 +00:00
|
|
|
Manifests json.RawMessage `json:"manifests"` // oci index, manifest list
|
|
|
|
Config json.RawMessage `json:"config"` // schema2 Manifest
|
|
|
|
Layers json.RawMessage `json:"layers"` // schema2 Manifest
|
|
|
|
FSLayers json.RawMessage `json:"fsLayers"` // schema1 Manifest
|
2020-10-30 19:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(dt, &mfst); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// We may have a media type specified in the json, in which case that should be used.
|
|
|
|
// Docker types should generally have a media type set.
|
|
|
|
// OCI (golang) types do not have a `mediaType` defined, and it is optional in the spec.
|
|
|
|
//
|
2021-11-12 01:45:40 +00:00
|
|
|
// `distribution.UnmarshalManifest`, which is used to unmarshal this for real, checks these media type values.
|
2020-10-30 19:47:06 +00:00
|
|
|
// If the specified media type does not match it will error, and in some cases (docker media types) it is required.
|
|
|
|
// So pretty much if we don't have a media type we can fall back to OCI.
|
|
|
|
// This does have a special fallback for schema1 manifests just because it is easy to detect.
|
2021-11-12 01:45:40 +00:00
|
|
|
switch mfst.MediaType {
|
2023-05-08 09:57:52 +00:00
|
|
|
case schema2.MediaTypeManifest, ocispec.MediaTypeImageManifest:
|
2021-11-12 01:45:40 +00:00
|
|
|
if mfst.Manifests != nil || mfst.FSLayers != nil {
|
|
|
|
return "", fmt.Errorf(`media-type: %q should not have "manifests" or "fsLayers"`, mfst.MediaType)
|
|
|
|
}
|
|
|
|
return mfst.MediaType, nil
|
2023-05-08 09:57:52 +00:00
|
|
|
case manifestlist.MediaTypeManifestList, ocispec.MediaTypeImageIndex:
|
2021-11-12 01:45:40 +00:00
|
|
|
if mfst.Config != nil || mfst.Layers != nil || mfst.FSLayers != nil {
|
|
|
|
return "", fmt.Errorf(`media-type: %q should not have "config", "layers", or "fsLayers"`, mfst.MediaType)
|
|
|
|
}
|
|
|
|
return mfst.MediaType, nil
|
|
|
|
case schema1.MediaTypeManifest:
|
disable pulling legacy image formats by default
This patch disables pulling legacy (schema1 and schema 2, version 1) images by
default.
A `DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE` environment-variable is
introduced to allow re-enabling this feature, aligning with the environment
variable used in containerd 2.0 (`CONTAINERD_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE`).
With this patch, attempts to pull a legacy image produces an error:
With graphdrivers:
docker pull docker:1.0
1.0: Pulling from library/docker
[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
With the containerd image store enabled, output is slightly different
as it returns the error before printing the `1.0: pulling ...`:
docker pull docker:1.0
Error response from daemon: [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
Using the "distribution" endpoint to resolve the digest for an image also
produces an error:
curl -v --unix-socket /var/run/docker.sock http://foo/distribution/docker.io/library/docker:1.0/json
* Trying /var/run/docker.sock:0...
* Connected to foo (/var/run/docker.sock) port 80 (#0)
> GET /distribution/docker.io/library/docker:1.0/json HTTP/1.1
> Host: foo
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Api-Version: 1.45
< Content-Type: application/json
< Docker-Experimental: false
< Ostype: linux
< Server: Docker/dev (linux)
< Date: Tue, 27 Feb 2024 16:09:42 GMT
< Content-Length: 354
<
{"message":"[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/"}
* Connection #0 to host foo left intact
Starting the daemon with the `DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE`
env-var set to a non-empty value allows pulling the image;
docker pull docker:1.0
[DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
b0a0e6710d13: Already exists
d193ad713811: Already exists
ba7268c3149b: Already exists
c862d82a67a2: Already exists
Digest: sha256:5e7081837926c7a40e58881bbebc52044a95a62a2ea52fb240db3fc539212fe5
Status: Image is up to date for docker:1.0
docker.io/library/docker:1.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-02-27 16:30:46 +00:00
|
|
|
if os.Getenv("DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE") == "" {
|
|
|
|
err := DeprecatedSchema1ImageError(nil)
|
|
|
|
log.G(context.TODO()).Warn(err.Error())
|
|
|
|
return "", err
|
|
|
|
}
|
2021-11-12 01:45:40 +00:00
|
|
|
if mfst.Manifests != nil || mfst.Layers != nil {
|
|
|
|
return "", fmt.Errorf(`media-type: %q should not have "manifests" or "layers"`, mfst.MediaType)
|
|
|
|
}
|
2020-10-30 19:47:06 +00:00
|
|
|
return mfst.MediaType, nil
|
2021-11-12 01:45:40 +00:00
|
|
|
default:
|
|
|
|
if mfst.MediaType != "" {
|
|
|
|
return mfst.MediaType, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch {
|
|
|
|
case mfst.FSLayers != nil && mfst.Manifests == nil && mfst.Layers == nil && mfst.Config == nil:
|
disable pulling legacy image formats by default
This patch disables pulling legacy (schema1 and schema 2, version 1) images by
default.
A `DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE` environment-variable is
introduced to allow re-enabling this feature, aligning with the environment
variable used in containerd 2.0 (`CONTAINERD_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE`).
With this patch, attempts to pull a legacy image produces an error:
With graphdrivers:
docker pull docker:1.0
1.0: Pulling from library/docker
[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
With the containerd image store enabled, output is slightly different
as it returns the error before printing the `1.0: pulling ...`:
docker pull docker:1.0
Error response from daemon: [DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
Using the "distribution" endpoint to resolve the digest for an image also
produces an error:
curl -v --unix-socket /var/run/docker.sock http://foo/distribution/docker.io/library/docker:1.0/json
* Trying /var/run/docker.sock:0...
* Connected to foo (/var/run/docker.sock) port 80 (#0)
> GET /distribution/docker.io/library/docker:1.0/json HTTP/1.1
> Host: foo
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Api-Version: 1.45
< Content-Type: application/json
< Docker-Experimental: false
< Ostype: linux
< Server: Docker/dev (linux)
< Date: Tue, 27 Feb 2024 16:09:42 GMT
< Content-Length: 354
<
{"message":"[DEPRECATION NOTICE] Docker Image Format v1, and Docker Image manifest version 2, schema 1 support will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format, or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/"}
* Connection #0 to host foo left intact
Starting the daemon with the `DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE`
env-var set to a non-empty value allows pulling the image;
docker pull docker:1.0
[DEPRECATION NOTICE] Docker Image Format v1 and Docker Image manifest version 2, schema 1 support is disabled by default and will be removed in an upcoming release. Suggest the author of docker.io/library/docker:1.0 to upgrade the image to the OCI Format or Docker Image manifest v2, schema 2. More information at https://docs.docker.com/go/deprecated-image-specs/
b0a0e6710d13: Already exists
d193ad713811: Already exists
ba7268c3149b: Already exists
c862d82a67a2: Already exists
Digest: sha256:5e7081837926c7a40e58881bbebc52044a95a62a2ea52fb240db3fc539212fe5
Status: Image is up to date for docker:1.0
docker.io/library/docker:1.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-02-27 16:30:46 +00:00
|
|
|
if os.Getenv("DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE") == "" {
|
|
|
|
err := DeprecatedSchema1ImageError(nil)
|
|
|
|
log.G(context.TODO()).Warn(err.Error())
|
|
|
|
return "", err
|
|
|
|
}
|
2020-10-30 19:47:06 +00:00
|
|
|
return schema1.MediaTypeManifest, nil
|
2021-11-12 01:45:40 +00:00
|
|
|
case mfst.Config != nil && mfst.Manifests == nil && mfst.FSLayers == nil,
|
|
|
|
mfst.Layers != nil && mfst.Manifests == nil && mfst.FSLayers == nil:
|
2023-05-08 09:57:52 +00:00
|
|
|
return ocispec.MediaTypeImageManifest, nil
|
2021-11-12 01:45:40 +00:00
|
|
|
case mfst.Config == nil && mfst.Layers == nil && mfst.FSLayers == nil:
|
|
|
|
// fallback to index
|
2023-05-08 09:57:52 +00:00
|
|
|
return ocispec.MediaTypeImageIndex, nil
|
2020-10-30 19:47:06 +00:00
|
|
|
}
|
2021-11-12 01:45:40 +00:00
|
|
|
return "", errors.New("media-type: cannot determine")
|
2020-10-30 19:47:06 +00:00
|
|
|
}
|