Skip to content

Commit 05dcae2

Browse files
authored
fix: [sc-112114] registry collector failed to talk to Replicated private registry (#1613)
decode auth for registry secret
1 parent 0c63880 commit 05dcae2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/collect/registry.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,14 @@ func getImageAuthConfigFromData(imageRef types.ImageReference, pullSecrets *v1be
221221
// docker.io auth uses auth, e.g. auth: <base64_encoded_username_password>
222222
// username and password can't contain colon
223223
// at least according to https://github.com/docker/cli/blob/v27.0.3/cli/config/configfile/file.go#L247
224-
parts := strings.Split(string(auth.Auth), ":")
224+
// fallback to not decode for compatibility
225+
authStr := auth.Auth
226+
decodedAuth, err := base64.StdEncoding.DecodeString(authStr)
227+
if err == nil {
228+
authStr = string(decodedAuth)
229+
}
230+
231+
parts := strings.Split(authStr, ":")
225232
if len(parts) != 2 {
226233
return nil, errors.Errorf("expected 2 parts in the auth string, but found %d", len(parts))
227234
}

pkg/collect/registry_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ func TestGetImageAuthConfigFromData(t *testing.T) {
4141
expectedPassword: "sa-key",
4242
expectedError: false,
4343
},
44+
{
45+
name: "proxy.replicated.com auth base64 encoded",
46+
imageName: "proxy.replicated.com/app-slug/myimage",
47+
dockerConfigJSON: `{"auths":{"proxy.replicated.com":{"auth":"bGljZW5zZV9pZF8xOmxpY2Vuc2VfaWRfMQ=="}}}`,
48+
expectedUsername: "license_id_1",
49+
expectedPassword: "license_id_1",
50+
expectedError: false,
51+
},
4452
}
4553

4654
for _, test := range tests {

0 commit comments

Comments
 (0)