From ce10318c8e445d261d93a8e22bfd930ebdc3499a Mon Sep 17 00:00:00 2001 From: Jeff Sedlak Date: Mon, 1 Apr 2024 13:11:05 -0400 Subject: [PATCH] Update Azure Credentials Provider Regex to be non-greedy --- pkg/credentialprovider/azure_credentials.go | 2 +- pkg/credentialprovider/azure_credentials_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/credentialprovider/azure_credentials.go b/pkg/credentialprovider/azure_credentials.go index 871bd941af..08d010f759 100644 --- a/pkg/credentialprovider/azure_credentials.go +++ b/pkg/credentialprovider/azure_credentials.go @@ -44,7 +44,7 @@ const ( var ( containerRegistryUrls = []string{"*.azurecr.io", "*.azurecr.cn", "*.azurecr.de", "*.azurecr.us"} - acrRE = regexp.MustCompile(`.*\.azurecr\.io|.*\.azurecr\.cn|.*\.azurecr\.de|.*\.azurecr\.us`) + acrRE = regexp.MustCompile(`^.+?\.(azurecr\.io|azurecr\.cn|azurecr\.de|azurecr\.us)`) ) // CredentialProvider is an interface implemented by the kubelet credential provider plugin to fetch diff --git a/pkg/credentialprovider/azure_credentials_test.go b/pkg/credentialprovider/azure_credentials_test.go index 940fb53b8e..7a705bc681 100644 --- a/pkg/credentialprovider/azure_credentials_test.go +++ b/pkg/credentialprovider/azure_credentials_test.go @@ -193,6 +193,10 @@ func TestParseACRLoginServerFromImage(t *testing.T) { image: "foo.azurecr.my.cloud/bar/image:version", expected: "foo.azurecr.my.cloud", }, + { + image: "foo.azurecr.us/foo.azurecr.io/bar/image:version", + expected: "foo.azurecr.us", + }, } for _, test := range tests { if loginServer := provider.parseACRLoginServerFromImage(test.image); loginServer != test.expected {