Turn on the default deny
About 953 words
The rendered manifests start with default-deny, a CiliumClusterwideNetworkPolicy that puts every pod outside spec.defaultDeny.exclude into default deny for ingress and egress. Once Cilium enforces it, a flow the catalog doesn't know about is dropped. On a cluster whose catalog isn't complete yet, that's an outage. This page gets you from rendered manifests to an enforced default deny without one.
The tool for it is Cilium's policy audit mode: Cilium evaluates every policy as usual, but instead of dropping a packet the policy doesn't allow, it lets it through and records an AUDITED verdict. You apply the manifests, read what would have been dropped, fix the catalog, and switch enforcement on when nothing is left.
1. Clear the warnings first
Open the policy's Problems in the console, or run backstage-cilium-render. Two warnings mean traffic that is in the catalog but won't be allowed, or will be allowed too widely:
consumes api:…, which doesn't run on resource:… and has no specht-labs.de/cilium-dst: not allowed: the API is outside the cluster and the catalog doesn't say where. Give it acilium-dst.reached on every port by … flows: the destination has nospecht-labs.de/cilium-ports. The flow works, but on every port. Ports and metrics fixes it.
Diagnostics lists every message.
2. Turn on audit mode
Audit mode is a setting of the Cilium agent. With Helm:
helm upgrade cilium cilium/cilium --namespace kube-system \
--reuse-values --set policyAuditMode=trueWithout Helm, set policy-audit-mode: "true" in the cilium-config ConfigMap and restart the agents:
kubectl -n kube-system patch configmap cilium-config --type merge \
--patch '{"data":{"policy-audit-mode":"true"}}'
kubectl -n kube-system rollout restart ds/ciliumIf Cilium is itself managed by your GitOps repository, change the value there instead, so the next sync doesn't undo it.
Audit mode is cluster-wide
While it's on, no network policy on the cluster drops anything, including the ones you wrote by hand before. Keep the audit period short on a cluster that already relies on policies.
3. Apply the manifests
Publish the manifests to the repository your GitOps tool applies, and merge the pull request. Cilium now evaluates default-deny and every allow-… policy, and audits instead of dropping.
4. Read the audited verdicts
Each agent's Hubble sees the verdicts of the pods on its node:
kubectl -n kube-system exec ds/cilium -c cilium-agent -- \
hubble observe flows -t policy-verdict --last 100A flow the policies don't allow shows up as AUDITED:
Feb 7 12:53:39.168: default/tiefighter:54134 (ID:31028) -> default/deathstar-6fb5694d48-5hmds:80 (ID:16530) policy-verdict:none AUDITED (TCP Flags: SYN)(The example line is from Cilium's documentation.) With Hubble Relay and the hubble CLI on your machine you can watch the whole cluster at once: hubble observe -t policy-verdict --follow.
For each audited flow, find out which catalog fact is missing, and add it:
| The flow is | Add |
|---|---|
| between two workloads the catalog has, one using the other's API | consumesApis on the consumer, providesApis on the provider |
| to a database, queue or cache with pods | dependsOn the Resource, and its cilium-ports |
| to something outside the cluster | dependsOn or consumesApis it, and a cilium-dst on it |
| from the internet, the API server or the nodes | a cilium-allow on the destination |
| from a scraper to a metrics port | cilium-metrics-ports on the endpoint and spec.metrics.scraper on the policy (Ports and metrics) |
| none of the above: a probe, an operator managing its instances | a rule entity |
| from a workload the catalog doesn't have yet | the Component or Resource, with its namespace and selector |
The source or destination often shows up as a Cilium identity rather than a pod: remote-node for an admission webhook call, host for a pod on the host network. Cilium identities you'll meet explains the usual ones.
Let audit mode run long enough to see the traffic that doesn't happen every minute: nightly backups, weekly jobs, certificate renewals.
5. Enforce
When the audited verdicts are gone, turn audit mode off the way you turned it on (policyAuditMode=false, or policy-audit-mode: "false" and a restart of the agents). From now on, Cilium drops what the catalog doesn't allow.
Smaller steps
You don't have to switch the whole cluster at once:
- Namespace by namespace. Start with a long
spec.defaultDeny.excludeand take namespaces off it one at a time. The flows of an excluded namespace are still allowed on the other end, so an enforced namespace can talk to an excluded one as soon as the catalog has the flow. - Endpoint by endpoint. Audit mode can be turned on for a single Cilium endpoint (one pod) with
cilium-dbg endpoint config <id> PolicyAuditMode=Enabledin the agent on its node. It's temporary: a restart of the agent resets it to the agent's setting.
If something breaks
Every allow-… policy sets enableDefaultDeny: false, so default-deny is the only policy that puts pods into default deny. Deleting it opens the cluster again, without touching the allows:
kubectl delete ciliumclusterwidenetworkpolicy default-denyPause your GitOps tool's sync of the manifests first, or it puts the policy back. Then fix the catalog, and let the next pull request restore default-deny.
