Every cloud server has a little help desk at a fixed address, 169.254.169.254, that answers questions like "who am I?" and "give me my keys". A pod living on that server can walk up to the same desk. If nothing stops it, a broken pod can ask for the server's keys and then act as the server in your whole cloud account.
The address every attacker tries first
On a cloud VM, http://169.254.169.254 is the instance metadata service: it hands out the instance id, user data and - the prize - temporary credentials of the node's IAM role. A pod can reach it too, so one compromised pod can act as the node in your cloud account.
Block it with an egress NetworkPolicy that allows everything except that address:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: deny-metadata
namespace: apps
spec:
podSelector: {} # every pod in the namespace
policyTypes: [Egress]
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 169.254.169.254/32
After it, the request times out; everything else still works. Per-pod cloud identities are the real fix: each pod's service account gets its own cloud role, so pods never need the node's role at all. (simulator) a minimal metadata service answers the lab pods.
Later (Ch 29, Ch 35): on Azure that is workload identity; on AWS, IRSA or EKS Pod Identity (AWS II).
On the exam: domain "Cluster setup": "restrict access to node metadata with a NetworkPolicy".
Why it helps
Stealing the node's cloud credentials from the metadata endpoint is one of the first things an attacker tries after getting into a pod, and it turns a container problem into a cloud-account problem. A single egress NetworkPolicy closes it per namespace, and the CKS exam lists exactly this task under cluster setup. Per-pod cloud identities are the long-term fix. Test the block from a pod afterwards.
FAQ
What does the metadata endpoint give out?
The instance id, user data, network details and, most importantly, temporary credentials for the node's IAM role at /latest/meta-data/iam/security-credentials/. Those credentials can do whatever the node's role is allowed to do in the cloud account.
How does a NetworkPolicy block it?
With an egress rule that allows 0.0.0.0/0 except 169.254.169.254/32 for the pods it selects. Once any egress policy selects a pod, only what the policy allows is permitted, so the metadata address is the one thing left out.
Why not simply deny all egress?
Because the application usually needs to reach databases, APIs or DNS. The except clause removes only the metadata address and keeps everything else working, so the policy can be rolled out to busy namespaces without breaking them.
What does the blocked request look like from the pod?
It times out instead of answering: wget reports that the download timed out. That is the proof you check in the lab, testing the block from inside the pod the same way an attacker would try it.
What is the better long-term fix?
Per-pod cloud identities: the cloud gives each pod's service account its own role, with only what that app needs, so pods never need the node's role. Then the node's role can stay minimal, and the NetworkPolicy becomes a second layer.
In an interview Mid
How do you stop pods from stealing the node's cloud credentials?
Block the instance metadata endpoint at http://169.254.169.254 with an egress NetworkPolicy: podSelector {}, policyTypes Egress, one rule allowing 0.0.0.0/0 except 169.254.169.254/32. Then test from inside a pod that the request times out. Longer term, give pods their own cloud identity (IRSA, Pod Identity, workload identity) so the node role can stay minimal.
Also asked: What does the metadata endpoint hand out? · Why use except instead of denying all egress? · How do per-pod cloud identities change the risk?