How do you implement a default-deny NetworkPolicy?
IntermediateConceptKubernetes Security
Answer
By default every pod can reach every other pod. A policy with an empty podSelector selects all pods in the namespace; listing both policy types with no rules denies everything.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata: { name: default-deny, namespace: shop }
spec:
podSelector: {}
policyTypes: ["Ingress", "Egress"]
Then add allow policies per flow, and remember to allow egress to CoreDNS on UDP and TCP 53, or every name lookup fails.
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