{"id":551,"date":"2026-11-18T06:52:00","date_gmt":"2026-11-18T14:52:00","guid":{"rendered":"https:\/\/blog.canutethegreat.com\/?p=551"},"modified":"2026-11-18T06:52:00","modified_gmt":"2026-11-18T14:52:00","slug":"kubernetes-rbac-admission-control-compromised-pod","status":"publish","type":"post","link":"https:\/\/blog.canutethegreat.com\/index.php\/2026\/11\/18\/kubernetes-rbac-admission-control-compromised-pod\/","title":{"rendered":"Kubernetes RBAC and admission control: how one compromised pod becomes a compromised cluster"},"content":{"rendered":"<p>Most Kubernetes incident write-ups I read start the same way. Somebody finds a remote code execution bug in an ordinary web app, lands in a pod, and twenty minutes later they are reading secrets from every namespace. The bug in the app was a normal bug. The part that turned it into a cluster compromise was a handful of RBAC and admission settings nobody had looked at since the cluster was stood up.<\/p>\n<p>I&#8217;ll assume you already run Kubernetes and know what a Role is.<\/p>\n<h2>What the attacker finds in the pod<\/h2>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/k8s-chain.png\" alt=\"Flowchart of the attack chain from an application bug in a pod through a service account token, an RBAC grant, a privileged pod and the node, with the control that breaks each step\" \/><\/figure>\n<p>The diagram shows the chain an attacker follows from an application bug to the node, and the control that breaks each step.<\/p>\n<p>Every pod gets a service account, and unless you say otherwise, a projected token for it is mounted at <code>\/var\/run\/secrets\/kubernetes.io\/serviceaccount\/token<\/code>. Since 1.24 that token is short-lived and bound to the pod, which is a real improvement over the old never-expiring secrets. It still works against the API server for as long as the pod lives, and the attacker lives inside the pod.<\/p>\n<p>The first thing they run is the equivalent of this:<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>kubectl auth can-i --list<\/code><\/pre>\n<p>You should run it yourself, from the outside, impersonating the service account of each workload:<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>kubectl auth can-i --list \\\n  --as=system:serviceaccount:shop:web \\\n  -n shop<\/code><\/pre>\n<p>Most web apps need no Kubernetes API access at all. If the answer is anything beyond the default discovery permissions, ask why. Then turn the token off where it isn&#8217;t needed:<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>apiVersion: v1\nkind: ServiceAccount\nmetadata:\n  name: web\n  namespace: shop\nautomountServiceAccountToken: false<\/code><\/pre>\n<p>The usual cause is a token nobody asked for and a RoleBinding inherited from a copy-pasted Helm chart.<\/p>\n<h2>RBAC verbs that are really something else<\/h2>\n<p>RBAC is purely additive. There are no deny rules, so the only way to be safe is to grant less. The documented behaviour that matters most is that the API stops you from creating or editing a Role that grants permissions you don&#8217;t hold yourself, unless you have the <code>escalate<\/code> verb on roles. The same goes for <code>bind<\/code> on creating RoleBindings. Hand those two out and you&#8217;ve handed out cluster-admin with extra steps. <code>impersonate<\/code> is the third one to grep for.<\/p>\n<p>The quieter problems are verbs that look read-only or small:<\/p>\n<ul>\n<li><code>get<\/code>, <code>list<\/code> and <code>watch<\/code> on <code>secrets<\/code> all return the secret data. A role that can <code>list<\/code> secrets in a namespace can read every secret in it. This is the one people get wrong because <code>list<\/code> sounds harmless.<\/li>\n<li><code>create<\/code> on <code>pods<\/code> in a namespace is, in practice, access to every secret and service account in that namespace. The attacker creates a pod that mounts the secret or runs as the more privileged service account. The Kubernetes docs call this out under privilege escalation via workload creation.<\/li>\n<li><code>create<\/code> on <code>pods\/exec<\/code> is a shell in any pod in scope.<\/li>\n<li>Wildcards. <code>resources: [\"*\"]<\/code> and <code>verbs: [\"*\"]<\/code> also match resources that don&#8217;t exist yet, including whatever the next CRD you install adds.<\/li>\n<\/ul>\n<p>The group <code>system:masters<\/code> bypasses RBAC entirely, so a client certificate with that group in the subject can&#8217;t be restricted by anything you write in a Role. Don&#8217;t issue those, and don&#8217;t bind <code>cluster-admin<\/code> to <code>system:authenticated<\/code>. That binding makes every authenticated identity an admin.<\/p>\n<p>A sane namespaced role for a controller that only needs to read config looks like this:<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>apiVersion: rbac.authorization.k8s.io\/v1\nkind: Role\nmetadata:\n  name: read-config\n  namespace: shop\nrules:\n  - apiGroups: [\"\"]\n    resources: [\"configmaps\"]\n    resourceNames: [\"web-config\"]\n    verbs: [\"get\", \"watch\"]<\/code><\/pre>\n<p>Note <code>resourceNames<\/code>. It narrows a grant to specific objects, and it works for <code>get<\/code> but not for <code>list<\/code> or <code>create<\/code>, since the name isn&#8217;t known at request time (with a <code>list<\/code> it only works if the request uses a field selector on <code>metadata.name<\/code>).<\/p>\n<h2>Admission is the second lock<\/h2>\n<p>RBAC decides whether you may create a pod. It says nothing about what the pod is allowed to contain. A pod with <code>privileged: true<\/code>, <code>hostPID: true<\/code> or a <code>hostPath<\/code> mount of <code>\/<\/code> is a node compromise waiting for a trigger, and from the node the attacker can read the kubelet credentials and every other pod&#8217;s tokens on that host.<\/p>\n<p>That&#8217;s what admission controllers are for. Pod Security Admission has been built in since it went stable in 1.25, replacing PodSecurityPolicy, which was removed in that release. It defines three profiles, privileged, baseline and restricted, applied per namespace through labels, in three modes: enforce, audit and warn.<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>kubectl label --overwrite ns shop \\\n  pod-security.kubernetes.io\/enforce=restricted \\\n  pod-security.kubernetes.io\/enforce-version=latest<\/code><\/pre>\n<p>Before enforcing on a namespace that already has workloads, ask the API server what would break. The documented way is a server-side dry run:<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>kubectl label --dry-run=server --overwrite ns --all \\\n  pod-security.kubernetes.io\/enforce=baseline<\/code><\/pre>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.canutethegreat.com\/wp-content\/uploads\/2026\/11\/k8s-psa-docs.png\" alt=\"Screenshot of the Kubernetes documentation page for Pod Security Admission labels, showing the enforce, audit and warn modes\" \/><\/figure>\n<p>The screenshot is the real Kubernetes documentation page for the Pod Security Admission labels, listing what enforce, audit and warn each do.<\/p>\n<p>It returns warnings listing the pods that violate the profile. I roll out <code>warn<\/code> and <code>audit<\/code> first, fix what shows up, and only then flip to <code>enforce<\/code>. Going straight to enforce on a busy namespace breaks deploys at the worst moment.<\/p>\n<p>Baseline blocks the obvious things: privileged containers, host namespaces, hostPath volumes, most added capabilities. Restricted adds non-root, no privilege escalation, a seccomp profile and dropped capabilities. It breaks a lot of off-the-shelf images, which is a useful thing to find out early.<\/p>\n<h2>When the built-in profiles aren&#8217;t enough<\/h2>\n<p>Pod Security Admission is coarse on purpose. For rules like &#8220;images only from our registry&#8221; or &#8220;no <code>hostNetwork<\/code> unless labelled&#8221;, you need a policy engine. Kyverno and OPA Gatekeeper are the established options. Since 1.30 there is also ValidatingAdmissionPolicy, which is stable and runs CEL expressions inside the API server with no webhook to keep alive. A validating webhook that is down either blocks every deploy or, with <code>failurePolicy: Ignore<\/code>, silently stops protecting you.<\/p>\n<pre tabindex=\"0\" class=\"wp-block-code\"><code>apiVersion: admissionregistration.k8s.io\/v1\nkind: ValidatingAdmissionPolicy\nmetadata:\n  name: no-host-network\nspec:\n  failurePolicy: Fail\n  matchConstraints:\n    resourceRules:\n      - apiGroups: [\"\"]\n        apiVersions: [\"v1\"]\n        operations: [\"CREATE\", \"UPDATE\"]\n        resources: [\"pods\"]\n  validations:\n    - expression: \"!has(object.spec.hostNetwork) || !object.spec.hostNetwork\"\n      message: \"hostNetwork is not allowed\"\n---\napiVersion: admissionregistration.k8s.io\/v1\nkind: ValidatingAdmissionPolicyBinding\nmetadata:\n  name: no-host-network\nspec:\n  policyName: no-host-network\n  validationActions: [\"Deny\"]<\/code><\/pre>\n<p>This matches pods directly. Deployments and Jobs create pods through their controllers, so the pod-level check still fires at that point, but the error shows up in the ReplicaSet events and not at <code>kubectl apply<\/code>, which confuses people the first time.<\/p>\n<h2>A short audit I&#8217;d run this week<\/h2>\n<p>Search every ClusterRoleBinding for subjects that are groups like <code>system:authenticated<\/code> or <code>system:unauthenticated<\/code>. List every Role and ClusterRole containing <code>secrets<\/code> with <code>get<\/code>, <code>list<\/code> or <code>watch<\/code>, plus <code>escalate<\/code>, <code>bind<\/code>, <code>impersonate<\/code>, <code>pods\/exec<\/code> and <code>*<\/code>. Check each namespace for a <code>pod-security.kubernetes.io\/enforce<\/code> label. Check which service accounts have a mounted token and no reason for one.<\/p>\n<p>None of this is clever. Each check removes a step from the chain in the diagram: app bug, token, a create-pods grant, a privileged pod, the node. Breaking one link stops the attacker at that point, and breaking several is cheap next to writing the incident report.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most Kubernetes incident write-ups I read start the same way. Somebody finds a remote code execution bug in an ordinary web app, lands in a pod, and twenty minutes later they are reading secrets from every namespace. The bug in the app was a normal bug. The part that turned it into a cluster compromise [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":552,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,21],"tags":[350,83,275,95,351,349],"class_list":["post-551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-security","tag-admission-control","tag-container-security","tag-kubernetes","tag-least-privilege","tag-pod-security-admission","tag-rbac"],"_links":{"self":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/comments?post=551"}],"version-history":[{"count":1,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":827,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/posts\/551\/revisions\/827"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/media\/552"}],"wp:attachment":[{"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/media?parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/categories?post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.canutethegreat.com\/index.php\/wp-json\/wp\/v2\/tags?post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}