Sub topic 9
The default security group and its defaults
This chapter assumes you know how allow-only, stateful rules work and how a rule can name another security group as its source. It builds on those ideas to explain the group that AWS creates for you in every VPC.
What the default group is
Every VPC has a security group named default. AWS creates it with the VPC, and you cannot delete it. You can change its rules, but you cannot rename it.
The group applies automatically. If you launch an instance, or create another resource with a network interface, and name no security group, AWS attaches the default group of that VPC. Because of this, the default group often ends up on resources whose owners never chose it.
The default rules
The default group ships with these rules:
| Direction | Protocol and ports | Source or destination | Effect |
|---|---|---|---|
| Inbound | All | The default group itself | Members can reach each other on any port |
| Outbound | All | 0.0.0.0/0 | Members can start connections to anywhere |
The inbound rule uses a security group reference, and the group references itself. Traffic is allowed only if it comes from a network interface that also has the default group attached. Traffic from the internet, or from instances in other groups, matches no inbound rule and is dropped by the implicit deny.
Why the defaults need attention
The self-referencing rule is permissive. Any two resources that carry the default group can talk on every port. That is a problem in three ways:
- A resource can get the group by accident, because it is attached when you specify nothing.
- Membership grants broad access. A database and a public web server that both carry the default group can reach each other on all ports.
- Tiered designs lose their meaning. If every tier also carries the default group, the narrow rules you wrote for each tier no longer limit anything.
For these reasons, a common practice is to leave the default group unused. Strip its rules so that an accidental attachment grants nothing, and create named groups for real workloads.
Emptying the default group
First find the group and read its rules:
aws ec2 describe-security-groups \
--filters Name=vpc-id,Values=vpc-0123456789abcdef0 Name=group-name,Values=defaultThen revoke the two default rules. Replace the group ID with the one from the output. The inbound rule is removed by naming the group itself as the source.
aws ec2 revoke-security-group-ingress \
--group-id sg-0bbbbbbbbbbbbbbbb \
--protocol -1 \
--source-group sg-0bbbbbbbbbbbbbbbb
aws ec2 revoke-security-group-egress \
--group-id sg-0bbbbbbbbbbbbbbbb \
--protocol -1 \
--cidr 0.0.0.0/0The protocol value -1 means all protocols and all ports. The describe output may also show an outbound IPv6 rule if your VPC has an IPv6 range. Revoke it the same way, with the matching ::/0 range.
Common mistakes
- Assuming a new group behaves like the default. A group you create has no inbound rules and allows all outbound traffic. It does not get the self-referencing rule.
- Expecting to delete it. Deleting the default group fails. Emptying it is the supported alternative.
- Treating "same group" as "same subnet". The self-reference depends on group membership, not on subnet or IP range. Two instances in different subnets can still talk if both carry the group.
- Forgetting that the default is per VPC. Each VPC has its own default group, and a group ID from one VPC cannot be used in another.
Exercise
You launch an EC2 instance in a VPC without choosing a security group, and a second instance in the same VPC with a new group named app-sg that has no inbound rules. From the first instance, can you open a connection to the second on port 8080? Can the second reach the first? Explain.
Show answer
The first instance carries the default group. The second instance's app-sg has no inbound rules, so it drops the connection to port 8080 even though the first instance's outbound rule allows it. The second instance can reach the first only if the traffic matches an inbound rule on the default group. Its source would have to be the default group, but app-sg is a different group, so the self-referencing rule does not match and the connection is dropped.