Lesson 7 of 13 · 12m
Everything Talks Until You Say Otherwise
Allow-only NetworkPolicy semantics, the silent no-op of a non-enforcing CNI, and the default-deny skeleton with DNS.
Default state: everything reaches everything
A fresh cluster has no firewall. Every pod can open a connection to every other pod, to any node's ports the CNI path allows, to your cloud metadata endpoint, and to the entire internet. NetworkPolicy is how you change that — and the first thing to know about it is what it doesn't do: there are no deny rules. NetworkPolicies are allow-lists only, and they work by selection.
The mechanics (networking.k8s.io/v1):
kind: NetworkPolicy
spec:
podSelector: {} # every pod in this namespace
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector:
matchLabels: {app: frontend}
- namespaceSelector:
matchLabels: {team: platform}
ports: [{port: 8080}]
egress:
- to:
- ipBlock:
cidr: 0.0.0.0/0
except: [10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16]
ports: [{port: 443}]Selection semantics: once any ingress policy selects a pod, only explicitly allowed ingress sources reach it; pods selected by no policy remain default-allow. Same for egress. Entries within a from list are OR'd; combining podSelector + namespaceSelector in one item AND's them — which is also the trap: a peer item with both selectors means "pods in that namespace matching those labels," while two separate items mean "that namespace OR those labels anywhere." ipBlock with except is how you carve "the internet but not cluster IPs." ports takes numbers, named ports, and endPort ranges (1.25+).
The enforcement trap
Here is the failure that produces no error: NetworkPolicy is only enforced if your CNI implements it. Calico, Cilium, Antrea, Weave, and kube-router enforce. Plain kubenet doesn't. AWS's VPC CNI added support in 2023; older managed setups vary. If your CNI doesn't enforce policies, kubectl apply succeeds, kubectl get networkpolicy shows the object, and absolutely nothing is blocked. The cluster looks governed and isn't.
Verify before you rely on it: apply a default-deny, then kubectl exec into a pod and curl a peer. "Connection refused/timeout" means the CNI enforces; a response means it doesn't — or that your podSelector didn't select the pod you thought it did. Both failure modes are silent at apply time.
The default-deny skeleton
The working pattern, per namespace:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
spec:
podSelector: {}
policyTypes: [Ingress, Egress]Then add the two allows every namespace actually needs:
- DNS egress to the cluster DNS pods (CoreDNS in
kube-system, UDP+TCP 53). The universal post-lockdown outage is "everything resolves to nothing," and it's because DNS egress died with the rest. - Monitoring ingress from your metrics namespace, plus genuine app peers, by label selector.
egress:
- to:
- namespaceSelector:
matchLabels: {kubernetes.io/metadata.name: kube-system}
ports: [{port: 53, protocol: UDP}, {port: 53, protocol: TCP}]kubernetes.io/metadata.name is the label every namespace gets automatically — the stable selector target that doesn't depend on anyone's labeling discipline.
Note what you cannot express: "deny this specific peer." Deny-lists don't exist; you deny by not allowing. If two pods must never talk, ensure no allow rule covers their pairing rather than hunting for a deny primitive that isn't there.
One scope rule that surprises people: a NetworkPolicy selects pods in its own namespace only — podSelector can't reach across namespaces; cross-namespace peers are expressed with namespaceSelector. Cilium and Calico extend the model with their own CRDs — L7 rules, FQDN-aware toFQDNs egress policies, clusterwide policies — useful, but they're vendor surface, not the portable API.
What to actually do
Default-deny ingress and egress per namespace, re-allow DNS, then add rules per workload. Test with exec+curl, not with confidence. And if your network plugin is one of the non-enforcing kind, switching CNIs is the real fix — YAML cannot conjure enforcement the datapath doesn't implement.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
Immich Had Fourteen Advisories and One Bug It Fixed Three Times
Immich's 2026 security record runs to fourteen advisories, and they cluster hard: the sharing features, the OAuth plumbing, and one login redirect parameter that took three separate fixes across eighty-three days. Plus the 3.0 migration traps still waiting for anyone who hasn't jumped yet.
Jellyfin's Threat Model Is Your Brother-in-Law
Four Jellyfin CVEs landed in 2026 and not one of them needs an admin account. One needs only the ability to name a file. Meanwhile Jellyfin 12 shipped in September, the version numbers stopped starting with 10, and every "am I patched" check you wrote is now wrong.
Node.js Fixed 16 Flaws in One Release. Most of Them Live in HTTP/2 and TLS.
The November 11 Node.js security releases fix 16 CVEs across the 26, 24 and 22 lines, seven of them rated high. Nearly all sit in HTTP/2 and TLS, where a remote client can crash a server, leak memory, or get past per-host client-certificate checks.