How it works
The explanation, with examples you can run.
Side by side
| Security group | Network ACL | |
|---|---|---|
| Attached to | Network interfaces (per resource) | Subnets |
| Rules | Allow only | Allow and deny, numbered |
| Evaluation | All rules considered together | Lowest number first; the first match wins |
| Return traffic | Allowed automatically (stateful) | Needs its own rule (stateless) |
| Default | New groups: no inbound, all outbound | Default NACL: allow everything both ways |
Security groups, in practice
alb-sg inbound 443 from 0.0.0.0/0, ::/0app-sg inbound 8080 from alb-sgdb-sg inbound 5432 from app-sgEach tier only admits the tier in front of it, by security group reference rather than by IP range. When the app scales from 3 to 30 tasks, nothing changes: anything with app-sg attached may reach the database, and nothing else may. A resource can have several groups; their rules add up.
Things that catch people out:
- Because groups only allow, you cannot block a single bad address with one. That is a job for a NACL or AWS WAF.
- Changing rules affects existing connections differently depending on tracking; the safest assumption is that removing a rule may not cut a connection that is already open.
- Groups are per VPC. A default group exists in every VPC; avoid using it, so permissions stay explicit.
- Opening
0.0.0.0/0on SSH, RDP or a database port is the most common finding in any security review. Use Systems Manager Session Manager instead of open SSH.
Network ACLs, when you need them
The default NACL allows all traffic, and many teams never change it. Custom NACLs are useful as a coarse, subnet-wide backstop: deny a range at the edge of a data subnet, or meet a rule that requires explicit deny lists. Because they are stateless, an inbound allow for port 443 also needs an outbound allow for the ephemeral ports the replies go to, and an outbound call to an API needs an inbound allow for its replies. Forgetting that produces connections that open and then hang, which looks like an application problem.
The AWS guidance is to rely on security groups for fine-grained control and use NACLs sparingly for stateless, coarse rules.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.