fix: [sc-112114] registry collector failed to talk to Replicated private registry (#1613)

decode auth for registry secret
This commit is contained in:
Gerard Nguyen
2024-09-13 15:03:52 +01:00
committed by GitHub
parent 0c63880528
commit afae30e9b9
2 changed files with 16 additions and 1 deletions
+8 -1
View File
@@ -221,7 +221,14 @@ func getImageAuthConfigFromData(imageRef types.ImageReference, pullSecrets *v1be
// docker.io auth uses auth, e.g. auth: <base64_encoded_username_password>
// username and password can't contain colon
// at least according to https://github.com/docker/cli/blob/v27.0.3/cli/config/configfile/file.go#L247
parts := strings.Split(string(auth.Auth), ":")
// fallback to not decode for compatibility
authStr := auth.Auth
decodedAuth, err := base64.StdEncoding.DecodeString(authStr)
if err == nil {
authStr = string(decodedAuth)
}
parts := strings.Split(authStr, ":")
if len(parts) != 2 {
return nil, errors.Errorf("expected 2 parts in the auth string, but found %d", len(parts))
}
+8
View File
@@ -41,6 +41,14 @@ func TestGetImageAuthConfigFromData(t *testing.T) {
expectedPassword: "sa-key",
expectedError: false,
},
{
name: "proxy.replicated.com auth base64 encoded",
imageName: "proxy.replicated.com/app-slug/myimage",
dockerConfigJSON: `{"auths":{"proxy.replicated.com":{"auth":"bGljZW5zZV9pZF8xOmxpY2Vuc2VfaWRfMQ=="}}}`,
expectedUsername: "license_id_1",
expectedPassword: "license_id_1",
expectedError: false,
},
}
for _, test := range tests {