Skip to content

Lesson 8 of 13 · 10m

Egress Is the Exfiltration Path

The 169.254.169.254 metadata endpoint, DNS exfiltration, ipBlock except, and workload identity as blast-radius control.

Exfiltration needs one open port

Ingress rules get the attention; egress is where breaches leave. A compromised pod that can open outbound TCP 443 — or worse, UDP 53 — can move data out over HTTPS, DNS tunneling, or a paste site. Default clusters allow all of it. Every egress rule you don't write is a channel a hostile workload gets for free.

Three egress paths matter, in order of how often they're exploited:

Cloud instance metadata. 169.254.169.254 — the link-local IMDS endpoint — is reachable from pods on most managed clusters. On AWS it serves the node's IAM role credentials to anything that asks. A pod that can reach it owns whatever the node role owns: S3, SSM, whatever's attached. Cryptojacking campaigns (TeamTNT's cloud variants did this systematically) harvest IMDS creds from compromised pods as their standard first move, because pod→IMDS is a one-request privilege escalation into the cloud account.

Two real fixes. Block it at the CNI — NetworkPolicy has no deny primitive, so the portable shape is an egress allow of 0.0.0.0/0 with except: [169.254.169.254/32] on the ipBlock, or a CNI-specific deny rule where your plugin offers one. Enforcement caveat: pod-interface CNIs police this fine, but verify your plugin actually applies ipBlock egress. And require IMDSv2 with hop limit 1 on the instances. The mechanism is worth understanding: IMDSv2 mints session tokens via a PUT whose IP TTL is set to the configured hop limit; a pod's request reaches IMDS through the node's NAT — one hop — so a limit of 1 decrements the packet's TTL to zero in flight and the token response dies before it reaches the container. The node itself can still authenticate; pods can't. AWS's own container guidance recommends hop limit 1 on EKS node groups.

DNS exfiltration. When everything else is blocked, kubectl can still resolve names — and resolution is egress. Data encoded in subdomains of a domain the attacker controls resolves through CoreDNS and out. If your egress policy allows port 53 anywhere, it allows exfil anywhere. Restrict DNS egress to the cluster's own DNS pods only, and enable CoreDNS's log plugin in the Corefile — a pod suddenly resolving thousands of unique subdomains under an unfamiliar zone is exfil wearing a resolver costume, and it's visible in query logs.

Unrestricted internet egress. The miner download, the C2 callback, the S3 PUT to an attacker's bucket — all need open 443. This is also where ipBlock's except earns its keep: 0.0.0.0/0 except [cluster and VPC CIDRs] is "internet allowed, cluster internals denied," which is the right default for a frontend and the wrong default for a batch processor that should never see the internet at all. The except clause is load-bearing — cluster-internal traffic doesn't traverse public IPs, and forgetting your pod/service CIDRs in the exception list kills peer traffic under a rule meant to only reach outward.

Where workload identity reduces the blast radius

If pods can't reach the metadata endpoint, they can't steal node creds. If workloads use IRSA/Workload Identity instead of the node role, there are no node creds worth stealing. Egress policy and workload identity are the same control wearing different clothes: both decide "what can this workload's stolen identity buy?"

For regulated egress — "only these source IPs may hit our partner API" — egress gateways (Cilium Egress Gateway, Calico egress gateways) pin specific nodes' IPs as the outbound source, giving external firewalls something stable to allow-list.

What to actually do

Deny-all egress, allow DNS to cluster DNS only, allow-list real destinations — and where a rule must reach the internet, carve 169.254.169.254/32 out of the broad ipBlock with except. Require IMDSv2 hop-limit 1 on node groups. Log CoreDNS queries. A pod that can't phone home is a pod that can only sit there — which is exactly the shape you want a compromised pod to have.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.