diff --git a/cli/command/image/pull.go b/cli/command/image/pull.go index 0cf3df609d..1824de2a9b 100644 --- a/cli/command/image/pull.go +++ b/cli/command/image/pull.go @@ -41,24 +41,25 @@ func NewPullCommand(dockerCli command.Cli) *cobra.Command { } func runPull(cli command.Cli, opts pullOptions) error { - ctx := context.Background() - imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), opts.remote) - if err != nil { + distributionRef, err := reference.ParseNormalizedNamed(opts.remote) + switch { + case err != nil: return err - } - - distributionRef := imgRefAndAuth.Reference() - if opts.all && !reference.IsNameOnly(distributionRef) { + case opts.all && !reference.IsNameOnly(distributionRef): return errors.New("tag can't be used with --all-tags/-a") - } - - if !opts.all && reference.IsNameOnly(distributionRef) { + case !opts.all && reference.IsNameOnly(distributionRef): distributionRef = reference.TagNameOnly(distributionRef) if tagged, ok := distributionRef.(reference.Tagged); ok { fmt.Fprintf(cli.Out(), "Using default tag: %s\n", tagged.Tag()) } } + ctx := context.Background() + imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), distributionRef.String()) + if err != nil { + return err + } + // Check if reference has a digest _, isCanonical := distributionRef.(reference.Canonical) if command.IsTrusted() && !isCanonical { diff --git a/cli/command/image/pull_test.go b/cli/command/image/pull_test.go index ec83ba1f35..b0e9929abe 100644 --- a/cli/command/image/pull_test.go +++ b/cli/command/image/pull_test.go @@ -2,11 +2,14 @@ package image import ( "fmt" + "io" "io/ioutil" + "strings" "testing" "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/testutil" + "github.com/docker/docker/api/types" "github.com/gotestyourself/gotestyourself/golden" "github.com/stretchr/testify/assert" ) @@ -44,20 +47,28 @@ func TestNewPullCommandErrors(t *testing.T) { func TestNewPullCommandSuccess(t *testing.T) { testCases := []struct { - name string - args []string + name string + args []string + expectedTag string }{ { - name: "simple", - args: []string{"image:tag"}, + name: "simple", + args: []string{"image:tag"}, + expectedTag: "image:tag", }, { - name: "simple-no-tag", - args: []string{"image"}, + name: "simple-no-tag", + args: []string{"image"}, + expectedTag: "image:latest", }, } for _, tc := range testCases { - cli := test.NewFakeCli(&fakeClient{}) + cli := test.NewFakeCli(&fakeClient{ + imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) { + assert.Equal(t, tc.expectedTag, ref, tc.name) + return ioutil.NopCloser(strings.NewReader("")), nil + }, + }) cmd := NewPullCommand(cli) cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index f2847e954b..85f816e219 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -200,7 +200,11 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image if err != nil { return err } - if err := imagePullPrivileged(ctx, cli, imgRefAndAuth, false); err != nil { + updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, AuthResolver(cli), trustedRef.String()) + if err != nil { + return err + } + if err := imagePullPrivileged(ctx, cli, updatedImgRefAndAuth, false); err != nil { return err } diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 8ee2e905b3..1651ad1eb0 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,7 +1,7 @@ FROM golang:1.8.4-alpine -RUN apk add -U git make bash coreutils +RUN apk add -U git make bash coreutils ca-certificates ARG VNDR_SHA=a6e196d8b4b0cbbdc29aebdb20c59ac6926bb384 RUN go get -d github.com/LK4D4/vndr && \ diff --git a/e2e/compose-env.yaml b/e2e/compose-env.yaml index afc95e3af0..d77427a253 100644 --- a/e2e/compose-env.yaml +++ b/e2e/compose-env.yaml @@ -8,3 +8,14 @@ services: image: 'docker:${TEST_ENGINE_VERSION:-edge-dind}' privileged: true command: ['--insecure-registry=registry:5000'] + + notary-server: + image: 'notary:server-0.4.2' + ports: + - 4443:4443 + volumes: + - notary-fixtures:/fixtures + command: ['notary-server', '-config=/fixtures/notary-config.json'] + +volumes: + notary-fixtures: {} diff --git a/e2e/image/main_test.go b/e2e/image/main_test.go new file mode 100644 index 0000000000..4638467a01 --- /dev/null +++ b/e2e/image/main_test.go @@ -0,0 +1,17 @@ +package image + +import ( + "fmt" + "os" + "testing" + + "github.com/docker/cli/internal/test/environment" +) + +func TestMain(m *testing.M) { + if err := environment.Setup(); err != nil { + fmt.Println(err.Error()) + os.Exit(3) + } + os.Exit(m.Run()) +} diff --git a/e2e/image/pull_test.go b/e2e/image/pull_test.go new file mode 100644 index 0000000000..4da6748be2 --- /dev/null +++ b/e2e/image/pull_test.go @@ -0,0 +1,71 @@ +package image + +import ( + "fmt" + "os" + "testing" + + "github.com/gotestyourself/gotestyourself/golden" + "github.com/gotestyourself/gotestyourself/icmd" +) + +const notaryURL = "https://notary-server:4443" +const registryPrefix = "registry:5000" + +const alpineImage = "registry:5000/alpine:3.6" +const busyboxImage = "registry:5000/busybox:1.27.2" + +func TestPullWithContentTrust(t *testing.T) { + image := createMaskedTrustedRemoteImage(t, "trust", "latest") + + result := icmd.RunCmd(icmd.Command("docker", "pull", image), withTrustNoPassphrase) + result.Assert(t, icmd.Expected{Err: icmd.None}) + golden.Assert(t, result.Stdout(), "pull-with-content-trust.golden") +} + +// createMaskedTrustedRemoteImage creates a remote image that is signed with +// content trust, then pushes a different untrusted image at the same tag. +func createMaskedTrustedRemoteImage(t *testing.T, repo, tag string) string { + image := createTrustedRemoteImage(t, repo, tag) + createNamedUnsignedImageFromBusyBox(t, image) + return image +} + +func createTrustedRemoteImage(t *testing.T, repo, tag string) string { + image := fmt.Sprintf("%s/%s:%s", registryPrefix, repo, tag) + icmd.RunCommand("docker", "pull", alpineImage).Assert(t, icmd.Success) + icmd.RunCommand("docker", "tag", alpineImage, image).Assert(t, icmd.Success) + result := icmd.RunCmd( + icmd.Command("docker", "push", image), + withTrustAndPassphrase("root_password", "repo_password")) + result.Assert(t, icmd.Success) + icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success) + return image +} + +func createNamedUnsignedImageFromBusyBox(t *testing.T, image string) { + icmd.RunCommand("docker", "pull", busyboxImage).Assert(t, icmd.Success) + icmd.RunCommand("docker", "tag", busyboxImage, image).Assert(t, icmd.Success) + icmd.RunCommand("docker", "push", image).Assert(t, icmd.Success) + icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success) +} + +func withTrustAndPassphrase(rootPwd, repositoryPwd string) func(cmd *icmd.Cmd) { + return func(cmd *icmd.Cmd) { + env := append(os.Environ(), + "DOCKER_CONTENT_TRUST=1", + "DOCKER_CONTENT_TRUST_SERVER="+notaryURL, + "DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE="+rootPwd, + "DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE="+repositoryPwd, + ) + cmd.Env = append(cmd.Env, env...) + } +} + +func withTrustNoPassphrase(cmd *icmd.Cmd) { + env := append(os.Environ(), + "DOCKER_CONTENT_TRUST=1", + "DOCKER_CONTENT_TRUST_SERVER="+notaryURL, + ) + cmd.Env = append(cmd.Env, env...) +} diff --git a/e2e/image/testdata/pull-with-content-trust.golden b/e2e/image/testdata/pull-with-content-trust.golden new file mode 100644 index 0000000000..85a043aca6 --- /dev/null +++ b/e2e/image/testdata/pull-with-content-trust.golden @@ -0,0 +1,5 @@ +Pull (1 of 1): registry:5000/trust:latest@sha256:641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d +sha256:641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d: Pulling from trust +Digest: sha256:641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d +Status: Downloaded newer image for registry:5000/trust@sha256:641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d +Tagging registry:5000/trust@sha256:641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d as registry:5000/trust:latest diff --git a/e2e/testdata/notary/notary-config.json b/e2e/testdata/notary/notary-config.json new file mode 100644 index 0000000000..a4aed592a6 --- /dev/null +++ b/e2e/testdata/notary/notary-config.json @@ -0,0 +1,19 @@ +{ + "server": { + "http_addr": "notary-server:4443", + "tls_key_file": "./notary-server.key", + "tls_cert_file": "./notary-server.cert" + }, + "trust_service": { + "type": "local", + "hostname": "", + "port": "", + "key_algorithm": "ed25519" + }, + "logging": { + "level": "debug" + }, + "storage": { + "backend": "memory" + } +} diff --git a/e2e/testdata/notary/notary-server.cert b/e2e/testdata/notary/notary-server.cert new file mode 100644 index 0000000000..2573d00218 --- /dev/null +++ b/e2e/testdata/notary/notary-server.cert @@ -0,0 +1,63 @@ +-----BEGIN CERTIFICATE----- +MIIFBDCCAuygAwIBAgIJAPlHYZzp1daGMA0GCSqGSIb3DQEBCwUAMGwxCzAJBgNV +BAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0G +A1UEChMGRG9ja2VyMScwJQYDVQQDEx5Ob3RhcnkgSW50ZXJtZWRpYXRlIFRlc3Rp +bmcgQ0EwHhcNMTcwMjE3MDA0MzE3WhcNMTkwMzA5MDA0MzE3WjBbMQswCQYDVQQG +EwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xDzANBgNV +BAoTBkRvY2tlcjEWMBQGA1UEAxMNbm90YXJ5LXNlcnZlcjCCASIwDQYJKoZIhvcN +AQEBBQADggEPADCCAQoCggEBAKjbeflOtVrOv0IOeJGKfi5LHH3Di0O2nlZu8AIT +SJbDZPSXoYc+cprpoEWYncbFFC3C94z5xBW5vcAqMhLs50ml5ADl86umcLl2C/mX +8NuZnlIevMCb0mBiavDtSPV3J5DqOk+trgKEXs9g4hyh5Onh5Y5InPO1lDJ+2cEt +VGBMhhddfWRVlV9ZUWxPYVCTt6L0bD9SeyXJVB0dnFhr3xICayhDlhlvcjXVOTUs +ewJLo/L2nq0ve93Jb2smKio27ZGE79bCGqJK213/FNqfAlGUPkhYTfYJT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vCVk6jNuuvw5mbHN9yHIfD7qI1pPY54EIEGgxVZGwaJTj +mRKvTbf6JQIDAQABo4GGMIGDMB8GA1UdIwQYMBaAFMXa5XX+ba5Jf0YRuL6UqjtU +QS5ZMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG +AQUFBwMCMA4GA1UdDwEB/wQEAwIBRjAdBgNVHQ4EFgQUupdDG81X7//TnYCdldrf +396Did0wDQYJKoZIhvcNAQELBQADggIBAEKzd2/OInjHpFNmqJnuAvrFJPQHhwAQ +CUv4HwLqMdRbKLhAF2Xc687K0rJaW6ZpvvCWP/bsgzDi7bcti+sbpRtutL98ollq +NtqEBW7pW3ljvQteBHiXCPzHmSdKBG5B972mFvIi1k9NpeHcEz4y9q5s9BBW5hIu +6UwKIQSZ/dQGsukgQXe3lXJ/MjRg/QK0U1Xn/ABknm75vMbdc7L+WLvmrEY11NAy +3vso6qm7k2elDLUVmqIwMU+r9pfGZFi0nQCxfiRhW1hZyDxzpngBZFnRppiO+2CX +u16yiJfipD5wHZc1NjZ1WQ+XuoUhDgV1yzGpgRGtUdX4fByEUqNZb1GbY6UdIjmx +LvwT2SJnEcv9irGlQU2D4mm5oXgeZXJhxP3gMxEtw9bZS3tUDMWkMD5GCdo8T+FB +tjlGIe8Uh8R4wn33EYDMq+qFeUe+NiMDsVcFIlKWSwCRvmsTB3gvTYYkssuyS65Y +8Ngdsy5GIBhMEsLnZNdwmP7NJ41CECqlojK9tQeu8KAhB7xsKibbwPUbec7whQFl +82vOLgag7Fn3V1eVonqxk7uBt0nriV39/hXifPwBRo3WLoVLUTs+IAOiLapLAb6o +LCQV7ymBRptOyj9bPPYV+NJrfr/5IlkNamioWlbzH3SJdvyp5ldZH/2vciItlO3s +ALNmRewqFkXD +-----END CERTIFICATE----- diff --git a/e2e/testdata/notary/notary-server.key b/e2e/testdata/notary/notary-server.key new file mode 100644 index 0000000000..871d41f643 --- /dev/null +++ b/e2e/testdata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/Uo6YJo +qYGoZr0mmnEZxVCkwODz5C9icnyjklcRdIRM6eljhFMQDVEacDkptsntHUyIdQZc +L2eLNUfEgwKBgHxy7UNg3lemag110rgIU8mzvHj7m3oymYw2nc/qcwVnvG17d5Tp +DPICr6R+NRfl//9JcDdjQBfdnm5hVHJgIbLS4UTH8j390GDRo+O0/dzJq4KfM4Rb +lUJ1ITqoVnuYQZG7QUJxJd330yedZLJwswZWz7N2TTmixqf9BC2TRd85AoGAN+Qh +bLhKaMSvkACMq61ifXSHP7AlGNB3pYlsEVCh5WnVvEPow9pNTAUbKbmumE7sU8+N +0WfYFQ0H5SP+74zcZTmQbfVDdvjhAw/mt64DJVg6JQKPi87bdJBYNz9mokVgYOiS +fz/Ux71pwZ1e0QxvBOU66NBp31+/c6uVT1wbR3ECgYAdye1+UPpS9Dn89g6Ks0kv +UaFKykXu7vY2uxiNqhmWzze4iq5wmIHmEwc6+rVMluXQPAME7Iya3mBmto9AHQ/n +/ka+fGoaUgAojCLZW5DZcelIETw+Dk+95vyyAUsWfAvn4nKo4/rkBXcSHlvgElzq +SorPiBWYosFB6jqUTXew2w== +-----END PRIVATE KEY----- diff --git a/e2e/testdata/notary/root-ca.cert b/e2e/testdata/notary/root-ca.cert new file mode 100644 index 0000000000..2f5b58bbee --- /dev/null +++ b/e2e/testdata/notary/root-ca.cert @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFhjCCA26gAwIBAgIJAI/HWUuNSUQjMA0GCSqGSIb3DQEBCwUAMF8xCzAJBgNV +BAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0G +A1UEChMGRG9ja2VyMRowGAYDVQQDExFOb3RhcnkgVGVzdGluZyBDQTAeFw0xNzAy +MTcwMDQzMTNaFw0yNzAyMTUwMDQzMTNaMF8xCzAJBgNVBAYTAlVTMQswCQYDVQQI +EwJDQTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEPMA0GA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DylhmNmygQNvpy0TBCMA9l2pgokN5RD4zbY88DTrdYetkdBV70QFTUn3Za1Y3z0 +ZAigKyA9U1FUnRIgZprkliVJiBzv+JVD5uFIxut5nVoKaEuQ/EoM89BMJXEmlm2T +LDmfJ2pSm4rjvt+V+jfR/f8lCwsqJ/DqnbxCbpCoMegJSoaSGvL0yWvfCTuiDzRk +tAcz4v/bZ6mtH4pYJLQ1xswrDUW+3loCjB+9bU1185X7hZo2nkan409zqQ2gPWKR +0qaVC1KnvsQaVupd7j4mYr/AzBNugR7PZpNKmBomLVZx/HLRAW7Qkz9wrXl3pcW7 +rXU5R3Z8NygRbzRadG2pXcmZqOTEM/3El5LOQs2bxb2/Qr7YAz957xEZBtZbRlMt +lhWyA0PnlewJ2NeIBwf1WAw8lYXJMQnibCCHXsPh0A864F95QJAopVrsx0w+Junz +C5rBWBS2H5c9cDA+BrIEV6SE94AvPs7OxEMCFDrqybZh/Q0xD4ADlm6EJoRvgtN/ +rba7O3YGSuScQakjt9mw2Q5ISwImkRHF3qE= +-----END CERTIFICATE----- diff --git a/scripts/test/e2e/load-busybox b/scripts/test/e2e/load-busybox new file mode 100755 index 0000000000..b9eed04612 --- /dev/null +++ b/scripts/test/e2e/load-busybox @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +src=busybox@sha256:3e8fa85ddfef1af9ca85a5cfb714148956984e02f00bec3f7f49d3925a91e0e7 +dest=registry:5000/busybox:1.27.2 +docker pull $src +docker tag $src $dest +docker push $dest diff --git a/scripts/test/e2e/run b/scripts/test/e2e/run index 4010e756c4..2229eb2964 100755 --- a/scripts/test/e2e/run +++ b/scripts/test/e2e/run @@ -23,6 +23,7 @@ function setup { export DOCKER_HOST="$engine_host" timeout -t 200 ./scripts/test/e2e/wait-on-daemon ./scripts/test/e2e/load-alpine + ./scripts/test/e2e/load-busybox is_swarm_enabled || docker swarm init ) >&2 echo "$engine_host" @@ -33,12 +34,14 @@ function is_swarm_enabled { } function cleanup { - COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker-compose down >&2 + COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker-compose down -v >&2 } function runtests { local engine_host=$1 + # TODO: only run if inside a container + update-ca-certificates # shellcheck disable=SC2086 env -i \ TEST_DOCKER_HOST="$engine_host" \ @@ -77,6 +80,9 @@ case "$cmd" in cleanup "$unique_id" "$compose_env_file" exit $testexit ;; + shell) + $SHELL + ;; *) echo "Unknown command: $cmd" echo "Usage: " diff --git a/scripts/test/e2e/wrapper b/scripts/test/e2e/wrapper index 0f85f43283..1e4cb117ff 100755 --- a/scripts/test/e2e/wrapper +++ b/scripts/test/e2e/wrapper @@ -22,13 +22,31 @@ docker build \ -t "$dev_image" \ -f dockerfiles/Dockerfile.dev . +notary_volume="${unique_id}_notary-fixtures" +docker volume create --name "$notary_volume" +docker run --rm \ + -v "$PWD:/go/src/github.com/docker/cli" \ + -v "$notary_volume:/data" \ + "$dev_image" \ + cp -r ./e2e/testdata/notary/* /data/ + engine_host=$(run_in_env setup) testexit=0 + + +test_cmd="test" +if [[ -n "${TEST_DEBUG-}" ]]; then + test_cmd="shell" +fi + docker run -i --rm \ -v "$PWD:/go/src/github.com/docker/cli" \ + -v "$PWD/e2e/testdata/notary/root-ca.cert:/usr/local/share/ca-certificates/notary.cert" \ --network "${unique_id}_default" \ -e TESTFLAGS \ + -e ENGINE_HOST="$engine_host" \ "$dev_image" \ - ./scripts/test/e2e/run test "$engine_host" || testexit="$?" + ./scripts/test/e2e/run "$test_cmd" "$engine_host" || testexit="$?" + run_in_env cleanup exit "$testexit"