open atlas
↑ Back to track
Security Foundations SECF · 04 · 03

Segmentation and firewalls

One compromised web box should not reach your database, your secrets store, and your CI runner. Segmentation, firewalls, security groups, and microsegmentation are how you bound that blast radius — and where flat networks quietly fail.

SECF Middle ◷ 15 min
Level
FoundationsJuniorMiddleSenior

An attacker pops one of your web servers through a vulnerable image-upload endpoint. On a flat network that single foothold is the whole game: from that box they can open a TCP connection to the database on 5432, to the internal admin panel on 8080, to the secrets sidecar, to the CI runner that holds a deploy token, and to every other service in the VPC — because nothing between them ever said no. The web box never needed to talk to the CI runner, but the network let it, so the attacker inherits everything the web box can reach. The breach was one host; the loss was the data center. Segmentation is the discipline that makes those two numbers different.

By the end of this lesson you’ll be able to bound the blast radius of a compromised host by drawing zone boundaries and enforcing them with firewalls, security groups, and microsegmentation.

Blast radius: the number segmentation actually moves

Start from the assumption a senior never drops: something will be compromised. A dependency CVE, a leaked credential, an SSRF that pivots inward — eventually one host is the attacker’s. The only question left is how far that foothold reaches. That reachable surface is the blast radius, and it is the metric segmentation exists to shrink.

A flat network — one big subnet, every host able to dial every other host on any port — maximizes blast radius by construction. Compromise of any single node equals reachability to all of them. This is exactly the structure that turns a contained web-tier bug into a lateral-movement spree: the 2013 Target breach famously began with credentials stolen from an HVAC vendor and reached the point-of-sale network because the segments that should have separated vendor access from card-processing systems weren’t enforced. The lesson generalizes: lateral movement is only possible across paths the network permits, so the defense is to permit fewer paths.

Segmentation slices that flat space into zones with controlled crossings. A classic three-tier cut is web / app / data: the web tier accepts traffic from the internet on 443, the app tier accepts traffic only from the web tier, and the data tier accepts traffic only from the app tier. Now a compromised web box can reach the app tier on one port — not the database, not the secrets store, not CI. The attacker has to find a second vulnerability at each border to keep moving, and every border is a place you get to detect and stop them.

The enforcement layers: firewalls, security groups, microsegmentation

A zone boundary is only as real as the thing enforcing it. Three layers do the work, at three different granularities.

A network firewall sits at a subnet or perimeter boundary and filters traffic by 5-tuple (source IP, destination IP, source port, destination port, protocol). The non-negotiable posture is default-deny: the ruleset starts by dropping everything, and you explicitly allow only the flows the architecture requires. A default-allow firewall with a few block rules is a sieve — it fails open the moment a new service appears that nobody wrote a block rule for. Default-deny fails closed: a flow nobody allowed simply doesn’t happen.

Security groups (the cloud’s native primitive — AWS, GCP, Azure all have an equivalent) push that filter down to the instance and make it identity-based instead of IP-based. Instead of “allow 10.0.2.0/24 → 5432,” you write “allow the app-sg source group → the db-sg on 5432.” The rule references roles, not addresses, so it survives autoscaling and IP churn, and it is stateful: you allow the inbound request and the response is permitted automatically. Security groups are deny-by-default by nature — an instance with no inbound rule accepts nothing.

Microsegmentation takes it to the limit: policy per workload, often per service or pod, enforced regardless of where it runs. In Kubernetes this is a NetworkPolicy (or a service-mesh authorization policy) that says pods labeled app=checkout may receive traffic only from pods labeled app=gateway on 8080 — and the default in a namespace with any policy is deny all else. This is the structural core of zero trust (NIST SP 800-207): the network location of a request grants it nothing; every flow is authorized on its own identity. Microsegmentation is what shrinks east-west blast radius from “the whole namespace” to “the one neighbor this service legitimately talks to.”

LayerGranularitySelectorBounds which blast radius
Network firewallSubnet / perimeter5-tuple (IP, port, proto)North-south, zone-to-zone
Security groupInstanceSource group / identityTier-to-tier, survives IP churn
MicrosegmentationWorkload / podLabel / service identityEast-west, pod-to-pod

Defense in depth, and where segmentation stops helping

Segmentation is one layer of defense in depth, not the whole defense. It controls who can reach whom; it does not validate what they send once allowed. If the app tier is permitted to query the database and the app has a SQL injection flaw, the firewall waves the malicious query straight through — the 5-tuple is on the allowlist. So segmentation must be paired with controls at the next layer in (parameterized queries, authn/authz on the service, input validation) and the layer above (WAF, TLS). The point of depth is that no single control failing should be game over.

Two honest costs keep this from being free. Operational drag: fine-grained policy is a lot of rules, and rules drift — a stale allow nobody removed becomes the exact path the attacker uses. The discipline is to treat policy as code, review it, and audit for unused allows. The failure mode of doing it badly: over-segment without good observability and you get mystery outages where a legitimate flow is silently dropped, the team can’t tell a misconfiguration from an attack, and — worst of all — under pressure someone “fixes” it by adding an allow all rule that quietly re-flattens the network you spent a quarter segmenting.

Why this works

Why prefer identity-based security groups over IP-based firewall rules in the cloud? Because IPs are ephemeral there. Autoscaling, spot reclamation, and rolling deploys recycle instances constantly, so an IP-pinned rule (allow 10.0.2.37 → 5432) is either wrong within the hour or so broad (allow 10.0.2.0/24) that it re-creates a flat zone inside the “segmented” one. Referencing a source security group binds the rule to a role, not an address, so it stays correct as instances come and go — and it reads as intent (“app may reach db”) instead of a CIDR puzzle a future engineer has to reverse-engineer.

Reading a policy like a senior

When you review a segmentation design, you’re really asking two questions. First, is it default-deny? If the baseline is allow-with-exceptions, the design is already lost — find the implicit any-any rule and you’ve found the whole network’s true reachability. Second, what does a single compromise reach? Pick the most exposed node (the internet-facing tier), assume it’s owned, and trace every flow it’s allowed to make. That set is your blast radius. If it includes the database, the secrets store, or CI, you have lateral-movement paths to cut.

Pick the best fit

Your three-tier app runs in a cloud VPC with autoscaling on every tier. You need the app tier to reach the database on 5432 and nothing else to. Pick the rule that bounds blast radius best.

Quiz

A firewall is configured default-allow with a handful of explicit block rules. Why is this the wrong posture for a zone boundary?

Quiz

Your Kubernetes namespace has a NetworkPolicy allowing `app=gateway` → `app=checkout` on 8080. The checkout pod has a remote-code-execution bug and is compromised. What does microsegmentation buy you here?

Order the steps

Order these enforcement scopes from broadest (coarsest segmentation) to narrowest (finest), as you'd layer them in defense in depth:

  1. 1 Perimeter firewall — north-south, subnet/zone boundary, 5-tuple
  2. 2 Security group — tier-to-tier, instance-level, identity-based
  3. 3 Microsegmentation / NetworkPolicy — east-west, per-workload, label-based
Recall before you leave
  1. 01
    Explain blast radius, why a flat network maximizes it, and how a three-tier segmentation shrinks it.
  2. 02
    Compare network firewalls, security groups, and microsegmentation, and explain why each is default-deny and why identity-based rules beat IP-based ones in the cloud.
Recap

Segmentation starts from the senior assumption that some host will be compromised, and its job is to bound the blast radius — the set of systems that foothold can reach. A flat network maximizes blast radius because every host can dial every other; cutting the network into web/app/data zones with controlled crossings means a compromised web box reaches one port into the app tier, not the database, secrets store, or CI. Boundaries are enforced at three granularities, all default-deny: network firewalls filter north-south by 5-tuple at the perimeter, security groups push an identity-based, stateful filter to the instance (the right primitive in a cloud where IPs churn), and microsegmentation applies per-workload policy pod-to-pod — the structural core of zero trust, where location grants no trust. Segmentation is one layer of defense in depth: it controls who can reach whom, not what they send once allowed, so it must be paired with app-level controls, and its real costs are policy drift and outages from over-segmenting without observability. When you read a design, ask two things: is it default-deny, and what does a single compromise actually reach?

Practice

Start at the top. Tasks go easiest → hardest: recall a fact, apply it to a case, then a senior-level stretch. Open one, attempt it, then reveal.

recallapplystretch0 of 6 done
Connected lessons

Something unclear?

Ask a question about this lesson. Questions are anonymous and go straight to the author to make the lesson better.

Apply this

Put this lesson to work on a real build.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.