Post

Adding Offline Cilium Egress Audit to the CI Gate

Adding Offline Cilium Egress Audit to the CI Gate

My homelab now runs an offline audit that flags broad or ambiguous destination shapes in Cilium egress policies before they reach the cluster. The new audit script and its unittest companion run as part of the static offline-checks pipeline, so a policy with a world destination or a rule missing an explicit grant fails the CI gate instead of surfacing at runtime.

Flagging broad destinations in Cilium egress policies

I added scripts/cilium-egress-audit.py, which reads JSON policy snapshots and reports findings for CiliumNetworkPolicy and CiliumClusterwideNetworkPolicy resources. It treats an empty egress rule as Cilium default deny, flags rules with no explicit peer destination, rejects broad entity destinations such as all, world, cluster, cluster-mesh, and unmanaged, and scans endpoint and node selectors for positive match label or match expression operators that would widen the grant. The script reports findings to stderr and exits nonzero when any finding exists, making it suitable as a gate.

Running the audit as an offline CI test

I added scripts/ci/cilium-egress-audit-test.py, a unittest module that builds temporary JSON snapshots and invokes the audit script against them. Tests cover an empty default-deny rule passing, a ports-only rule failing with no explicit destination, cluster-mesh failing as a broad destination, and reserved world labels failing. The test file is registered in scripts/ci/offline-checks.sh so it runs alongside the other static checks. These are unit tests that exercise the audit logic in isolation; they are not runtime results from a live Cilium deployment.

Verification status and the next live check

The code is merged and the offline tests exist, but I have not yet run the audit against actual Cilium policy snapshots exported from the homelab cluster. The next check is to export real egress policies, run the audit against them, and confirm no false positives block legitimate traffic before treating the CI gate as enforced.

Where this pre-merge audit pattern transfers

A platform team can use the same technique for any admission-control or network-policy review: extract the risky shapes into a small offline script, add focused unit tests with synthetic snapshots, and gate the check in CI before policies are applied. This works well when the risk is structural—broad destinations, missing selectors, or wildcard entities—because the check needs no cluster credentials and can run on pull requests.

This post is licensed under CC BY 4.0 by the author.