Skip to content

Commit 9b6dcc8

Browse files
Make docker pull detect plugin content and error out.
Signed-off-by: Anusha Ragunathan <[email protected]>
1 parent 09e1de2 commit 9b6dcc8

5 files changed

Lines changed: 31 additions & 14 deletions

File tree

api/client/image/pull.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package image
33
import (
44
"errors"
55
"fmt"
6+
"strings"
67

78
"golang.org/x/net/context"
89

@@ -77,9 +78,16 @@ func runPull(dockerCli *client.DockerCli, opts pullOptions) error {
7778

7879
if client.IsTrusted() && !registryRef.HasDigest() {
7980
// Check if tag is digest
80-
return dockerCli.TrustedPull(ctx, repoInfo, registryRef, authConfig, requestPrivilege)
81+
err = dockerCli.TrustedPull(ctx, repoInfo, registryRef, authConfig, requestPrivilege)
82+
} else {
83+
err = dockerCli.ImagePullPrivileged(ctx, authConfig, distributionRef.String(), requestPrivilege, opts.all)
84+
}
85+
if err != nil {
86+
if strings.Contains(err.Error(), "target is a plugin") {
87+
return errors.New(err.Error() + " - Use `docker plugin install`")
88+
}
89+
return err
8190
}
8291

83-
return dockerCli.ImagePullPrivileged(ctx, authConfig, distributionRef.String(), requestPrivilege, opts.all)
84-
92+
return nil
8593
}

distribution/pull_v2.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import (
3232
"golang.org/x/net/context"
3333
)
3434

35-
var errRootFSMismatch = errors.New("layers from manifest don't match image configuration")
35+
var (
36+
errRootFSMismatch = errors.New("layers from manifest don't match image configuration")
37+
errMediaTypePlugin = errors.New("target is a plugin")
38+
errRootFSInvalid = errors.New("invalid rootfs in image configuration")
39+
)
3640

3741
// ImageConfigPullError is an error pulling the image config blob
3842
// (only applies to schema2).
@@ -356,6 +360,12 @@ func (p *v2Puller) pullV2Tag(ctx context.Context, ref reference.Named) (tagUpdat
356360
return false, fmt.Errorf("image manifest does not exist for tag or digest %q", tagOrDigest)
357361
}
358362

363+
if m, ok := manifest.(*schema2.DeserializedManifest); ok {
364+
if m.Manifest.Config.MediaType == schema2.MediaTypePluginConfig {
365+
return false, errMediaTypePlugin
366+
}
367+
}
368+
359369
// If manSvc.Get succeeded, we can be confident that the registry on
360370
// the other side speaks the v2 protocol.
361371
p.confirmedV2 = true
@@ -574,6 +584,10 @@ func (p *v2Puller) pullSchema2(ctx context.Context, ref reference.Named, mfst *s
574584
}
575585
}
576586

587+
if unmarshalledConfig.RootFS == nil {
588+
return "", "", errRootFSInvalid
589+
}
590+
577591
// The DiffIDs returned in rootFS MUST match those in the config.
578592
// Otherwise the image config could be referencing layers that aren't
579593
// included in the manifest.

plugin/distribution/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func Pull(name string, rs registry.Service, metaheader http.Header, authConfig *
143143
logrus.Debugf("pull.go: error in json.Unmarshal(): %v", err)
144144
return nil, err
145145
}
146-
if m.Config.MediaType != MediaTypeConfig {
146+
if m.Config.MediaType != schema2.MediaTypePluginConfig {
147147
return nil, ErrUnsupportedMediaType
148148
}
149149

plugin/distribution/push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func Push(name string, rs registry.Service, metaHeader http.Header, authConfig *
7979
return "", err
8080
}
8181
f.Close()
82-
mt := MediaTypeLayer
82+
mt := schema2.MediaTypeLayer
8383
if i == 0 {
84-
mt = MediaTypeConfig
84+
mt = schema2.MediaTypePluginConfig
8585
}
8686
// Commit completes the write process to the BlobService.
8787
// The descriptor arg to Commit is called the "provisional" descriptor and

plugin/distribution/types.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,5 @@ var ErrUnsupportedRegistry = errors.New("only V2 repositories are supported for
1010
// ErrUnsupportedMediaType indicates we are pulling content that's not a plugin
1111
var ErrUnsupportedMediaType = errors.New("content is not a plugin")
1212

13-
// Plugin related media types
14-
const (
15-
MediaTypeManifest = "application/vnd.docker.distribution.manifest.v2+json"
16-
MediaTypeConfig = "application/vnd.docker.plugin.v0+json"
17-
MediaTypeLayer = "application/vnd.docker.image.rootfs.diff.tar.gzip"
18-
DefaultTag = "latest"
19-
)
13+
// DefaultTag is the default tag for plugins
14+
const DefaultTag = "latest"

0 commit comments

Comments
 (0)