Skip to content

Commit 19f4879

Browse files
authored
Merge branch 'main' into add-ssl-option-cassandra
2 parents 545a00e + c75e56c commit 19f4879

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

Pipfile.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker_auth.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"net/url"
1212
"os"
13+
"strings"
1314
"sync"
1415

1516
"github.com/cpuguy83/dockercfg"
@@ -42,6 +43,13 @@ func dockerImageAuth(ctx context.Context, image string, configs map[string]regis
4243
defaultRegistry := defaultRegistryFn(ctx)
4344
reg := core.ExtractRegistry(image, defaultRegistry)
4445

46+
// Normalize Docker Hub aliases for credential lookup
47+
if strings.EqualFold(reg, "docker.io") ||
48+
strings.EqualFold(reg, "registry.hub.docker.com") ||
49+
strings.EqualFold(reg, "registry-1.docker.io") {
50+
reg = defaultRegistry // This is https://index.docker.io/v1/
51+
}
52+
4553
if cfg, ok := getRegistryAuth(reg, configs); ok {
4654
return reg, cfg, nil
4755
}

docker_auth_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ func TestDockerImageAuth(t *testing.T) {
123123
require.Equal(t, base64, cfg.Auth)
124124
})
125125

126+
t.Run("match the default registry authentication by host", func(t *testing.T) {
127+
imageReg := "docker.io"
128+
imagePath := "/my/image:latest"
129+
reg := defaultRegistry(context.Background())
130+
base64 := setAuthConfig(t, reg, "gopher", "secret")
131+
132+
registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath)
133+
require.NoError(t, err)
134+
require.Equal(t, reg, registry)
135+
require.Equal(t, "gopher", cfg.Username)
136+
require.Equal(t, "secret", cfg.Password)
137+
require.Equal(t, base64, cfg.Auth)
138+
})
139+
126140
t.Run("fail to match registry authentication due to invalid host", func(t *testing.T) {
127141
imageReg := "example-auth.com"
128142
imagePath := "/my/image:latest"

internal/core/images.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ func ExtractRegistry(image string, fallback string) string {
100100

101101
registry := exp[1]
102102

103+
// docker.io is an implicit reference, return fallback for normalization
104+
if strings.EqualFold(registry, "docker.io") {
105+
return fallback
106+
}
107+
108+
// registry.hub.docker.com is an explicit registry reference, preserve it
109+
if strings.EqualFold(registry, "registry.hub.docker.com") {
110+
return "registry.hub.docker.com"
111+
}
112+
103113
if IsURL(registry) {
104114
return registry
105115
}

0 commit comments

Comments
 (0)