SecurityPart 3: Cloud and infrastructure security
Chapter 11Network defense and zero trust
In 2013 attackers logged into Target's network with credentials stolen from a heating contractor, then walked from the vendor portal to the payment terminals and took about 40 million card numbers. The network trusted them because they were inside; you will learn to build networks where being inside earns nothing, and to prove it with mutual TLS.
After this chapter you can
- Explain why the perimeter model fails and what segmentation and microsegmentation fix
- Configure stateful firewalls and cloud security groups that reference identities instead of IP ranges
- Describe how an IDS or IPS such as Suricata inspects traffic, and where encryption blinds it
- Apply the NIST SP 800-207 zero trust model with mTLS, service meshes and identity-aware proxies
- Compare VPN and ZTNA, and outline defenses for DNS abuse and DDoS
The perimeter model and why it failed
The classic design is a castle with a moat: a hard firewall at the edge and a soft, flat interior where every machine can reach every other. It made sense when users, servers and data all sat in one building. That world is gone, and the design has three structural flaws.
- One breach reaches everything. Phishing one laptop, or stealing one vendor's VPN credentials, puts the attacker on the trusted side. From there, lateral movement (hopping from host to host) is limited only by what the flat network allows.
- The edge is itself a target. VPN concentrators and firewalls are internet-facing appliances with full internal access. Ivanti Connect Secure (CVE-2023-46805 and CVE-2024-21887, exploited in early 2024) is one of many edge-device bugs that handed attackers a foothold inside.
- The edge no longer exists. Users work from home, workloads run in several clouds, and SaaS holds the data. "Inside the network" stopped meaning "trustworthy" long ago.
Segmentation and microsegmentation
Segmentation splits a network into zones with controlled paths between them, so a compromise in one zone does not automatically reach the others. Traditional segmentation uses VLANs and subnets with firewalls between them. Microsegmentation takes this down to the individual workload: each service may talk only to the specific services it needs, on specific ports.
| Approach | Unit of control | Enforced by | Weakness |
|---|---|---|---|
| Flat network | None | Edge firewall only | Any foothold reaches everything |
| Zone segmentation | Subnet or VLAN | Internal firewalls, routing | Large zones, rules keyed on IP ranges |
| Microsegmentation | Workload or service | Host firewalls, security groups, Kubernetes NetworkPolicy, service mesh | Needs an accurate map of who talks to whom |
The hard part of microsegmentation is not the enforcement technology. It is knowing the legitimate flows. Most teams start in monitor mode with flow logs (VPC Flow Logs, a mesh's telemetry), build the dependency map, and only then switch to default deny.
Firewalls and security groups
A stateful firewall tracks connections. Once it allows an outbound request, it automatically allows the matching reply, so rules describe who may start a conversation. A stateless filter checks every packet on its own, so you must write rules for both directions.
| Control | Stateful? | Scope | Notes |
|---|---|---|---|
| AWS security group | Yes | Network interface | Allow rules only; can reference other security groups |
| AWS network ACL | No | Subnet | Allow and deny, evaluated in rule-number order |
| Azure network security group | Yes | Subnet or interface | Priority-ordered allow and deny rules |
| GCP VPC firewall rules | Yes | VPC, targeted by tag or service account | Can target service accounts instead of IPs |
| Linux nftables or iptables | Either | Host | The building block under most container networking |
The most useful feature in that table is referencing identity instead of addresses. An AWS security group rule can say "allow port 5432 from members of the app-tier group", which keeps working as instances scale and change IPs.
aws ec2 authorize-security-group-ingress \
--group-id sg-0db1111111111111 \
--protocol tcp --port 5432 \
--source-group sg-0app222222222222Intrusion detection and prevention with Suricata
An IDS (intrusion detection system) watches a copy of the traffic and raises alerts. An IPS (intrusion prevention system) sits inline and can drop packets. Suricata, an open-source engine from the Open Information Security Foundation, does both, and also writes rich protocol logs (HTTP, DNS, TLS, flows) as JSON in its eve.json file.
Rules match on protocol fields, not just raw bytes. This one alerts when an HTTP request URI tries to read /etc/passwd:
alert http any any -> $HOME_NET any (msg:"Path traversal to /etc/passwd"; flow:to_server,established; http.uri; content:"/etc/passwd"; nocase; classtype:web-application-attack; sid:1000001; rev:1;)IDS (passive)
- Fed by a SPAN port, network tap or cloud traffic mirroring
- Cannot break production traffic
- Alerts arrive after the packet is delivered
IPS (inline)
- Sits in the traffic path
- Can block in real time
- A bad rule or an overloaded sensor drops legitimate traffic
Most traffic is now encrypted, which blinds payload rules. Network sensors still see metadata: who talked to whom, how much, DNS queries, the TLS server name and client fingerprints such as JA3 or JA4. That metadata is often enough to spot command-and-control beacons or data exfiltration, and it feeds the pipeline described in Logging and telemetry.
Zero trust principles from NIST SP 800-207
Zero trust is an architecture where no implicit trust is granted based on network location, and every access request is authenticated, authorized and encrypted. NIST SP 800-207, published in 2020, is the reference definition, and it reduces to a few tenets:
- Every data source and service is a resource to protect, wherever it runs.
- All communication is secured, regardless of network location.
- Access is granted per session, with least privilege.
- Access is decided by dynamic policy: identity, device health, behavior and environment.
- The enterprise monitors the integrity and posture of all assets, and keeps collecting data to improve policy.
The architecture separates the decision from the enforcement:
The policy enforcement point can be a reverse proxy, a service mesh sidecar or a ZTNA connector. The important property is that it sits in front of every resource and asks for a decision on every session. Google's BeyondCorp program, started after the 2009 Operation Aurora intrusions, was the first large deployment of this idea.
Mutual TLS, service meshes and identity-aware proxies
In ordinary TLS only the server proves its identity with a certificate. In mutual TLS (mTLS) the client presents a certificate too, and the server rejects the connection if it cannot verify it. Each side then knows exactly which workload is on the other end, cryptographically, before any application data flows.
Doing this by hand for hundreds of services means issuing, rotating and revoking thousands of certificates. A service mesh (Istio, Linkerd) automates it. Each workload gets a short-lived certificate encoding a SPIFFE ID such as spiffe://cluster.local/ns/shop/sa/web, and a proxy next to the app handles the handshake. Policy can then say "only web may call payments", independent of IP addresses.
For human users, an identity-aware proxy plays the same role in front of internal web apps. Google Cloud IAP, Cloudflare Access and the open-source Pomerium and oauth2-proxy authenticate the user with SSO, check device and group membership, and forward only authorized requests.
VPN
- Authenticates once, then joins you to a network
- Broad network-level access after login
- Concentrator is an internet-facing target
ZTNA
- Authenticates and authorizes per application
- User sees only the apps they are allowed
- Apps stay dark: connectors dial out, no inbound port
DNS security and DDoS basics
DNS is both infrastructure you must protect and a channel attackers abuse. The main threats and controls:
| Threat | What happens | Control |
|---|---|---|
| Spoofing and cache poisoning | Resolver accepts a forged answer | DNSSEC signing and validation |
| Eavesdropping on queries | Network observers see every lookup | DNS over TLS (port 853) or DNS over HTTPS |
| Malware lookups and C2 | Infected hosts resolve attacker domains | Protective DNS or response policy zones that block known-bad domains |
| DNS tunneling | Data is exfiltrated in long, random subdomains | Query length and entropy analytics |
| Subdomain takeover | A CNAME points at a deleted cloud resource someone else can claim | Inventory DNS records and remove dangling ones |
Note that DNSSEC gives integrity, not confidentiality. Encrypted DNS gives confidentiality, but it also hides queries from your own monitoring unless you run the resolver.
A DDoS (distributed denial of service) attack exhausts a resource with traffic from many sources. The defense depends on which resource is targeted:
- Volumetric floods fill your bandwidth, often via reflection: spoofed requests to open DNS, NTP or memcached servers that send large replies to the victim. Only a provider with more capacity than the attacker can absorb them, typically an anycast CDN or cloud DDoS service. Record attacks are measured in tens of terabits per second.
- Protocol attacks exhaust connection state, such as SYN floods. SYN cookies and stateful edge proxies handle them.
- Application attacks send expensive but valid-looking requests. HTTP/2 Rapid Reset (CVE-2023-44487) abused stream cancellation to reach hundreds of millions of requests per second. Rate limits, caching, WAF rules and autoscaling are the defenses.
Key terms
- Lateral movement
- Moving from an initially compromised host to other systems inside the same environment.
- Microsegmentation
- Restricting network access per workload so each service can reach only the services it needs.
- Stateful firewall
- A firewall that tracks connections and automatically allows replies to permitted traffic.
- IDS and IPS
- Systems that inspect traffic for attacks; an IDS alerts on a copy, an IPS sits inline and can block.
- Zero trust
- An architecture that grants no trust based on network location and authorizes every session by identity and policy.
- Policy enforcement point
- The component in front of a resource that allows or blocks a session based on a policy decision.
- Mutual TLS
- TLS in which both client and server present and verify certificates.
- SPIFFE ID
- A URI that names a workload's identity, carried in its certificate, used by service meshes for authorization.
- ZTNA
- Zero trust network access: per-application, identity-checked access that replaces broad VPN connectivity.
- Reflection attack
- A DDoS technique that sends spoofed requests to third-party servers so their larger replies flood the victim.
Build a segmented network with mutual TLS
Goal: build a two-network Docker environment where the API is unreachable from the front network, and where even a client inside the back network is rejected unless it holds a certificate signed by your CA.
You need: Docker with Docker Compose v2, and OpenSSL 3 (preinstalled on most Linux distributions; on macOS run brew install openssl and use the Homebrew binary, because the system LibreSSL lacks some options used here). Everything runs locally against containers you build.
- Create a private CA, a server certificate for
apiand a client certificate forweb.
mkdir -p mtls-lab/certs && cd mtls-lab/certs
openssl req -x509 -newkey rsa:2048 -nodes -days 30 -subj "/CN=lab-ca" \
-keyout ca.key -out ca.crt
printf "subjectAltName=DNS:api\nextendedKeyUsage=serverAuth\n" > api.ext
printf "extendedKeyUsage=clientAuth\n" > web.ext
for n in api web; do
openssl req -newkey rsa:2048 -nodes -subj "/CN=$n" -keyout $n.key -out $n.csr
openssl x509 -req -in $n.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-days 30 -extfile $n.ext -out $n.crt
done
chmod 644 *.key # lab only: lets the non-root curl container read keys
cd ..- Configure nginx to require and verify client certificates.
events {}
http {
server {
listen 8443 ssl;
ssl_certificate /certs/api.crt;
ssl_certificate_key /certs/api.key;
ssl_client_certificate /certs/ca.crt;
ssl_verify_client on;
location / {
default_type text/plain;
return 200 "hello $ssl_client_s_dn\n";
}
}
}- Define the two networks and four services.
internal: truegivesbacknetno route to the outside world.
services:
api:
image: nginx:stable-alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./certs:/certs:ro
networks: [backnet]
web:
image: curlimages/curl:latest
command: ["sleep", "infinity"]
volumes: ["./certs:/certs:ro"]
networks: [frontnet, backnet]
intruder:
image: curlimages/curl:latest
command: ["sleep", "infinity"]
volumes: ["./certs/ca.crt:/certs/ca.crt:ro"]
networks: [backnet]
outsider:
image: curlimages/curl:latest
command: ["sleep", "infinity"]
networks: [frontnet]
networks:
frontnet: {}
backnet:
internal: truedocker compose up -d
docker compose ps # four services, all running- The authorized client succeeds and the server sees its identity.
docker compose exec web curl -s --cacert /certs/ca.crt \
--cert /certs/web.crt --key /certs/web.key https://api:8443/
# hello CN=web- A client inside the same segment without a certificate is rejected.
docker compose exec intruder curl -s --cacert /certs/ca.crt https://api:8443/ \
| grep -o "No required SSL certificate was sent"
# No required SSL certificate was sent (nginx answers 400 and serves no content)- A client in the other segment cannot even find the API, and the back network has no internet egress.
docker compose exec outsider curl -s -m 3 https://api:8443/; echo "exit=$?"
# exit=6 (could not resolve host: api is not on frontnet)
docker compose exec intruder curl -s -m 3 https://example.com; echo "exit=$?"
# non-zero exit: backnet is internal onlyCheck your work: step 4 prints hello CN=web, step 5 prints the nginx "No required SSL certificate was sent" message, and step 6 shows a resolve failure from outsider. You have demonstrated segmentation (network reachability) and zero trust (identity required even inside the segment) as separate layers. Push the folder to a public repo with a README that explains each check, but leave the certs directory out of Git.
Stretch: generate a second CA and a client certificate signed by it, mount it into intruder, and confirm nginx rejects it with a certificate verification error. Then add authorization on top of authentication: use an nginx map on $ssl_client_s_dn so only CN=web gets a 200 and any other valid certificate gets a 403.
Check yourself
An attacker phishes a developer and gets a shell on their laptop, which is connected to the corporate VPN. In which design does this foothold give them the least?
Why is referencing a source security group better than referencing a CIDR range when allowing database access from an application tier?
A Suricata sensor detects almost nothing after the company moves all internal traffic to TLS. What can it still usefully inspect without decrypting?
In the lab, the intruder container is on the same network as the API but is still rejected. Which property does that demonstrate?
Recap
- The perimeter model treats network location as trust, so one stolen credential or edge-device bug reaches everything.
- Segmentation limits blast radius, and microsegmentation keyed on workload identity limits it further.
- IDS and IPS sensors such as Suricata remain valuable for metadata even when payloads are encrypted.
- Zero trust, as NIST SP 800-207 defines it, authenticates and authorizes every session through a policy enforcement point.
- mTLS and service meshes give workloads verifiable identities, and identity-aware proxies and ZTNA do the same for users.
- DNS and DDoS defenses depend on knowing which layer is attacked: integrity, privacy, bandwidth, state or application.
Go deeper
- NIST SP 800-207, Zero Trust Architecture: the reference definition of tenets and components.
- CISA Zero Trust Maturity Model: a staged roadmap across identity, devices, networks, applications and data.
- BeyondCorp: A New Approach to Enterprise Security: Google's original paper on removing the privileged network.
- Suricata documentation: rule writing, eve.json logging and IPS deployment modes.
- Istio security concepts: how a service mesh issues identities, enforces mTLS and applies authorization policy.