Skip to content

Commit

Permalink
Add check for ACR registry in ACR credential helper (#1658)
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Soyland <codysoyland@github.com>
  • Loading branch information
codysoyland authored Oct 31, 2024
1 parent cbf084e commit 9decba2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/webhook/registryauth/azure/acrhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net/url"
"os"
"strings"

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

func (a ACRHelper) Get(registryURL string) (string, string, error) {
if !isACR(registryURL) {
return "", "", fmt.Errorf("not an ACR registry")
}

azCred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return "", "", fmt.Errorf("failed to obtain a credential: %w", err)
Expand Down Expand Up @@ -81,3 +86,7 @@ func (a ACRHelper) Get(registryURL string) (string, string, error) {
func (a ACRHelper) List() (map[string]string, error) {
return nil, fmt.Errorf("list is unimplemented")
}

func isACR(registryURL string) bool {
return strings.HasSuffix(registryURL, ".azurecr.io")
}

0 comments on commit 9decba2

Please sign in to comment.