Skip to content

Commit 95db4a1

Browse files
authored
Merge pull request #1345 from mselim00/automated-cherry-pick-of-#1332-upstream-release-1.34
Automated cherry pick of #1332: feat(ecr-cred-provider): support public dualstack endpoints
2 parents 4e5afee + 68c6b45 commit 95db4a1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

cmd/ecr-credential-provider/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/url"
2525
"os"
2626
"regexp"
27+
"slices"
2728
"strings"
2829
"time"
2930

@@ -41,7 +42,8 @@ import (
4142
)
4243

4344
const ecrPublicRegion string = "us-east-1"
44-
const ecrPublicHost string = "public.ecr.aws"
45+
46+
var ecrPublicHosts []string = []string{"public.ecr.aws", "ecr-public.aws.com"}
4547

4648
var ecrPrivateHostPattern = regexp.MustCompile(`^(\d{12})\.dkr[\.\-]ecr(\-fips)?\.([a-zA-Z0-9][a-zA-Z0-9-_]*)\.(amazonaws\.(?:com(?:\.cn)?|eu)|on\.(?:aws|amazonwebservices\.com\.cn)|sc2s\.sgov\.gov|c2s\.ic\.gov|cloud\.adc-e\.uk|csp\.hci\.ic\.gov)$`)
4749

@@ -192,7 +194,7 @@ func (e *ecrPlugin) buildCredentialsProvider(ctx context.Context, request *v1.Cr
192194

193195
if e.sts == nil {
194196
region := ""
195-
if imageHost != ecrPublicHost {
197+
if !slices.Contains(ecrPublicHosts, imageHost) {
196198
region = parseRegionFromECRPrivateHost(imageHost)
197199
}
198200
e.sts, err = stsProvider(ctx, region)
@@ -240,7 +242,7 @@ func (e *ecrPlugin) GetCredentials(ctx context.Context, request *v1.CredentialPr
240242
}
241243
}
242244

243-
if imageHost == ecrPublicHost {
245+
if slices.Contains(ecrPublicHosts, imageHost) {
244246
var optFns = []func(*ecrpublic.Options){}
245247
if credentialsProvider != nil {
246248
optFns = append(optFns, func(o *ecrpublic.Options) {

cmd/ecr-credential-provider/main_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ func Test_GetCredentials_Public(t *testing.T) {
327327
getAuthorizationTokenOutput: generatePublicGetAuthorizationTokenOutput("user", "pass", nil),
328328
response: generateResponse("public.ecr.aws", "user", "pass"),
329329
},
330+
{
331+
name: "dualstack success",
332+
image: "ecr-public.aws.com",
333+
getAuthorizationTokenOutput: generatePublicGetAuthorizationTokenOutput("user", "pass", nil),
334+
response: generateResponse("ecr-public.aws.com", "user", "pass"),
335+
},
330336
{
331337
name: "empty image",
332338
image: "",
@@ -373,6 +379,17 @@ func Test_GetCredentials_Public(t *testing.T) {
373379
getAuthorizationTokenError: nil,
374380
expectedError: errors.New("error parsing username and password from authorization token"),
375381
},
382+
{
383+
name: "dualstack invalid authorization token",
384+
image: "ecr-public.aws.com",
385+
getAuthorizationTokenOutput: &ecrpublic.GetAuthorizationTokenOutput{
386+
AuthorizationData: &publictypes.AuthorizationData{
387+
AuthorizationToken: aws.String(base64.StdEncoding.EncodeToString([]byte("foo"))),
388+
},
389+
},
390+
getAuthorizationTokenError: nil,
391+
expectedError: errors.New("error parsing username and password from authorization token"),
392+
},
376393
}
377394

378395
for _, testcase := range testcases {

0 commit comments

Comments
 (0)