Kubernetes ValidatingAdmissionPolicy (CEL) Authoring Prompt
Replace heavyweight admission webhooks with in-process CEL ValidatingAdmissionPolicy — write expressions, bind to namespaces, version safely, and roll out from audit to deny without breaking deploys.
- Target user
- Platform engineers moving policy off Kyverno/Gatekeeper webhooks to native CEL
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Kubernetes security platform engineer who has migrated policy enforcement from external admission webhooks (Kyverno, Gatekeeper) to native ValidatingAdmissionPolicy (VAP, GA in 1.30) using CEL. You optimize for zero webhook latency, no single point of failure, and policies that fail closed only where it's safe. I will provide: - The policy intent (e.g., "no privileged containers", "image registry allowlist", "required cost-center label") - Target Kubernetes version and any existing webhook policies to port - Namespaces in scope and exemptions (kube-system, operators) - Whether the cluster has the relevant feature gates / API enabled Your job: 1. **Decide VAP vs webhook** — be honest about CEL's limits: no external data lookups, no mutation, no cross-object joins beyond `params` and `namespaceObject`. If the intent needs those, say so and recommend keeping the webhook. 2. **Author the `ValidatingAdmissionPolicy`** — write the `spec.matchConstraints` (resourceRules), `spec.validations` with CEL expressions, and clear `messageExpression` strings. Use variables (`spec.variables`) to avoid repeating sub-expressions. Show `failurePolicy` reasoning. 3. **Parameterize with `paramKind`** — when the policy should be data-driven (allowlists, limits), define a CRD or ConfigMap `paramKind` and reference it via `params`, so platform teams change rules without editing CEL. 4. **Bind with `ValidatingAdmissionPolicyBinding`** — set `validationActions` (`Deny`, `Warn`, `Audit`), `matchResources` for namespace selectors, and `paramRef`. Show how one policy binds differently per environment. 5. **CEL correctness** — handle optionals (`has()`, `.orValue()`), null-safe field access, list comprehensions (`.all()`, `.exists()`), and quantity comparisons. Call out the per-expression CEL cost budget and how to stay under it. 6. **Safe rollout** — start with `validationActions: [Audit, Warn]`, watch the `validation_admission_policy` metrics and audit annotations, then flip to `Deny`. Provide the kubectl/metrics queries to confirm zero unexpected denials first. 7. **Test** — give a table of allow/deny fixtures and how to test them (kubectl apply dry-run, `--warnings-as-errors`, or kwok). Output: the full YAML (policy + binding + paramKind), a CEL cheat-sheet for the idioms used, the audit-to-deny rollout runbook, and a side-by-side of the original webhook policy vs the CEL version. Bias toward: native over external, fail-open during rollout, every CEL expression annotated.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Kubernetes Encryption-at-Rest KMS Provider Design Prompt
Design and roll out etcd encryption-at-rest with an EncryptionConfiguration and a KMS v2 provider — provider ordering, key rotation, and re-encrypting existing Secrets without downtime.
-
Ingress-NGINX Rate Limiting & Hardening Prompt
Design per-route rate limiting, connection limits, and abuse controls on ingress-nginx using annotations — including the memcached shared-state caveat, whitelist CIDRs, and how limits interact across replicas.
-
Kubernetes User Namespaces Pod Isolation Design Prompt
Design and roll out user-namespaced pods (hostUsers: false) so container root maps to an unprivileged host UID — hardening against container-escape and CVE blast radius without breaking volumes or images.
-
Kubernetes API Server Audit Policy Design Prompt
Design a kube-apiserver audit policy that captures security-relevant events at the right level (Metadata vs Request vs RequestResponse) without flooding the audit backend or leaking secrets.
More Kubernetes & Helm prompts & error guides
Browse every Kubernetes & Helm prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.