Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 9decba2

Browse files
authored
Add check for ACR registry in ACR credential helper (#1658)
Signed-off-by: Cody Soyland <[email protected]>
1 parent cbf084e commit 9decba2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/webhook/registryauth/azure/acrhelper.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"net/url"
2222
"os"
23+
"strings"
2324

2425
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/containerregistry/runtime/containerregistry"
2526
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
@@ -42,6 +43,10 @@ func (a ACRHelper) Delete(_ string) error {
4243
}
4344

4445
func (a ACRHelper) Get(registryURL string) (string, string, error) {
46+
if !isACR(registryURL) {
47+
return "", "", fmt.Errorf("not an ACR registry")
48+
}
49+
4550
azCred, err := azidentity.NewDefaultAzureCredential(nil)
4651
if err != nil {
4752
return "", "", fmt.Errorf("failed to obtain a credential: %w", err)
@@ -81,3 +86,7 @@ func (a ACRHelper) Get(registryURL string) (string, string, error) {
8186
func (a ACRHelper) List() (map[string]string, error) {
8287
return nil, fmt.Errorf("list is unimplemented")
8388
}
89+
90+
func isACR(registryURL string) bool {
91+
return strings.HasSuffix(registryURL, ".azurecr.io")
92+
}

0 commit comments

Comments
 (0)