Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ec2): fixing vpc endpoint pattern for ecr and ecr docker #31434

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/aws-cdk-lib/aws-ec2/lib/vpc-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ISubnet, IVpc, SubnetSelection } from './vpc';
import * as iam from '../../aws-iam';
import * as cxschema from '../../cloud-assembly-schema';
import { Aws, ContextProvider, IResource, Lazy, Resource, Stack, Token } from '../../core';
import { PARTITION_MAP } from '../../region-info/build-tools/fact-tables';

/**
* A VPC endpoint.
Expand Down Expand Up @@ -666,8 +667,21 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ
'redshift', 'redshift-data', 's3', 'sagemaker.api', 'sagemaker.featurestore-runtime', 'sagemaker.runtime', 'securityhub',
'servicecatalog', 'sms', 'sqs', 'states', 'sts', 'sync-states', 'synthetics', 'transcribe', 'transcribestreaming', 'transfer',
'workspaces', 'xray'],
'us-isof-': ['ecr.api', 'ecr.dkr'],
'eu-isoe-': ['ecr.api', 'ecr.dkr'],
Comment on lines +670 to +671
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only need this two here? What about other us gov regions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two are the only ones flagged in ticket, so for now only these two. These are isolated, for US Gov region i think it starts with us-gov

};
if (VPC_ENDPOINT_SERVICE_EXCEPTIONS[region]?.includes(name)) {

const regionPartition = region.split('-').slice(0, 2).join('-');
const partitionDetails = PARTITION_MAP[`${regionPartition}-`];
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved

// Check for specific service name under isolated region prefix
const serviceInExceptions = VPC_ENDPOINT_SERVICE_EXCEPTIONS[`${regionPartition}-`]?.includes(name);

if (serviceInExceptions) {
// Endpoints generated in reverse of domain suffix for the services mentioned in map
const reverseString = partitionDetails.domainSuffix.split('.').reverse().join('.');
return reverseString;
} else if (VPC_ENDPOINT_SERVICE_EXCEPTIONS[region]?.includes(name)) {
return 'cn.com.amazonaws';
} else {
return 'com.amazonaws';
Expand Down
31 changes: 31 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/test/vpc-endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,37 @@ describe('vpc endpoint', () => {
});

});

test.each([
['us-isof-test-1', 'gov.ic.hci.csp'],
['eu-isoe-test-1', 'uk.adc-e.cloud'],
['us-east-1', 'com.amazonaws'],
['us-gov-west-1', 'com.amazonaws'],
['cn-northwest-1', 'cn.com.amazonaws'],
['cn-north-1', 'cn.com.amazonaws'],
])('test vpc interface endpoint for ECR can be created correctly in all regions', (region : string, domain: string) => {
//GIVEN
const stack = new Stack(undefined, 'TestStack', { env: { account: '123456789012', region: region } });
const vpc = new Vpc(stack, 'VPC');

//WHEN
vpc.addInterfaceEndpoint('ECR Endpoint', {
service: InterfaceVpcEndpointAwsService.ECR,
});

vpc.addInterfaceEndpoint('ECR Docker Endpoint', {
service: InterfaceVpcEndpointAwsService.ECR_DOCKER,
});

//THEN
Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPCEndpoint', {
ServiceName: `${domain}.${region}.ecr.api`,
});
Template.fromStack(stack).hasResourceProperties('AWS::EC2::VPCEndpoint', {
ServiceName: `${domain}.${region}.ecr.dkr`,
});
});

test.each([
['transcribe', InterfaceVpcEndpointAwsService.TRANSCRIBE],
])('test vpc interface endpoint with .cn suffix for %s can be created correctly in China regions', (name: string, given: InterfaceVpcEndpointAwsService) => {
Expand Down
Loading