Q&A-2Explain and combine AWS security groups and network ACLs.
Answer
What a strong candidate says first
They are two filters at two different layers, and only one of them is stateful.
Security groups attach to an elastic network interface: an EC2 instance, an RDS instance, a Lambda ENI, a load balancer node. They are allow-only: there is no deny rule, and all rules are evaluated together as a union, so order is irrelevant. They are stateful: once a flow is permitted inbound, the response is permitted outbound automatically, and vice versa. A newly created security group denies all inbound and all outbound until you add rules. The VPC's default security group is the exception: it allows all inbound from members of itself and all outbound, and it cannot be deleted.
Network ACLs attach to a subnet, so one rule set covers every resource in it. They have both allow and deny rules, numbered 1–32766, evaluated lowest-number-first with first match winning. They are stateless: the request and the reply are evaluated independently, and the reply's destination port is an ephemeral port, not the service port. A new custom NACL denies everything until you add rules; the default NACL allows all inbound and outbound on rule 100.
Where each one earns its place
Use security groups as the primary control, scoped to the workload role, and reference other security groups as sources rather than CIDRs: a rule allowing TCP 5432 from sg-rds-clients survives an IP renumbering. Add NACLs for the two things security groups cannot do: a coarse subnet-level guardrail, and an explicit deny. Blocking a specific CIDR after a compromise is a NACL job; a security group can only fail to allow it.
| Security group | Network ACL | |
|---|---|---|
| Attaches to | ENI | Subnet |
| Rules | Allow only, unordered union | Allow and deny, numbered, first match wins |
| State | Stateful | Stateless |
| Default when new | Deny all in and out | Deny all in and out |
| VPC default | Allow all in from self, all out | Allow all in and out, rule 100 |
| Default quota | 60 in + 60 out rules; 5 SGs per ENI | 20 rules per NACL |
| Same-subnet traffic | Evaluated | Not evaluated |
That last row matters: two instances in the same subnet talk to each other without the NACL seeing the packets, so a NACL deny you added for a subnet does not isolate those two from each other.
Failure modes
Missing ephemeral return rule. NACL outbound allows TCP 443 to the server, the server subnet's NACL inbound allows TCP 443 from the client, and the connection still hangs. The SYN-ACK comes back from server port 443 to the client's ephemeral port, and the server subnet's NACL outbound has no rule for it. Client-side tcpdump shows repeated SYN with no SYN-ACK; Reachability Analyzer reports the blocking component. The ranges to allow: 1024–65535 for traffic from a NAT gateway or an ELB, 32768–60999 for a Linux client's default ip_local_port_range, 49152–65535 for Windows.
Rule order. A deny at rule 100 for 0.0.0.0/0 beats an allow at rule 200 for 10.0.2.0/24. Adding the allow at 32766 changes nothing.
Asymmetric NACLs across AZs. Subnet A's NACL allows outbound to subnet B, but subnet B's NACL has no matching inbound rule. Works one way, fails the other; the symptom is a one-directional timeout that looks like an application bug.
Default security group drift. An instance launched without an explicit security group lands in the default one, which allows all inbound from every other member of the default security group. That is lateral movement inside the VPC.
Rule quota. At 60 inbound rules per security group you start merging CIDRs; a /24 that should have been a prefix list is the usual cause.
Diagnosing
VPC Flow Logs give per-ENI ACCEPT/REJECT records with srcaddr, dstaddr, srcport, dstport: enough to see which direction stopped. Reachability Analyzer tests a path between two ENIs and names the blocking component. Neither replaces reading the NACL rule numbers in order.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.