Layering Both for Defense in Depth
Combine the two firewalls to reinforce your network security.
Layering Both for Defense in Depth is a free AWS Security Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Defense in Depth
Defense in depth means stacking independent controls so a failure or gap in one does not expose the workload. In a VPC, security groups and network ACLs are two such layers, joined by route tables, WAF, and Network Firewall to form overlapping barriers around your resources.
Complementary Strengths
Security groups give fine, per-resource, stateful control with allow-only rules. NACLs give coarse, subnet-wide, stateless control with both allow and deny. Using them together lets you set a broad subnet baseline while tuning each resource precisely.
Both Must Allow
For inbound traffic to reach an instance, both the NACL and the security group must permit it. A deny at either layer drops the packet. This AND logic means a restrictive NACL acts as a backstop even if an overly permissive security group is created by mistake.
Subnet Baseline with NACLs
Use NACLs to enforce subnet-level guardrails that no resource owner can override, such as denying a known malicious CIDR or blocking traffic between tiers that should never communicate. Because NACLs are coarse, keep these rules broad and stable.
Per-Resource Tuning with SGs
Use security groups for the day-to-day, least-privilege rules: open port 443 on the web tier, allow the app tier to reach the database, and reference groups instead of IPs. This is where most of your network policy lives because it is precise and stateful.
Tiered Architecture
A classic layered design places public, private-app, and private-data subnets in separate tiers. NACLs prevent the data subnet from talking directly to the internet, while security groups chain web to app to database. An attacker breaching one tier still faces both controls at the next.
Limiting Blast Radius
Layering shrinks the blast radius of a compromise. If an app server is breached, tight security groups stop it from scanning the data tier, and NACLs stop subnet-wide lateral movement. The attacker is boxed in rather than free to roam the VPC.
Verifying with Flow Logs
Confirm your layered rules actually behave by analyzing VPC Flow Logs. Reject entries reveal blocked attempts; unexpected accepts reveal gaps. Pair Flow Logs with Athena queries to audit whether traffic between tiers matches your intended design.
Avoiding Over-Reliance on NACLs
Because NACLs are stateless and limited to 20 rules per direction by default, do not try to express granular policy in them. Over-loading NACLs creates ephemeral-port headaches and rule-number sprawl. Keep them simple and let security groups carry the detail.
Beyond Layer 4
Security groups and NACLs filter on IP, port, and protocol only. To inspect HTTP content, block SQL injection, or filter by domain, you add higher layers: WAF for web requests and AWS Network Firewall for deep packet inspection, both covered later in this category.
The Whole Stack
A mature VPC layers route tables, NACLs, security groups, Network Firewall, and WAF, each catching what the others miss. The SCS-C02 exam rewards choosing the right control at the right layer and combining them rather than relying on any single one.
Quick Check
Reason about layered controls.
Recap
Defense in depth stacks NACLs and security groups so a gap in one is caught by the other. Both must allow inbound for traffic to pass, making a restrictive NACL a backstop. Use NACLs for coarse subnet guardrails and security groups for fine per-resource least privilege. Verify with Flow Logs, keep NACLs simple, and add WAF or Network Firewall for content-aware filtering.
Frequently asked questions
Is the “Layering Both for Defense in Depth” lesson free?
Yes — the full text of “Layering Both for Defense in Depth” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “Layering Both for Defense in Depth”?
Combine the two firewalls to reinforce your network security. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Layering Both for Defense in Depth” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- How Security Groups Filter Traffic
- How Network ACLs Filter Subnets
- Stateful versus Stateless Behavior
- Layering Both for Defense in Depth