An unexpected security group rule

0

Hi,

An inbound HTTPS(443) TCP rule is added to my SG when I add a VPC Interface Endpoint using the ec2.Vpc L1 construct method addInterfaceEndpoint. If I use CfnVPCEndpoint (commented out below) instead. all is good.

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';

export class ScratchStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = new ec2.Vpc(this, 'vpc', {
    });

    const vpcEndpointSg = new ec2.SecurityGroup(this, 'vpc-endpoint-sg', {
      vpc: vpc,
      allowAllOutbound: true
    });

    vpc.addInterfaceEndpoint('vpc-endpoint', {
      service: ec2.InterfaceVpcEndpointAwsService.IOT_CORE,
      privateDnsEnabled: false,
      securityGroups: [vpcEndpointSg]
    });

    // new ec2.CfnVPCEndpoint(this, 'cfn-vpc-endpoint', {
    //   serviceName: `com.amazonaws.${process.env.CDK_DEFAULT_REGION}.iot.data`,
    //   vpcId: `${vpc.vpcId}`,
    //   vpcEndpointType: 'Interface',
    //   securityGroupIds: [vpcEndpointSg.securityGroupId]
    // });

  }
}

Thoughts/help welcome.

Thanks, Gary

1개 답변
1
수락된 답변

Compared to cloudformation CDK is opinionated and includes settings to shortcut creating a resource. In your example a IOT vpc endpoint must allow 443 inbound for it to be at all useful so this rule is automatically added by default. You can override this be setting the parameter "open" to false (it is default true). See in docs

AWS
전문가
Peter_G
답변함 일 년 전
  • Thanks Peter, I didn't spot the 'open' prop! (And I think using the InterfaceVpcEndpoint construct is more appropriate in my context than the Vpc construct method). In my real code, I have other SG rules, so it's useful without 443 i/b :-)

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠