VPC Security
Security Groups and Network ACLs
1. Two Layers of VPC Firewall
Amazon VPC provides two firewall options to control traffic: security groups and network access control lists (network ACLs). They operate at different levels and have different behaviors.
2. Security Groups
A security group acts as a virtual firewall at the instance level. Each instance in a subnet can be assigned to a different set of security groups. Security groups control both inbound and outbound traffic.
Default Behavior
- Default security group denies all inbound traffic.
- Default security group allows all outbound traffic.
- You can specify allow rules only — no deny rules.
- All rules are evaluated before the decision to allow traffic.
Stateful
Security groups are stateful. If you send a request from your instance, the response traffic is automatically allowed back in regardless of inbound rules. Responses to allowed inbound traffic are automatically allowed out.
Example Rules
| Direction | Protocol | Port | Source/Destination | Purpose |
|---|---|---|---|---|
| Inbound | TCP | 80 | 0.0.0.0/0 | Allow HTTP from anywhere |
| Inbound | TCP | 443 | 0.0.0.0/0 | Allow HTTPS from anywhere |
| Inbound | TCP | 22 | 192.0.2.0/24 | Allow SSH from corporate network |
| Outbound | TCP | 1433 | sg-database | Allow SQL Server to database security group |
Rules can reference other security groups as sources or destinations — a powerful feature for layered security.
3. Network ACLs
A network ACL is an optional firewall that operates at the subnet level. It controls traffic entering and leaving one or more subnets.
Default Behavior
- Default network ACL allows all inbound and outbound IPv4 traffic.
- Custom network ACLs deny all traffic until you add rules.
- You can specify both allow and deny rules.
- Rules are evaluated in number order (lowest number first).
Stateless
Network ACLs are stateless. Return traffic must be explicitly allowed by outbound rules. If you allow inbound traffic on port 80, you must also add an outbound rule for the response.
4. Side-by-Side Comparison
| Attribute | Security Group | Network ACL |
|---|---|---|
| Scope | Instance level | Subnet level |
| Supported rules | Allow rules only | Allow and deny rules |
| State | Stateful (return traffic auto-allowed) | Stateless (return traffic needs explicit rule) |
| Rule evaluation | All rules evaluated together | Rules evaluated in number order (lowest first) |
| Default behavior | Deny inbound, allow all outbound | Default NACL: allow all. Custom NACL: deny all. |
| Association | Multiple per instance | One per subnet; one NACL can serve many subnets |
5. Quick Quiz
Test Your Understanding
Select one answer per question. You will receive immediate feedback.