Guardrails That Stop It
- Policy-as-Code: All admission rules are managed in Git and reconciled via Flux.
- Fail-Closed Baseline: Critical security policies are set to
Enforceby default in Production. - Audit-First Rollout: New policies always start in
Auditmode to prevent accidental downtime. - Explicit Exceptions: Policy bypasses require a documented, time-bound label or annotation.
Kyverno vs. Gatekeeper
In this course, we use Kyverno as our policy engine because it is:
- Kubernetes Native: Policies are written in YAML, not a specialized language like Rego.
- Mutation Capable: It can automatically inject sidecars or fix small label errors.
- Image Aware: Built-in support for verifying signatures and attestations (Chapter 15).
Rollout Strategy
- Develop Audit: Apply the policy in
Auditmode in thedevelopnamespace. - Evidence Collection: Review
PolicyReportsto identify existing violations. - Upstream Fix: Correct the manifests in Git to comply with the new rules.
- Production Enforce: Move the policy to
Enforcemode once all environments are clean.
Safe Workflow (Step-by-Step)
- Define Policy: Create a Kyverno
ClusterPolicymanifest in YAML. - Local Validate: Test the policy against your manifests using the Kyverno CLI.
- Deploy Audit: Use Flux to deploy the policy in
validationFailureAction: Audit. - Monitor Reports: Use
kubectl get polrto check for violations. - Enforce: Change the action to
Enforceand verify that non-compliant requests are blocked.
This builds on: Supply chain verification (Chapter 15) — Kyverno enforces what supply chain verified. This enables: Rollback and migrations (Chapter 17) — policies guard schema changes too.