Skip to content
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

Simplify credential normalization, fix tests #1318

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pkg/docker/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,11 @@ func findAuthentication(ref reference.Named, registry, path string, legacyFormat
// those entries even in non-legacyFormat ~/.docker/config.json.
// The docker.io registry still uses the /v1/ key with a special host name,
// so account for that as well.
registry = normalizeAuthFileKey(registry, legacyFormat)
normalizedAuths := map[string]dockerAuthConfig{}
registry = normalizeRegistry(registry)
for k, v := range auths.AuthConfigs {
normalizedAuths[normalizeAuthFileKey(k, legacyFormat)] = v
}

if val, exists := normalizedAuths[registry]; exists {
return decodeDockerAuth(val)
if normalizeAuthFileKey(k, legacyFormat) == registry {
return decodeDockerAuth(v)
}
}

return types.DockerAuthConfig{}, nil
Expand Down
22 changes: 11 additions & 11 deletions pkg/docker/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ func TestGetAuth(t *testing.T) {
},
{
name: "normalize registry",
hostname: "https://example.org/v1",
hostname: "normalize.example.org",
path: filepath.Join("testdata", "full.json"),
expected: types.DockerAuthConfig{
Username: "example",
Password: "org",
Username: "normalize",
Password: "example",
},
testPreviousAPI: true,
},
{
name: "match localhost",
hostname: "http://localhost",
hostname: "localhost",
path: filepath.Join("testdata", "full.json"),
expected: types.DockerAuthConfig{
Username: "local",
Expand All @@ -222,7 +222,7 @@ func TestGetAuth(t *testing.T) {
},
{
name: "match port",
hostname: "https://localhost:5000",
hostname: "localhost:5000",
path: filepath.Join("testdata", "abnormal.json"),
expected: types.DockerAuthConfig{
Username: "local",
Expand Down Expand Up @@ -387,16 +387,16 @@ func TestGetAuthFromLegacyFile(t *testing.T) {
expectedError error
}{
{
name: "normalize registry",
hostname: "https://docker.io/v1",
name: "ignore schema and path",
hostname: "localhost",
expected: types.DockerAuthConfig{
Username: "docker",
Password: "io-legacy",
Username: "local",
Password: "host-legacy",
},
},
{
name: "ignore schema and path",
hostname: "http://index.docker.io/v1",
name: "normalize registry",
hostname: "docker.io",
expected: types.DockerAuthConfig{
Username: "docker",
Password: "io-legacy",
Expand Down
3 changes: 3 additions & 0 deletions pkg/docker/config/testdata/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
"10.10.30.45:5000": {
"auth": "MTAuMTA6MzAuNDUtNTAwMA=="
},
"https://normalize.example.org/v1": {
"auth": "bm9ybWFsaXplOmV4YW1wbGU="
}
}
}
2 changes: 1 addition & 1 deletion pkg/docker/config/testdata/legacy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"docker.io/v2": {
"http://index.docker.io/v1": {
"auth": "ZG9ja2VyOmlvLWxlZ2FjeQ=="
},
"https://localhost/v1": {
Expand Down