Skip to content

Commit

Permalink
fix: [sc-112114] registry collector failed to talk to Replicated priv…
Browse files Browse the repository at this point in the history
…ate registry (#1613)

decode auth for registry secret
  • Loading branch information
nvanthao authored Sep 13, 2024
1 parent 0c63880 commit 05dcae2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/collect/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/collect/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 05dcae2

Please sign in to comment.