A Kubernetes admission rule exempts one username, yet still blocks that user's Deployment — why?
answer
- the exemption matched the wrong request
- identity is per-request, not per-intent
- the Pod's requester is a controller
- exempting that account exempts the cluster
- pod-template metadata is what propagates
basics
~20 sBecause the exemption is checked against the requester, and the request that gets blocked is the Pod create — made by the ReplicaSet controller's service account, not by the person. The human's name only ever appears on the Deployment request.
solid answer
~40 sAn exemption keyed on the requester survives exactly one hop. The Deployment create carries the human in the request's user information, so the exemption matches there. The Pod create, seconds later, is made by `system:serviceaccount:kube-system:replicaset-controller`, so the exemption cannot match and the Pod is rejected. Nothing on the Pod names the person. The tempting fix — exempt the ReplicaSet controller's service account — is far worse than the problem, because nearly every Pod in the cluster is created by that account, so it silently disables the rule everywhere. Key the exemption on something that actually travels: the namespace, or a label or annotation on the workload's **pod template**, which the controller copies onto the Pod. An annotation on the Deployment's own metadata does not propagate and will not help.
code
json · 14 lines{
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"request": {
"operation": "CREATE",
"kind": { "group": "", "version": "v1", "kind": "Pod" },
"namespace": "payments",
"userInfo": {
"username": "system:serviceaccount:kube-system:replicaset-controller",
"groups": ["system:serviceaccounts", "system:serviceaccounts:kube-system", "system:authenticated"]
},
"object": { "metadata": { "generateName": "checkout-7d9f8b6c5-" }, "spec": {} }
}
}go deeper
Remember that the identity in an admission request is whoever made that specific call. For a Pod created behind a Deployment, that is a control-plane controller, not the engineer who deployed.
Explain that user-based conditions only work on the request the human submits, and that what reaches the Pod is whatever the pod template carries — template metadata, not the workload's own metadata.
Show that you spot the failure mode in the obvious repair: exempting the controller's account disables the rule cluster-wide while still reporting green. Offer namespace or pod-template scoping instead.
Own the governance question: an exemption anyone can grant themselves by editing a manifest is not an exemption process. Decide who may set the marker, what evidence it leaves, and when it expires.
## Identity does not survive the controller hop The admission request carries who made *that* request. When you apply a Deployment, that is you. When the ReplicaSet controller subsequently creates a Pod, the requester on that request is `system:serviceaccount:kube-system:replicaset-controller`, with the groups any service account carries — `system:serviceaccounts`, `system:serviceaccounts:kube-system` and `system:authenticated`. The person is gone. There is no field anywhere in the Pod's admission payload that names them, and the payload carries no other object you could consult to find out. So any rule clause of the form "skip this check when the requester is X" only works at the hop where X is the requester. Applied to a Pod-level rule, an exemption for a human never fires. ## Why exempting the controller is the wrong repair The first instinct — "fine, exempt the ReplicaSet controller service account" — collapses the rule. Every Pod behind every Deployment in the cluster is created by that one account. Exempting it does not exempt the one team that asked; it exempts effectively the whole estate, and it does so invisibly, because the rule still exists, still evaluates, and still reports green. The same applies to broad group matches: excluding `system:serviceaccounts:kube-system` takes out the controllers that create almost all workload Pods. The general principle is worth stating plainly in an interview: **on a Pod-level rule, requester identity is a poor axis to make decisions on, because it is almost always a controller.** Requester-based logic belongs on rules that match the object the human submits. ## What does travel What reaches the Pod is what the controller copies into it — the contents of the workload's **pod template**. Labels and annotations placed under a Deployment's `spec.template.metadata` land on every Pod it produces; labels and annotations on the Deployment's own `metadata` do not. That distinction is the whole trick, and it is the thing candidates get backwards. Practical options, roughly in order of preference: - **Scope by namespace.** The Pod's namespace is on the Pod. If the exemption is really "this team's environment", a namespace scope expresses it directly, is visible in the rule, and is governed by whoever controls namespace creation. - **Scope by a pod-template label or annotation.** Workable, and it travels — but note who can set it. Anyone who can edit the Deployment can add the exemption marker to its pod template, so this is a request, not a control, unless a second rule governs who may set that marker. - **Put the exemption on the parent rule instead.** If you also run a rule against Deployments for feedback, an identity-based exemption is meaningful there, because the human really is the requester. ## The evidence problem There is an audit consequence too. If your record of "who was allowed to do this" comes from the Pod-level evaluation, every entry attributes the action to a controller. Reconstructing the human requires correlating back to the workload write in the API server's audit trail. Design the exemption so the record names a namespace, a workload, or an approval reference — something with an owner — rather than relying on an identity that was never in the request. ## How to answer this out loud Name the mechanism (identity is per-request and the Pod's requester is a controller), name the trap (exempting that controller exempts nearly everything), then give the axis that actually travels (namespace, or pod-template metadata rather than the workload's own metadata), and close on who is allowed to set it.
- Why is exempting the ReplicaSet controller's service account a dangerous fix?Because that account creates the Pods behind essentially every Deployment in the cluster. The exemption you meant for one team applies to the entire estate, and it fails open silently: the rule still exists and still reports as passing, so nobody notices the guarantee is gone until something bad ships.
- Which metadata on a Deployment actually reaches the Pod?Only what sits under `spec.template.metadata` — the pod template's own labels and annotations are copied onto the Pods the controller creates. Labels and annotations on the Deployment's top-level `metadata` stay on the Deployment. A Pod-level rule keyed on the latter never matches anything.
- Is a pod-template annotation a real control or just a convention?Just a request, unless you govern it. Anyone who can edit the workload can add the annotation, so the exemption is self-service by default. Make it a control by restricting who may set that key — for example a second rule that rejects the annotation outside approved namespaces, or by requiring an approval reference in its value.
saying these in an interview costs you the question
- Thinks the human's identity propagates down to the Pod
- Proposes exempting the controller service account
- Puts the exemption annotation on the workload's own metadata
- Expects the engine to look up who owns the Pod
- Treats a self-serve annotation as an enforced exemption