Write Kyverno validate rules using CEL expressions instead of pattern-based or Rego validation

domain: security/compliance · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Ensure you are running a Kyverno version that supports CEL-based validate rules; check the changelog for the version that introduced cel in validate rules.
  2. In the validate rule, use the validate.cel block instead of validate.pattern or validate.deny; write CEL expressions that evaluate to true when the resource is compliant.
  3. Use CEL's object model to traverse the admission request object (e.g., object.spec.containers.all(c, has(c.resources))) and return a bool from each expression.
  4. Add a message field alongside each expression so admission denials include a human-readable explanation.
  5. Test CEL rules with the Kyverno CLI (kyverno test) by providing resource manifests and verifying expected pass/fail outcomes.

Known gotchas

Related routes

Author a Kyverno ClusterPolicy with a validate rule and set validationFailureAction to Enforce to block non-compliant resources
security/compliance · 5 steps · unrated
Write a ValidatingAdmissionPolicy using CEL expressions to enforce resource limits
kubernetes.io · 5 steps · unrated
Write a Kyverno PolicyException to exempt a specific workload from a validate policy rule without modifying the policy itself
security/compliance · 5 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans