For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-ec2-instance-using-default-security-group.md.
A documentation index is available at /llms.txt.
Attaching EC2 instances to the VPC default security group increases risk because the default group is typically shared, often permits broad intra‑VPC traffic, and cannot be tightly scoped, which facilitates lateral movement and unintended access.
This rule checks AWS::EC2::Instance resources and inspects the SecurityGroups and SecurityGroupIds properties. Any entry that references or names the default security group (case‑insensitive match for default) will be flagged. The check evaluates both literal values and Ref references, so entries containing default or pointing to a default security group resource are considered noncompliant.
Use explicit, purpose‑built security groups with restrictive ingress/egress rules and reference those group IDs or logical names instead of the default group.
Secure configuration example:
MySecurityGroup:Type:AWS::EC2::SecurityGroupProperties:GroupDescription:Web server security groupVpcId:!Ref MyVPCSecurityGroupIngress:- IpProtocol:tcpFromPort:443ToPort:443CidrIp:0.0.0.0/0MyInstance:Type:AWS::EC2::InstanceProperties:ImageId:ami-0abcdef1234567890InstanceType:t3.microSecurityGroupIds:- !Ref MySecurityGroup