Skip to content

Commit

Permalink
Remove requirement for ECR URL to end in amazonaws.com or amazonaws.c…
Browse files Browse the repository at this point in the history
…om.cn

Signed-off-by: Noah Gearhart <[email protected]>
  • Loading branch information
ngearhart committed Dec 6, 2024
1 parent 3431579 commit 541f6cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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]*)`)
// We cannot put "amazonaws.com" at the end of the regex because some AWS partitions do not use "amazonaws.com" as their domain name.
// However, we can assume the structure <Account ID>.dkr.ecr<-fips?>.<Region>.<Partition API domain> is consistent everywhere.
var registryPartRe = regexp.MustCompile(`([0-9+]+).dkr.ecr(?:-fips)?\.([^/.]*)\.`)

// 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
21 changes: 16 additions & 5 deletions oci/auth/aws/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,22 @@ func TestParseRegistry(t *testing.T) {
wantRegion: "us-gov-west-1",
wantOK: true,
},
// TODO: Fix: this invalid registry is allowed by the regex.
// {
// registry: ".dkr.ecr.error.amazonaws.com",
// wantOK: false,
// },
{
registry: "012345678901.dkr.ecr.special-region.special-partition.unknown",
wantAccountID: "012345678901",
wantRegion: "special-region",
wantOK: true,
},
{
registry: "012345678901.dkr.ecr-fips.special-region.special-partition.unknown",
wantAccountID: "012345678901",
wantRegion: "special-region",
wantOK: true,
},
{
registry: ".dkr.ecr.error.amazonaws.com",
wantOK: false,
},
{
registry: "gcr.io/foo/bar:baz",
wantOK: false,
Expand Down

0 comments on commit 541f6cc

Please sign in to comment.