Skip to content

Commit d54623a

Browse files
authored
Merge pull request #835 from ngearhart/update-ecr-parsing
Update ECR parsing regex to include non-public AWS partitions
2 parents cb8e4a8 + 6c80137 commit d54623a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

oci/auth/aws/auth.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import (
3737
"github.com/fluxcd/pkg/oci"
3838
)
3939

40-
var registryPartRe = regexp.MustCompile(`([0-9+]*).dkr.ecr(?:-fips)?\.([^/.]*)\.(amazonaws\.com[.cn]*)`)
40+
// This regex is sourced from the AWS ECR Credential Helper (https://github.com/awslabs/amazon-ecr-credential-helper).
41+
// It covers both public AWS partitions like amazonaws.com, China partitions like amazonaws.com.cn, and non-public partitions.
42+
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)`)
4143

4244
// ParseRegistry returns the AWS account ID and region and `true` if
4345
// the image registry/repository is hosted in AWS's Elastic Container Registry,

oci/auth/aws/auth_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ func TestParseRegistry(t *testing.T) {
7777
wantRegion: "us-gov-west-1",
7878
wantOK: true,
7979
},
80+
{
81+
registry: "012345678901.dkr.ecr.us-secret-region.sc2s.sgov.gov",
82+
wantAccountID: "012345678901",
83+
wantRegion: "us-secret-region",
84+
wantOK: true,
85+
},
86+
{
87+
registry: "012345678901.dkr.ecr-fips.us-ts-region.c2s.ic.gov",
88+
wantAccountID: "012345678901",
89+
wantRegion: "us-ts-region",
90+
wantOK: true,
91+
},
92+
{
93+
registry: "012345678901.dkr.ecr.uk-region.cloud.adc-e.uk",
94+
wantAccountID: "012345678901",
95+
wantRegion: "uk-region",
96+
wantOK: true,
97+
},
98+
{
99+
registry: "012345678901.dkr.ecr.us-ts-region.csp.hci.ic.gov",
100+
wantAccountID: "012345678901",
101+
wantRegion: "us-ts-region",
102+
wantOK: true,
103+
},
80104
// TODO: Fix: this invalid registry is allowed by the regex.
81105
// {
82106
// registry: ".dkr.ecr.error.amazonaws.com",

0 commit comments

Comments
 (0)