Interview Prep/DevSecOps/Kubernetes Security

What are the common NetworkPolicy gotchas?

AdvancedConceptKubernetes Security
Answer
  • The CNI must enforce it. Flannel alone ignores NetworkPolicy; Calico, Cilium and the AWS VPC CNI (with network policy enabled) enforce it.
  • Selectors in one from entry are ANDed, separate entries are ORed. namespaceSelector and podSelector in the same list item means "these pods in those namespaces"; as two items it means "any pod in those namespaces, or these pods in my namespace".
  • Policies are additive allow lists. There is no deny rule in the core API; use Cilium or Calico policies, or AdminNetworkPolicy, for cluster-wide denies.
  • No L7 and no FQDN rules in the core API.
  • hostNetwork pods are not governed.

Test with a throwaway pod (kubectl run tmp --rm -it --image=busybox -- wget -qO- http://svc) rather than trusting the YAML.

All DevSecOps questions Roadmap: Supply chain, secrets & identity

More on Kubernetes Security