A pentest shows any pod can reach any other pod, including the database. What do you implement?
BeginnerScenarioKubernetes Security
Answer
Situation read → Kubernetes networking is flat by default. NetworkPolicies need a CNI that enforces them (Calico, Cilium, or VPC CNI with network policy enabled).
What I'd do →
- Confirm enforcement support in the CNI.
- Apply default deny in each namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: default-deny, namespace: orders }
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
- Add allow rules: ingress controller to frontend, frontend to API, API to DB on 5432, and DNS egress to kube-dns on 53.
- Test with a temporary pod and
nc -zv.
Why → Default deny turns lateral movement from trivial into hard.
Interview tip → Forgetting DNS egress is the classic mistake; mention it.
More on Kubernetes Security
What are the 4Cs of cloud native security?BeginnerWhat happens to a request between `kubectl apply` and etcd from a security point of view?IntermediateExplain Role, ClusterRole, RoleBinding and ClusterRoleBinding.BeginnerHow do you check what a user or service account is allowed to do?BeginnerWhich RBAC permissions are effectively cluster-admin in disguise?AdvancedHow do service account tokens work now, and what is `automountServiceAccountToken`?Intermediate