Skip to content

Commit

Permalink
Merge pull request #835 from ngearhart/update-ecr-parsing
Browse files Browse the repository at this point in the history
Update ECR parsing regex to include non-public AWS partitions
  • Loading branch information
stefanprodan authored Jan 9, 2025
2 parents cb8e4a8 + 6c80137 commit d54623a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion oci/auth/aws/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import (
"github.com/fluxcd/pkg/oci"
)

var registryPartRe = regexp.MustCompile(`([0-9+]*).dkr.ecr(?:-fips)?\.([^/.]*)\.(amazonaws\.com[.cn]*)`)
// This regex is sourced from the AWS ECR Credential Helper (https://github.com/awslabs/amazon-ecr-credential-helper).
// It covers both public AWS partitions like amazonaws.com, China partitions like amazonaws.com.cn, and non-public partitions.
var registryPartRe = regexp.MustCompile(`([0-9+]*).dkr.ecr(?:-fips)?\.([^/.]*)\.(amazonaws\.com[.cn]*|sc2s\.sgov\.gov|c2s\.ic\.gov|cloud\.adc-e\.uk|csp\.hci\.ic\.gov)`)

// ParseRegistry returns the AWS account ID and region and `true` if
// the image registry/repository is hosted in AWS's Elastic Container Registry,
Expand Down
24 changes: 24 additions & 0 deletions oci/auth/aws/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ func TestParseRegistry(t *testing.T) {
wantRegion: "us-gov-west-1",
wantOK: true,
},
{
registry: "012345678901.dkr.ecr.us-secret-region.sc2s.sgov.gov",
wantAccountID: "012345678901",
wantRegion: "us-secret-region",
wantOK: true,
},
{
registry: "012345678901.dkr.ecr-fips.us-ts-region.c2s.ic.gov",
wantAccountID: "012345678901",
wantRegion: "us-ts-region",
wantOK: true,
},
{
registry: "012345678901.dkr.ecr.uk-region.cloud.adc-e.uk",
wantAccountID: "012345678901",
wantRegion: "uk-region",
wantOK: true,
},
{
registry: "012345678901.dkr.ecr.us-ts-region.csp.hci.ic.gov",
wantAccountID: "012345678901",
wantRegion: "us-ts-region",
wantOK: true,
},
// TODO: Fix: this invalid registry is allowed by the regex.
// {
// registry: ".dkr.ecr.error.amazonaws.com",
Expand Down

0 comments on commit d54623a

Please sign in to comment.