Skip to content

Commit 295a85a

Browse files
authored
Merge pull request #1344 from mselim00/automated-cherry-pick-of-#1332-upstream-release-1.35
Automated cherry pick of #1332: feat(ecr-cred-provider): support public dualstack endpoints
2 parents 277b2a4 + 02dd001 commit 295a85a

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

@@ -195,7 +197,7 @@ func (e *ecrPlugin) buildCredentialsProvider(ctx context.Context, request *v1.Cr
195197

196198
if e.sts == nil {
197199
region := ""
198-
if imageHost != ecrPublicHost {
200+
if !slices.Contains(ecrPublicHosts, imageHost) {
199201
region = parseRegionFromECRPrivateHost(imageHost)
200202
}
201203
sts, err := stsProvider(ctx, region)
@@ -237,7 +239,7 @@ func (e *ecrPlugin) GetCredentials(ctx context.Context, request *v1.CredentialPr
237239
}
238240

239241
credentialsProvider := e.buildCredentialsProvider(ctx, request, imageHost)
240-
if imageHost == ecrPublicHost {
242+
if slices.Contains(ecrPublicHosts, imageHost) {
241243
var optFns = []func(*ecrpublic.Options){}
242244
if credentialsProvider != nil {
243245
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
@@ -341,6 +341,12 @@ func Test_GetCredentials_Public(t *testing.T) {
341341
getAuthorizationTokenOutput: generatePublicGetAuthorizationTokenOutput("user", "pass", nil),
342342
response: generateResponse("public.ecr.aws", "user", "pass"),
343343
},
344+
{
345+
name: "dualstack success",
346+
image: "ecr-public.aws.com",
347+
getAuthorizationTokenOutput: generatePublicGetAuthorizationTokenOutput("user", "pass", nil),
348+
response: generateResponse("ecr-public.aws.com", "user", "pass"),
349+
},
344350
{
345351
name: "empty image",
346352
image: "",
@@ -387,6 +393,17 @@ func Test_GetCredentials_Public(t *testing.T) {
387393
getAuthorizationTokenError: nil,
388394
expectedError: errors.New("error parsing username and password from authorization token"),
389395
},
396+
{
397+
name: "dualstack invalid authorization token",
398+
image: "ecr-public.aws.com",
399+
getAuthorizationTokenOutput: &ecrpublic.GetAuthorizationTokenOutput{
400+
AuthorizationData: &publictypes.AuthorizationData{
401+
AuthorizationToken: aws.String(base64.StdEncoding.EncodeToString([]byte("foo"))),
402+
},
403+
},
404+
getAuthorizationTokenError: nil,
405+
expectedError: errors.New("error parsing username and password from authorization token"),
406+
},
390407
}
391408

392409
for _, testcase := range testcases {

0 commit comments

Comments
 (0)