EC2 instance uses the default security group

Separate EC2 security groups by purpose and allow only the network access each workload needs.

Description

An EC2 instance in the default group shares network permissions with its other members. The initial rules permit inbound traffic from group members and outbound traffic to all destinations. Check the rules currently deployed.

Potential impact

A change intended for one instance can open ports on unrelated services that share its group.

Remediation

Define a dedicated group for the instance’s role and restrict its peers and ports. Check all attached groups together. Review the CloudFormation change set before updating the instance, then test the required connections before removing shared rules.

Examples

Use a suitable AMI. SecurityGroups expects group names in the default VPC, and changing this property requires instance replacement. In other VPCs, use SecurityGroupIds with group IDs.

Before

yaml
Resources:
  MyEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-79fd7eee
      SecurityGroups:
        - !Ref default

!Ref default must refer to a defined value that resolves to the default group name.

After

yaml
Resources:
  MyEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-79fd7eee
      SecurityGroups:
        - !Ref AppServerSecurityGroup

!Ref AppServerSecurityGroup must resolve to the dedicated group’s name. Its actual rules determine what traffic the instance accepts.

References