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
fromentry are ANDed, separate entries are ORed.namespaceSelectorandpodSelectorin 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.
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