VPC Default Security Group Has Rules
vpc-default-security-group-rules-present
What this rule checks
Detects standalone security group rules attached to a VPC default security group (GroupId referencing Fn::GetAtt DefaultSecurityGroup). CIS requires the default group to have no rules.
How to fix it
- 1Attach rules to a purpose-built security group instead of the VPC default group
- 2In CDK, enable restrictDefaultSecurityGroup: true on the Vpc so the default group has no rules
import { App, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
// FLAGGED: rules added to the VPC's default security group.
new ec2.CfnSecurityGroup(this, 'DefaultSg', {
groupName: 'default',
groupDescription: 'default VPC security group',
securityGroupIngress: [
{ ipProtocol: 'tcp', fromPort: 443, toPort: 443, cidrIp: '0.0.0.0/0' },
],
});import { App, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
// FIXED: default group left empty; a purpose-built SG carries the rules.
new ec2.CfnSecurityGroup(this, 'DefaultSg', {
groupName: 'default',
groupDescription: 'default VPC security group',
});
new ec2.CfnSecurityGroup(this, 'WebSg', {
groupDescription: 'web tier',
securityGroupIngress: [
{ ipProtocol: 'tcp', fromPort: 443, toPort: 443, cidrIp: '0.0.0.0/0' },
],
});CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.
Affected resource types
AWS::EC2::SecurityGroupIngressAWS::EC2::SecurityGroupEgressIntentional? Suppress this finding
Sometimes a flag is deliberate β a genuinely public endpoint, say. You can dismiss vpc-default-security-group-rules-present and the reason is kept in the report, not silently hidden.
In .cdk-insights.json:
{
"ignoreRules": [
{ "id": "vpc-default-security-group-rules-present", "reason": "Why this is intentional" }
]
}Or inline in your CDK code:
Validations.of(scope).acknowledge({
id: 'cdk-insights::vpc-default-security-group-rules-present',
reason: 'Why this is intentional',
});Use the rule ID vpc-default-security-group-rules-present shown above β not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs β
Catch this in your stack
$ npx cdk-insights scanCDK Insights runs this and 136+ other rules locally against your synthesised CDK app β free, no account, your code never leaves your machine.