NetworkPolicy in full
A default deny on ingress and egress in the shop's namespace: what breaks after it (DNS, the cluster API, traffic from outside) and how to allow exactly the paths you need.
The fourth lesson of the hardening track. The attacker in web already has no root and no useful permissions in the API, but the cluster network is still open: from web you can connect straight to the database and send data to any address on the internet. The lesson shows how to close a namespace with network policies without breaking what used to work.
Threat model
The attacker runs commands in the web Pod. They need the data, which lives in db, and a channel to carry it out.
Attack path
- A command through the vulnerable
webendpoint. - A direct TCP connection from
webto the database on 5432, bypassing theapiservice. - An HTTP request from
webto the attacker's external server with the data in the body.
Checklist
- The namespace has a policy with an empty
podSelectorthat denies both ingress and egress. - DNS is allowed to
kube-dnson UDP and TCP 53. - Egress to the cluster API is allowed to the apiserver endpoint address, not to the Service IP.
- Each service gets only its own ingress and egress, and the database connects nowhere.
- Selectors tell "and" (one element) from "or" (two elements).
Practice
A lab on the shared cluster of the track. The attack from web opens a connection to the database and sends data to the attacker's server. You write policies for shop that make both paths time out, while the shop still takes orders and the status page sees the Pods.
Done reading?
Mark the lesson as read to move your track progress forward.
Lesson marked as done.
Practice
Fix a local lab. The agent checks your work and gives hints if you get stuck.
Full access to all labs
One payment, no auto-renewal · Terms
Progress saved in this browser
Clear your history or open this on your phone, and the marks will be gone. Leave your email and they'll move to your account. No password needed.
Done. moved to your account. You can see your progress on any device. My progress