Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add check for ACR registry in ACR credential helper #1658

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
Loading