Skip to content

Commit

Permalink
Add Dual Stack Public ECR endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
BDworak committed Dec 10, 2024
1 parent 2bec795 commit 98f70b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/ecr-credential-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"regexp"
"strings"
"time"
"slices"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand All @@ -40,7 +41,10 @@ import (
)

const ecrPublicRegion string = "us-east-1"
const ecrPublicHost string = "public.ecr.aws"

func getECRPublicHosts() []string {
return []string{"public.ecr.aws", "ecr-public.aws.com"}
}

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

Expand Down Expand Up @@ -162,7 +166,7 @@ func (e *ecrPlugin) GetCredentials(ctx context.Context, image string, args []str
return nil, err
}

if imageHost == ecrPublicHost {
if slices.Contains(getECRPublicHosts(), imageHost) {
creds, err = e.getPublicCredsData(ctx)
} else {
creds, err = e.getPrivateCredsData(ctx, imageHost, image)
Expand Down
6 changes: 6 additions & 0 deletions cmd/ecr-credential-provider/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ func Test_GetCredentials_Public(t *testing.T) {
getAuthorizationTokenOutput: generatePublicGetAuthorizationTokenOutput("user", "pass", "", nil),
response: generateResponse("public.ecr.aws", "user", "pass"),
},
{
name: "success dual stack public endpoint",
image: "ecr-public.aws.com",
getAuthorizationTokenOutput: generatePublicGetAuthorizationTokenOutput("user", "pass", "", nil),
response: generateResponse("ecr-public.aws.com", "user", "pass"),
},
{
name: "empty authorization data",
image: "public.ecr.aws",
Expand Down

0 comments on commit 98f70b1

Please sign in to comment.