Skip to content

Commit 6939398

Browse files
committed
[image-builder-bob] tolerate host:port:token
Special case is to strip port for 443
1 parent 6f33488 commit 6939398

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

components/image-builder-bob/pkg/proxy/auth.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,30 @@ func (a MapAuthorizer) Authorize(host string) (user, pass string, err error) {
5353
}()
5454

5555
// Strip any port from the host if present
56-
host = strings.Split(host, ":")[0]
56+
hostSlice := strings.Split(host, ":")
57+
portStrippedHost := hostSlice[0]
58+
var port string
59+
if len(hostSlice) > 1 {
60+
port = hostSlice[1]
61+
}
5762

5863
explicitHostMatcher := func() (authConfig, bool) {
59-
res, ok := a[host]
64+
eval := host
65+
if port == "443" {
66+
eval = portStrippedHost
67+
}
68+
res, ok := a[eval]
6069
return res, ok
6170
}
6271
ecrHostMatcher := func() (authConfig, bool) {
63-
if isECRRegistry(host) {
72+
if isECRRegistry(portStrippedHost) {
6473
res, ok := a[DummyECRRegistryDomain]
6574
return res, ok
6675
}
6776
return authConfig{}, false
6877
}
6978
dockerHubHostMatcher := func() (authConfig, bool) {
70-
if isDockerHubRegistry(host) {
79+
if isDockerHubRegistry(portStrippedHost) {
7180
res, ok := a["docker.io"]
7281
return res, ok
7382
}

components/image-builder-bob/pkg/proxy/auth_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestAuthorize(t *testing.T) {
3232
},
3333
},
3434
{
35-
name: "docker auth format - valid credentials - host with port",
35+
name: "docker auth format - valid credentials - host with :443 port",
3636
constructor: NewAuthorizerFromDockerEnvVar,
3737
input: `{"auths": {"registry.example.com": {"auth": "dXNlcjpwYXNz"}}}`, // base64(user:pass)
3838
testHost: "registry.example.com:443",
@@ -110,6 +110,26 @@ func TestAuthorize(t *testing.T) {
110110
pass: "",
111111
},
112112
},
113+
{
114+
name: "Docker Hub",
115+
constructor: NewAuthorizerFromEnvVar,
116+
input: `{"docker.io": {"auth": "dXNlcjpwYXNz"}}`,
117+
testHost: "registry-1.docker.io",
118+
expected: expectation{
119+
user: "user",
120+
pass: "pass",
121+
},
122+
},
123+
{
124+
name: "docker auth format - valid credentials - host with :5000 port",
125+
constructor: NewAuthorizerFromDockerEnvVar,
126+
input: `{"auths": {"registry.example.com:5000": {"auth": "dXNlcjpwYXNz"}}}`, // base64(user:pass)
127+
testHost: "registry.example.com:5000",
128+
expected: expectation{
129+
user: "user",
130+
pass: "pass",
131+
},
132+
},
113133
}
114134

115135
for _, tt := range tests {

0 commit comments

Comments
 (0)