Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Dual Stack Public ECR endpoint support #1070

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions cmd/ecr-credential-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/url"
"os"
"regexp"
"slices"
"strings"
"time"

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