Skip to main content
HIGHEC2Security

Security Group Unrestricted Ingress

security-group-unrestricted-ingress

What this rule checks

Detects security groups with unrestricted ingress (0.0.0.0/0).

How to fix it

  1. 1Restrict ingress to specific IP ranges
  2. 2Use security group references for internal traffic
  3. 3Implement least privilege network access
FlaggedAn ingress rule opens SSH (tcp/22) to 0.0.0.0/0, producing the unrestricted-ingress and dangerous-port findings (both under this ruleId).
import * as ec2 from 'aws-cdk-lib/aws-ec2';

const vpc = new ec2.Vpc(this, 'Vpc', {
  maxAzs: 2,
  natGateways: 0,
  subnetConfiguration: [
    { name: 'isolated', subnetType: ec2.SubnetType.PRIVATE_ISOLATED, cidrMask: 24 },
  ],
});
const sg = new ec2.SecurityGroup(this, 'Sg', { vpc });
// SSH open to the whole internet.
sg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(22), 'ssh');
FixedThe group allows a single narrow ingress (private CIDR, HTTPS) and, with allowAllOutbound false, has no 0.0.0.0/0 egress and is not empty โ€” so none of the security-group finding branches fire.
import * as ec2 from 'aws-cdk-lib/aws-ec2';

const vpc = new ec2.Vpc(this, 'Vpc', {
  maxAzs: 2,
  natGateways: 0,
  subnetConfiguration: [
    { name: 'isolated', subnetType: ec2.SubnetType.PRIVATE_ISOLATED, cidrMask: 24 },
  ],
});
// allowAllOutbound:false keeps egress off 0.0.0.0/0; a single narrow
// ingress rule (private CIDR, HTTPS) is the only opening.
const sg = new ec2.SecurityGroup(this, 'Sg', {
  vpc,
  allowAllOutbound: false,
});
sg.addIngressRule(ec2.Peer.ipv4('10.0.0.0/16'), ec2.Port.tcp(443), 'internal https');

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::SecurityGroup

Compliance frameworks

SOC2HIPAAPCI-DSSCISNIST

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

Sometimes a flag is deliberate โ€” a genuinely public endpoint, say. You can dismiss security-group-unrestricted-ingress and the reason is kept in the report, not silently hidden.

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "security-group-unrestricted-ingress", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::security-group-unrestricted-ingress',
  reason: 'Why this is intentional',
});

Use the rule ID security-group-unrestricted-ingress 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 scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ€” free, no account, your code never leaves your machine.

More EC2 rules