Skip to content

Commit 50362e5

Browse files
authored
Merge pull request #1075 from BDworak/automated-cherry-pick-of-#1069-upstream-release-1.28
Automated cherry pick of #1069: Update ECR Regex to support new dual stack endpoints, modify
2 parents 4161da4 + be8d772 commit 50362e5

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

cmd/ecr-credential-provider/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
const ecrPublicRegion string = "us-east-1"
4343
const ecrPublicHost string = "public.ecr.aws"
4444

45-
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)$`)
45+
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)$`)
4646

4747
// ECR abstracts the calls we make to aws-sdk for testing purposes
4848
type ECR interface {
@@ -229,7 +229,7 @@ func parseHostFromImageReference(image string) (string, error) {
229229

230230
func parseRegionFromECRPrivateHost(host string) (string, error) {
231231
splitHost := ecrPrivateHostPattern.FindStringSubmatch(host)
232-
if len(splitHost) != 6 {
232+
if len(splitHost) != 5 {
233233
return "", fmt.Errorf("invalid private ECR host: %s", host)
234234
}
235235
return splitHost[3], nil

cmd/ecr-credential-provider/main_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,62 @@ func Test_parseRegionFromECRPrivateHost(t *testing.T) {
306306
region string
307307
err error
308308
}{
309+
// us-west-2
309310
{
310311
name: "success",
311312
host: "123456789123.dkr.ecr.us-west-2.amazonaws.com",
312313
region: "us-west-2",
313314
err: nil,
314315
},
316+
// CN region
317+
{
318+
name: "success",
319+
host: "123456789123.dkr.ecr.cn-north-1.amazonaws.com.cn",
320+
region: "cn-north-1",
321+
},
322+
// GovCloud
323+
{
324+
name: "success",
325+
host: "123456789123.dkr.ecr.us-gov-east-1.amazonaws.com",
326+
region: "us-gov-east-1",
327+
},
328+
// ISO
329+
{
330+
name: "success",
331+
host: "123456789123.dkr.ecr.us-iso-east-1.c2s.ic.gov",
332+
region: "us-iso-east-1",
333+
},
334+
// Dual-Stack
335+
{
336+
name: "success",
337+
host: "123456789123.dkr-ecr.us-west-2.on.aws",
338+
region: "us-west-2",
339+
},
340+
// Dual-Stack FIPS
341+
{
342+
name: "success",
343+
host: "123456789123.dkr-ecr-fips.us-west-2.on.aws",
344+
region: "us-west-2",
345+
},
346+
// IPv6 CN
347+
{
348+
name: "success",
349+
host: "123456789123.dkr-ecr.cn-north-1.on.amazonwebservices.com.cn",
350+
region: "cn-north-1",
351+
},
352+
// IPv6 GovCloud
353+
{
354+
name: "success",
355+
host: "123456789123.dkr-ecr.us-gov-east-1.on.aws",
356+
region: "us-gov-east-1",
357+
},
358+
// IPv6 GovCloud FIPS
359+
{
360+
name: "success",
361+
host: "123456789123.dkr-ecr-fips.us-gov-east-1.on.aws",
362+
region: "us-gov-east-1",
363+
},
364+
// Invalid name
315365
{
316366
name: "invalid registry",
317367
host: "foobar",
@@ -385,6 +435,12 @@ func TestRegistryPatternMatch(t *testing.T) {
385435
{"123456789012.dkr.ecr.us-isof-east-1.csp.hci.ic.gov", true},
386436
// invalid gov endpoint
387437
{"123456789012.dkr.ecr.us-iso-east-1.amazonaws.gov", false},
438+
//IPv6 dual stack endpoint
439+
{"123456789012.dkr-ecr.lala-land-1.on.aws", true},
440+
//IPv6 dual stack endpoint fips
441+
{"123456789012.dkr-ecr-fips.lala-land-1.on.aws", true},
442+
//IPv6 dual stack endpoint .cn
443+
{"123456789012.dkr-ecr.lala-land-1.on.amazonwebservices.com.cn", true},
388444
}
389445
for _, g := range grid {
390446
actual := ecrPrivateHostPattern.MatchString(g.Registry)

0 commit comments

Comments
 (0)