EC2 instance uses the default security group

Review the default security group used by an EC2 instance and restrict its rules to the service requirements.

Description

An EC2 instance in the default group shares its rules with other members. Initially, the group admits connections from its own members and allows outbound traffic. Internet ingress requires a rule and a network path that permit it.

Potential impact

Instances that do not need to communicate may reach each other. Changing a shared rule affects every attached service.

Remediation

Create a group for the instance’s role with only the required peers, ports and protocols. Check the combined permissions of all attached groups and test new connections after switching. Review other workloads before removing rules from the shared group.

Examples

These excerpts use the legacy amazon.aws.ec2 module. For current playbooks, use amazon.aws.ec2_instance with its supported parameters and your own AMI, key and subnet.

Before

yaml
- name: EC2 인스턴스 생성
  amazon.aws.ec2:
    key_name: mykey
    instance_type: t2.micro
    image: ami-123456
    wait: yes
    group: default
    count: 1
    vpc_subnet_id: subnet-29e63245
    assign_public_ip: yes

group: default selects the VPC’s shared default rules.

After

yaml
- name: EC2 인스턴스 생성
  amazon.aws.ec2:
    key_name: mykey
    instance_type: t2.micro
    image: ami-123456
    wait: yes
    group: web-private-sg
    count: 1
    vpc_subnet_id: subnet-29e63245
    assign_public_ip: yes

web-private-sg selects another group whose rules are not shown. Both tasks request a public IP with assign_public_ip: yes.

References