- Deny images that use the floating
:latesttag. - Deny explicit replica counts outside the supported range (1–10). The
replicasfield is optional for the WebApp API, so omission remains allowed.
- A
ValidatingAdmissionPolicythat describes which resources to match and contains the CEL expressions. - A
ValidatingAdmissionPolicyBindingthat attaches the policy and selects the enforcement action. Here the enforcement action isDeny, so any failed expression blocks the write before the object is stored.
A policy without a binding is like a rule written down but not posted at the door — it won’t be enforced until it is bound.
What this policy enforces
- Image rule: prevents images that explicitly end with
:latest. The expression allows theimagefield to be omitted, or if present requires it not to end with:latest. - Replicas rule: allows omitting
replicas, or if present requires its value to be an integer between 1 and 10 inclusive.
ValidatingAdmissionPolicy
This resource matcheswebapps.webapp.kodekloud.com/v1 on CREATE and UPDATE and contains the two CEL validations shown below:
failurePolicy: Failmeans the admission request is rejected on policy evaluation errors.- The CEL
has()check lets the field be optional; only present values are evaluated against the constraint.
Ensure your cluster supports
ValidatingAdmissionPolicy resources in admissionregistration.k8s.io/v1 before applying these manifests. Cluster feature availability can vary by Kubernetes distribution and version.ValidatingAdmissionPolicyBinding
Bind the policy and set enforcement toDeny so failed validations block writes:
Apply the policy and confirm
Apply the policy and binding, then verify both exist:Test resources
Use the following example manifests to validate policy behavior.- Test: image with
:latestshould be rejected
- Test: replicas outside allowed range should be rejected
- Test: valid WebApp should be accepted
Links and references
- Kubernetes Admission Controllers
- ValidatingAdmissionPolicy API reference (admissionregistration.k8s.io)
- Common Expression Language (CEL) for Kubernetes