Skip to content

Commit

Permalink
Update ECR Regex to support new dual stack endpoints + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BDworak committed Dec 6, 2024
1 parent e58b027 commit 9dffb43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/ecr-credential-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
const ecrPublicRegion string = "us-east-1"
const ecrPublicHost string = "public.ecr.aws"

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

// ECR abstracts the calls we make to aws-sdk for testing purposes
type ECR interface {
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 @@ -395,6 +395,12 @@ func TestRegistryPatternMatch(t *testing.T) {
{"123456789012.dkr.ecr.us-isof-east-1.csp.hci.ic.gov", true},
// invalid gov endpoint
{"123456789012.dkr.ecr.us-iso-east-1.amazonaws.gov", false},
//IPv6 dual stack endpoint
{"123456789012.dkr-ecr.lala-land-1..on.aws", true},
//IPv6 dual stack endpoint fips
{"123456789012.dkr-ecr-fips.lala-land-1.on.aws", true},
//IPv6 dual stack endpoint .cn
{"123456789012.dkr-ecr.lala-land-1.on.amazonwebservices.com.cn", true},
}
for _, g := range grid {
actual := ecrPrivateHostPattern.MatchString(g.Registry)
Expand Down

0 comments on commit 9dffb43

Please sign in to comment.