-
Notifications
You must be signed in to change notification settings - Fork 2.1k
e2e: add private registry pull/push regression test #7007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lohitkolluri
wants to merge
5
commits into
docker:master
Choose a base branch
from
lohitkolluri:e2e/private-registry-pull-push-5965
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2fbbd74
e2e: add private registry pull/push regression test
lohitkolluri c9fc077
e2e: add TLS-backed private registry test
lohitkolluri db1e57b
e2e: merge TLS test, generate certs dynamically
lohitkolluri f1b1803
e2e: install tlsregistry CA in connhelper-ssh engine
lohitkolluri 16df6a4
e2e: verify all 4 cert files before generating
lohitkolluri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Generated by gen-certs.sh at setup time | ||
| testdata/registry/certs/ca.crt | ||
| testdata/registry/certs/ca.key | ||
| testdata/registry/certs/tlsregistry.crt | ||
| testdata/registry/certs/tlsregistry.key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package image | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/docker/cli/e2e/internal/fixtures" | ||
| "gotest.tools/v3/assert" | ||
| "gotest.tools/v3/icmd" | ||
| ) | ||
|
|
||
| // Regression test for https://github.com/docker/cli/issues/5963 | ||
| func TestPullPushPrivateRepository(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| for _, tc := range []struct { | ||
| name string | ||
| registryPrefix string | ||
| tagSuffix string | ||
| }{ | ||
| {name: "insecure", registryPrefix: "privateregistry:5001", tagSuffix: "private"}, | ||
| {name: "tls", registryPrefix: "tlsregistry:5003", tagSuffix: "tls"}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| dir := fixtures.SetupConfigFile(t) | ||
| t.Cleanup(dir.Remove) | ||
| emptyConfigDir := t.TempDir() | ||
|
|
||
| sourceImage := fixtures.AlpineImage | ||
| privateImage := tc.registryPrefix + "/private/alpine:test-" + tc.tagSuffix + "-pull-push" | ||
|
|
||
| runWithPrivateRegistryRetry(t, | ||
| icmd.Command("docker", "pull", sourceImage), | ||
| ).Assert(t, icmd.Success) | ||
| t.Cleanup(func() { | ||
| icmd.RunCommand("docker", "image", "rm", "-f", privateImage).Assert(t, icmd.Success) | ||
| }) | ||
|
|
||
| icmd.RunCommand("docker", "tag", sourceImage, privateImage).Assert(t, icmd.Success) | ||
|
|
||
| pushNoAuth := runWithPrivateRegistryRetry(t, | ||
| icmd.Command("docker", "push", privateImage), | ||
| fixtures.WithConfig(emptyConfigDir), | ||
| ) | ||
| pushNoAuth.Assert(t, icmd.Expected{ExitCode: 1}) | ||
| assertAuthDenied(t, pushNoAuth) | ||
|
|
||
| pushWithAuth := runWithPrivateRegistryRetry(t, | ||
| icmd.Command("docker", "push", privateImage), | ||
| fixtures.WithConfig(dir.Path()), | ||
| ) | ||
| pushWithAuth.Assert(t, icmd.Success) | ||
| // Docker omits the tag in the "push refers to repository" line; strip it before asserting. | ||
| privateRepo := privateImage[:strings.LastIndex(privateImage, ":")] | ||
| assert.Check(t, strings.Contains(pushWithAuth.Combined(), "The push refers to repository ["+privateRepo+"]"), pushWithAuth.Combined()) | ||
|
|
||
| icmd.RunCommand("docker", "image", "rm", "-f", privateImage).Assert(t, icmd.Success) | ||
|
|
||
| pullNoAuth := runWithPrivateRegistryRetry(t, | ||
| icmd.Command("docker", "pull", privateImage), | ||
| fixtures.WithConfig(emptyConfigDir), | ||
| ) | ||
| pullNoAuth.Assert(t, icmd.Expected{ExitCode: 1}) | ||
| assertAuthDenied(t, pullNoAuth) | ||
|
|
||
| pullWithAuth := runWithPrivateRegistryRetry(t, | ||
| icmd.Command("docker", "pull", privateImage), | ||
| fixtures.WithConfig(dir.Path()), | ||
| ) | ||
| pullWithAuth.Assert(t, icmd.Success) | ||
| assert.Check(t, strings.Contains(pullWithAuth.Combined(), privateImage), pullWithAuth.Combined()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func assertAuthDenied(t *testing.T, result *icmd.Result) { | ||
| t.Helper() | ||
| output := result.Combined() | ||
| if isPrivateRegistryTransient(output) { | ||
| t.Fatalf("private registry unavailable while expecting auth failure: %s", output) | ||
| } | ||
|
|
||
| assert.Assert(t, | ||
| strings.Contains(output, "requested access to the resource is denied") || | ||
| strings.Contains(output, "no basic auth credentials") || | ||
| strings.Contains(output, "unauthorized") || | ||
| strings.Contains(output, "authentication required"), | ||
| output, | ||
| ) | ||
| } | ||
|
|
||
| func runWithPrivateRegistryRetry(t *testing.T, cmd icmd.Cmd, opts ...icmd.CmdOp) *icmd.Result { | ||
| t.Helper() | ||
|
|
||
| deadline := time.Now().Add(90 * time.Second) | ||
| for { | ||
| result := icmd.RunCmd(cmd, opts...) | ||
| output := result.Combined() | ||
| if isPrivateRegistryTransient(output) { | ||
| if time.Now().Before(deadline) { | ||
| t.Logf("waiting for private registry availability: %s", output) | ||
| time.Sleep(500 * time.Millisecond) | ||
| continue | ||
| } | ||
| } | ||
| return result | ||
| } | ||
| } | ||
|
|
||
| func isPrivateRegistryTransient(output string) bool { | ||
| return strings.Contains(output, "lookup privateregistry") || | ||
| strings.Contains(output, "lookup tlsregistry") || | ||
| strings.Contains(output, "lookup registry") || | ||
| strings.Contains(output, "no such host") || | ||
| strings.Contains(output, "server misbehaving") || | ||
| strings.Contains(output, "Temporary failure in name resolution") || | ||
| strings.Contains(output, "connection refused") || | ||
| strings.Contains(output, "i/o timeout") || | ||
| strings.Contains(output, "TLS handshake timeout") || | ||
| strings.Contains(output, "context deadline exceeded") || | ||
| strings.Contains(output, "connection reset by peer") || | ||
| strings.Contains(output, "unexpected EOF") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ARG ENGINE_VERSION | ||
| FROM docker:${ENGINE_VERSION}-dind | ||
|
|
||
| # Trust the tlsregistry CA so dockerd connects without --insecure-registry. | ||
| COPY registry/certs/ca.crt /usr/local/share/ca-certificates/tlsregistry-ca.crt | ||
| RUN update-ca-certificates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| FROM registry:3 | ||
| COPY auth /auth | ||
| COPY certs /certs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| e2e:$2y$05$DxRBsGSy61vZsBgNVxwUh.UtZmlg3wZHMxYcHYAlupY7r1xbIiuoq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/sh | ||
| set -eu | ||
|
|
||
| # Regenerate test certificates for the TLS-enabled private registry. | ||
| # Run this from the repository root or from e2e/testdata/registry/certs/. | ||
|
|
||
| cd "$(dirname "$0")" | ||
|
|
||
| # --- CA --- | ||
| openssl genrsa -out ca.key 2048 | ||
| openssl req -new -x509 -days 3650 \ | ||
| -key ca.key \ | ||
| -subj '/CN=Test CA (TLS Registry)' \ | ||
| -out ca.crt | ||
|
|
||
| # --- Server cert for tlsregistry (signed by CA) --- | ||
| cat > openssl-tlsregistry.cnf <<-EOF | ||
| [v3_req] | ||
| subjectAltName=DNS:tlsregistry | ||
| EOF | ||
| openssl genrsa -out tlsregistry.key 2048 | ||
| openssl req -new \ | ||
| -key tlsregistry.key \ | ||
| -subj '/CN=tlsregistry' \ | ||
| -out tlsregistry.csr | ||
| openssl x509 -req -days 3650 \ | ||
| -in tlsregistry.csr \ | ||
| -CA ca.crt -CAkey ca.key \ | ||
| -CAcreateserial \ | ||
| -out tlsregistry.crt \ | ||
| -extfile openssl-tlsregistry.cnf \ | ||
| -extensions v3_req | ||
| rm -f tlsregistry.csr ca.srl openssl-tlsregistry.cnf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.