Appearance

Request lifecycle and admission

Follow a Kubernetes write through identity, authorization, admission, and storage.

What you will understand

  • Identify which part of the request path rejects a bad credential, missing grant, or invalid object.
  • Explain where admission mutation and validation change the outcome.
  • Use a lab policy binding to see how authorization and admission answer different questions.

Builds on: Release configuration and safe delivery

Where the API can reject a write

A deployer submits a Deployment in a team namespace. The deployer has permission to create Deployments, but the request omits the label required for ownership. Kubernetes evaluates the request through several gates. Authentication establishes the caller’s identity. Authorization evaluates the operation, resource, and namespace for that identity. Admission acts on the proposed change after those checks. The API server also validates the object and, for an accepted ordinary write, persists the result to storage. Controllers learn about it and work on it afterwards.

A bad credential can yield an authentication error. A correctly identified identity may get a forbidden response from authorization. A permitted writer can get a denial from admission. Identify the gate using the API’s status and message. In the scene, try the same Deployment with different callers and labels.

What must pass before the API stores a write?

A client write needs a trusted identity, permission for the operation, and an object that passes admission and validation.

  1. Deployment clientPresent a credential
    AuthenticationThe API server establishes the caller’s identity.
  2. Authenticated requestCheck the requested action
    AuthorizationThis caller may create Deployments in the target namespace.
  3. Authorized objectRun admission and validation
    API serverThe proposal satisfies the policies and schema that apply.
  4. API serverPersist the accepted write
    StorageThe Deployment record exists and controllers can observe it.
Follow the sequence

A client write needs a trusted identity, permission for the operation, and an object that passes admission and validation.

Decoding, conversion, defaulting and detailed validation stages are summarized; this is the security decision sequence for a write.

Add and validate a required team label

Mutating admission can change an incoming object. A webhook might add labels or defaults before validating admission checks what would be written. A ValidatingAdmissionPolicy uses CEL, the Common Expression Language, for in-process validation. It needs a matching binding to apply. In the example, the policy checks for the team label on a Deployment’s own metadata during create or update. The Deny binding applies in namespaces labeled training-policy=enabled. A team label only on the Pod template does not satisfy that expression.

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: kv-team-label
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
      - apiGroups: [apps]
        apiVersions: [v1]
        operations: [CREATE, UPDATE]
        resources: [deployments]
  validations:
    - expression: "has(object.metadata.labels) && 'team' in object.metadata.labels"
      message: "metadata.labels.team is required"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
  name: kv-team-label
spec:
  policyName: kv-team-label
  validationActions: [Deny]
  matchResources:
    namespaceSelector:
      matchLabels:
        training-policy: enabled

A mutating hook changes the object before validation

A binding makes a matching CEL policy active. The validator evaluates the proposal that would actually be stored.

  1. Mutate the proposal

    A selected mutating webhook supplies a missing label. It must tolerate reinvocation and avoid irreversible side effects.

  2. Match a policy binding

    The binding selects namespaces and requests Deny action; the policy expression checks the resulting object.

  3. Evaluate the object after mutation

    The required label now exists, so validation accepts the write. CEL evaluation does not require a separate webhook service.

One optional mutator is illustrated; real clusters may have multiple admission plugins and selected webhook reinvocation.

Explore another case

Test authorization and admission separately

Save the manifest as team-policy.yaml. Use a disposable kind-kv-lab cluster and an authorized account before applying the cluster-scoped objects. Label only the target training namespace for the policy. Run kubectl auth can-i to check the verb. Then submit a Deployment with and without the label using server-side dry run. The dry run exercises admission without storing the Deployment, subject to admission support. When finished, remove the binding and policy using the cleanup commands.

kubectl --context kind-kv-lab apply -f team-policy.yaml
# An authorization check does not execute this admission policy.
kubectl --context kind-kv-lab auth can-i create deployments -n kv-lab
# Clean up the optional cluster-scoped objects explicitly.
kubectl --context kind-kv-lab delete validatingadmissionpolicybinding kv-team-label
kubectl --context kind-kv-lab delete validatingadmissionpolicy kv-team-label

The API mechanics lab provides a disposable baseline and exercises for distinguishing API decisions from controller progress.

Plan for admission failures

A webhook runs in the critical path of affected requests. Its timeout and availability matter. A webhook’s failurePolicy controls how invocation errors such as timeouts are handled. An explicit denial from a successfully called webhook still rejects the request. Keep matching scopes tight and decide how operators can recover if admission blocks an important change.

Check your understanding

kubectl auth can-i says yes, but your Deployment without a team label is rejected. Which check actually rejected it?

Authorization allowed that identity to create a Deployment. Admission then evaluated the proposed object and found it lacked a required label. The response message and a labeled dry-run request help show the difference.

Go to the source

Reviewed 2026-10-27 · Kubernetes 1.37 · Related local exercise

Search the book

Search loads when you open it.

Keyboard shortcuts

Ctrl + K / ⌘ + K
Search the book
?
Open this guide
Tab / Shift + Tab
Move between controls
Enter / Space
Activate a focused button or disclosure
← / →
Focused visual timeline · previous or next step
Home / End
Focused visual timeline · first or last point
Esc
Close the open dialog or menu