Kubernetes ValidatingAdmissionPolicy: Roll Out CEL Guardrails Without Surprises

Kubernetes admission control is a useful place to stop unsafe objects before they become stored cluster state. A ValidatingAdmissionPolicy lets operators express checks in CEL and bind them to selected API requests. It can catch configuration mistakes at the API boundary, such as a workload missing an approved label or selecting a disallowed service account. It does not inspect a running container's behavior, replace network controls, or make a cluster safe by itself.

The central rollout problem is balancing enforcement with reliability. A policy that rejects every workload missing a label may be technically correct but can interrupt a release pipeline or a controller that was not included in testing. Start by choosing a narrow invariant, identifying every writer that creates the relevant object, and collecting evidence before enforcing it cluster-wide.

Choose controls with a clear owner

Technical Architecture: Choose controls with a clear owner
Figure: Technical Architecture: Choose controls with a clear owner

Use admission validation for properties that can be checked from the submitted object and that should remain true regardless of which user or automation created it. Examples include requiring a team label on Deployments, limiting a field to an approved set, or preventing a service from enabling a risky option. Keep rules small and explain the operational reason in the policy message. If the rule cannot be described precisely, it will be difficult to test and maintain.

Kubernetes already provides Pod Security Admission and the Pod Security Standards for common pod security profiles. Prefer those built-in controls when they cover the requirement. A custom CEL policy is appropriate for organization-specific conventions or constraints not represented by a built-in mechanism. Avoid re-implementing a broad policy catalog in dozens of overlapping expressions; duplicated rules drift and produce confusing rejection messages.

Write a policy and binding in stages

The policy defines the resource match and validation expressions. A binding selects the namespaces or objects to which the policy applies and decides what happens when validation fails. In a controlled test cluster, begin with the API version supported by the target Kubernetes releases, and verify that the validating admission policy feature is available and enabled for those releases. Do not assume that all managed Kubernetes services expose identical versions or features.

Use kubectl explain validatingadmissionpolicy and the cluster's OpenAPI schema to confirm field names for the target version. Apply the policy first with an audit or warning action where practical, then inspect actual violations. A binding should target the intended namespaces and resource kinds; an overly broad match can affect operators, system add-ons, and third-party controllers. Document exclusions explicitly and review them as part of the policy's ownership record.

A policy's parameter reference can change evaluation behavior. Kubernetes documents parameterNotFoundAction; a binding configured to allow missing parameters can unintentionally fail open when the parameter object is absent. Where a parameter is required for the control, choose a deny behavior that matches the desired failure policy, restrict who can change the parameter resource, and monitor for its deletion. Test both present and missing parameter cases.

Test the policy like production code

Create positive and negative fixtures for each expression. A positive fixture should satisfy the policy, while a negative fixture should violate one rule at a time so the rejection message is understandable. Test omitted fields, null values, unexpected types, empty lists, and objects created by the actual controllers used in the cluster. CEL expressions need careful optional-field handling; a property that is absent must not cause an ambiguous evaluation result.

Use server-side dry run for object-level checks where supported, and apply test objects to a non-production cluster with the same API version. Server-side dry run checks admission without persisting the object, but it can still invoke configured admission components. Ensure test accounts have only the permissions needed for the exercise. Test updates as well as creates, because an object may be safe at creation and later changed into a noncompliant state.

Example review sequence:

  1. Record the Kubernetes version, admission feature availability, policy owner, and exact resource scope.
  2. Validate the policy schema with kubectl apply --dry-run=server -f policy.yaml in a representative test cluster.
  3. Apply the policy and binding in audit or warning mode if supported by the cluster's API version.
  4. Exercise one compliant and several intentionally noncompliant objects in a test namespace.
  5. Review audit events and application delivery logs for violations from humans, CI jobs, operators, and controllers.
  6. Set enforcement for a pilot namespace, monitor deployments, then expand in controlled stages.

Decide what happens when validation fails

The failure policy governs evaluation errors, not ordinary validation failures. A fail-closed approach improves enforcement when the policy is available, but may reduce API availability if evaluation cannot complete. A fail-open approach favors availability but can permit an object when validation errors occur. Choose based on the risk of the field, the cluster's reliability requirements, and the team's ability to detect and respond to evaluation failures.

Define an exception process with a ticket, owner, reason, expiry, and compensating control. Prefer a narrow namespace or parameter exception over weakening a global rule. Avoid blanket exemptions for an entire platform namespace unless there is evidence that all objects there need them. Review exceptions on a schedule and remove them when the associated software is fixed.

Operate and maintain guardrails

Alert on policy evaluation failures separately from user violations. A spike in denied objects can be a malicious attempt, but more often it may indicate a rollout or template change. Dashboards should identify the policy, namespace, resource, principal, and request time without logging secrets or full sensitive object payloads. Keep policy source in version control with code review, test fixtures, and a rollback manifest.

Re-run tests when upgrading Kubernetes, changing controllers, or modifying a policy. A policy that once matched a field correctly may stop doing so after API behavior or resource schemas change. Record the supported cluster versions and retire policies that duplicate a built-in control. Admission is one layer: combine it with least-privilege RBAC, Pod Security Admission, network policy, image trust, secrets management, and runtime monitoring.

Safe-testing and maintenance note

Test only in clusters you own or are authorized to administer. Use a non-production namespace and avoid policies that could lock out cluster operators or critical controllers. This guide provides rollout patterns, not a guarantee that a given expression fits every Kubernetes version. Last updated: 2026-11-09. Change log: Initial publication; validation workflow checked against current Kubernetes references.

References