Admission policies and webhooks
Mutation versus validation
A mutating admission step can adjust an object, for example by supplying an approved default label. Validation examines the resulting request and may reject it. Mutation must be safe to repeat and should not rely on a particular ordering among webhooks. A validating step is appropriate for a rule that must hold after mutations. Neither step proves a workload is healthy.
authorized request → mutation phase → validation phase → accepted objectA declarative CEL policy
ValidatingAdmissionPolicy uses CEL to express checks inside the API server. The stable v1 API is available from Kubernetes 1.30. This policy checks that Pod create/update requests carry a nonempty owner label; it does not verify who owns the application or whether the label is truthful. The has and membership checks guard missing values. The object is illustrative and never applied here.
apiVersion: admissionregistration.k8s.io/v1kind: ValidatingAdmissionPolicymetadata: name: book-owner.example.invalidspec: failurePolicy: Fail matchConstraints: resourceRules: - apiGroups: - '' apiVersions: - v1 operations: - CREATE - UPDATE resources: - pods scope: Namespaced validations: - expression: has(object.metadata.labels) && 'owner' in object.metadata.labels && object.metadata.labels['owner'] != '' message: A nonempty owner label is required.Bindings select scope and action
A policy definition alone does not activate a rule for requests. A binding connects it to matched requests and selects actions. This binding limits its scope to explicitly labelled namespaces and selects Warn and Audit for review. Deny can block a violating request; Deny and Warn cannot be combined in one binding. The namespace label must be governed by authorized administrators.
apiVersion: admissionregistration.k8s.io/v1kind: ValidatingAdmissionPolicyBindingmetadata: name: book-owner-audit.example.invalidspec: policyName: book-owner.example.invalid validationActions: - Warn - Audit matchResources: namespaceSelector: matchLabels: bytemind.example.invalid/policy-lab: 'true'Failures are not denials
A webhook is an external admission endpoint. A valid response that denies a request is a policy decision. A timeout or unreachable endpoint is an invocation failure; failurePolicy determines whether that failure rejects the request or is ignored. For a CEL policy, failurePolicy governs evaluation/configuration failures, while binding actions determine how enforced failures are handled. Do not use Ignore as a blanket way to weaken a security gate.
explicit deny + Ignore → still deniedwebhook timeout + Fail → rejectedwebhook timeout + Ignore → continue to remaining checksOperating a policy safely
Use small scope, short measured timeouts, appropriate TLS trust, and monitoring of admission latency and errors. Plan availability and recovery before introducing a webhook. Gatekeeper and Kyverno are optional policy systems with distinct APIs and release compatibility; neither is required for this CEL example. Verify their exact versions and behavior before adopting them.
review → warn/audit → remediate → test → authorized enforcement → monitorRead evidence, not just status codes
A synthetic API rejection with an owner-label message points to a validation rule, not missing RBAC by itself. A timeout points to admission dependency health. An accepted object can still fail at scheduling or runtime. Compare the policy, binding and fictional request outcomes. Do not change real policies or bypass admission to troubleshoot.
request ID: fixture-34result: rejectedreason: required owner label absentnext action: correct the workload metadataCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Admission policies and webhooks — knowledge check
Interpret synthetic workload security evidence.
Which mechanism can alter an admission object?
What activates the example CEL policy for matching requests?
Which actions cannot coexist in one VAP binding?
A webhook explicitly denies a request. Does failurePolicy Ignore override it?
What should be done first with a new rule?