✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes ValidatingAdmissionPolicy Management

Kubernetes ValidatingAdmissionPolicy Management ensures policy enforcement during admission, validating resources before they are created or updated in a cluster.

Kubernetes ValidatingAdmissionPolicy Management is the practice of authoring and operating ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding objects, a built-in, in-process alternative to webhook-based validation that expresses policy logic using the Common Expression Language (CEL) directly within the API server, avoiding the network call, external service dependency, and associated latency of a validating webhook.


Why ValidatingAdmissionPolicy Exists

Removing the External Service Dependency

Traditional validating admission relies on an external webhook service reachable over the network, introducing latency, a TLS trust relationship, and an availability dependency into the request path; ValidatingAdmissionPolicy evaluates CEL expressions in-process within the API server itself, eliminating that network round trip and the operational burden of running and securing a separate webhook service for many common policy checks.

CEL as the Policy Language

Common Expression Language provides a constrained, safe expression syntax for evaluating conditions against the submitted object, making it suitable for embedding directly in cluster configuration without the security concerns of running arbitrary external code inline with every admission request.


Defining a Policy

ValidatingAdmissionPolicy Structure

A ValidatingAdmissionPolicy declares the resources it matches, one or more CEL validations expressions evaluated against the object, and the failure message returned when a validation fails.

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: require-resource-limits
spec:
  matchConstraints:
    resourceRules:
    - apiGroups: [""]
      apiVersions: ["v1"]
      operations: ["CREATE", "UPDATE"]
      resources: ["pods"]
  validations:
  - expression: >
      object.spec.containers.all(c, has(c.resources.limits) &&
      has(c.resources.limits.memory))
    message: "every container must specify a memory limit"

Binding the Policy

A ValidatingAdmissionPolicy has no effect until a ValidatingAdmissionPolicyBinding attaches it to a specific enforcement action and scope, separating the reusable policy definition from where and how strictly it is applied.

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: require-resource-limits-binding
spec:
  policyName: require-resource-limits
  validationActions: ["Deny"]
  matchResources:
    namespaceSelector:
      matchLabels:
        environment: production

Enforcement Actions

Deny, Warn, and Audit

validationActions on a binding determines the behavior when a validation fails: Deny rejects the request outright, Warn allows it while returning a warning to the client, and Audit allows it while annotating the audit log — mirroring the same staged-rollout pattern available for Pod Security Standards, but applicable to arbitrary custom CEL logic.

spec:
  validationActions: ["Warn", "Audit"]

Combining Multiple Actions

Multiple actions can be set on the same binding simultaneously, allowing a policy to both warn the calling client and record an audit entry without blocking, useful during the observation period before committing to Deny enforcement.


Parameter Resources

Externalizing Configuration From Policy Logic

A ValidatingAdmissionPolicy can reference a paramKind — a custom resource supplying configurable parameters — allowing the same policy definition to be reused with different thresholds or allowed values across different bindings, rather than hardcoding specific values directly into the CEL expression.

spec:
  paramKind:
    apiVersion: policy.example.com/v1
    kind: ResourceLimitParams

Operational Advantages Over Webhooks

No TLS or Service Availability to Manage

Because the CEL expression runs directly within the API server process, there is no certificate to rotate, no external service to keep available, and no network timeout to tune — removing an entire category of operational failure modes that affect webhook-based validation.

Lower Latency

Evaluating a CEL expression in-process is materially faster than a network round trip to an external webhook service, which matters for clusters with high API request volume where cumulative webhook latency across many registered webhooks becomes a measurable factor in overall API responsiveness.


Limitations and When Webhooks Are Still Needed

Expressiveness Boundaries

CEL is intentionally constrained and cannot perform arbitrary external lookups, call other services, or execute logic beyond what the expression language and available object fields support; policies requiring integration with an external system (a vulnerability database, an approval workflow) still require a traditional webhook.

Choosing Between the Two Mechanisms

ValidatingAdmissionPolicy is well suited to self-contained structural and configuration checks against the submitted object itself, while validating webhooks remain necessary for policies that depend on external state or systems — many clusters use both together, reserving webhooks for the cases that genuinely require them.