Skip to main content
All articles

Reaching a service account that outranks you: Kubernetes RBAC escalation and CVE-2021-25742

Kubernetes RBAC escalation is rarely a broken authorizer. It is a verb whose blast radius you underestimated, or a component whose service account outranks the caller. ingress-nginx CVE-2021-25742 is the second kind.

By Published

8 min read12 views

Kubernetes RBAC privilege escalation almost never means someone defeated the authorizer. The authorizer usually does exactly what it was told. Escalation comes from one of two places, and telling them apart is the point of this post.

  • Escalation through RBAC's own escape hatches. A subject is granted escalate, bind, or impersonate, and those verbs are designed to let you exceed your current permissions. Used as intended by the wrong subject, they are a straight line to more power.
  • Escalation by reaching a more privileged component. A subject cannot read secrets, but it can influence a controller whose service account can. The caller never gains a permission. It borrows one.

The first class is a review problem: you can read it out of the role definitions. The second class is a reachability problem: you have to trace what a limited identity can touch, and what those things are allowed to do. The named CVE below is the second kind, which is the kind scanners miss.

Why the authorizer's own rules push escalation into the second class

Kubernetes tries hard to stop the obvious move. You cannot create or update a Role or ClusterRole containing permissions you do not already hold; the RBAC authorizer checks every rule against your effective permissions and rejects the request otherwise. You cannot create a RoleBinding to a role more powerful than your own unless you have been granted bind. These guardrails are real and they work.

The effect is that direct self-promotion is mostly closed off, so escalation flows to the paths the guardrails do not cover:

  • The escape-hatch verbs. escalate on roles, bind on rolebindings, and impersonate on users, groups or service accounts each exist to let a subject step outside its own permission set. A ClusterRole that grants any of these to a broad audience has handed out the keys.
  • Wildcards. resources: ["*"] and verbs: ["*"] read as convenient and mean "including the ones that matter", which is secrets, serviceaccounts/token, and the ability to create workloads.
  • Workload identity. If you can create a pod, you can mount a service account, and that pod runs with the service account's permissions, not yours. create pods in a namespace with a privileged service account is a permission you do not appear to have on paper.
  • Borrowing a controller. Shared platform components run with wide permissions. If a limited tenant can influence what a controller does, the tenant inherits the controller's reach without ever holding it.

The real one: ingress-nginx CVE-2021-25742

The ingress-nginx controller renders Ingress objects into NGINX configuration. To do its job it runs with a service account that can read Secrets across the cluster, because TLS certificates live in Secrets in many namespaces. That is the over-privileged component. The escalation was the bridge to it.

The CVE record states the failure directly:

a user that can create or update ingress objects can use the custom snippets feature to obtain all secrets in the cluster.

That is CVE-2021-25742, scored 7.6 by Kubernetes (CVSS 3.1, CWE-20, Improper Input Validation); NVD's own score is 7.1. The custom-snippet annotation let a namespaced tenant inject configuration that the controller then executed with the controller's identity, and that identity could read every Secret in the cluster. A subject whose only granted power was "manage Ingress in my namespace" reached a service account that outranked it, and through that account read TLS keys, service-account tokens, and application secrets it was never granted.

The same lesson recurred: CVE-2023-5044 (also 7.6 per Kubernetes, CWE-20; NVD scores it 8.8) is code injection through the nginx.ingress.kubernetes.io/permanent-redirect annotation, a different route to the same over-privileged identity (the chrooted controller, introduced in v1.2.0, allows command execution but not credential extraction). When a shared component holds cluster-wide power, every input it accepts is an escalation surface. The fix in both cases narrowed what the annotations could do, which is the tell that the root issue was the reachability of the controller's permissions, not any one parser bug.

The injection payloads are public and are not reproduced here. What a defender needs is not the payload, it is the graph: who can create Ingress, what the controller's service account can do, and the fact that the first group can borrow the second.

A lab you can build without Docker

You can build the whole picture on a single machine with minikube and kubectl. minikube runs a real cluster in a local VM, so no Docker Desktop is required; the --driver can be a hypervisor such as qemu or hyperkit. kind is not the Docker-free path: it runs its nodes as containers and needs Docker, Podman or nerdctl installed. kubectl is the only other tool.

minikube start --driver=qemu            # any VM driver

First, see the escape-hatch guardrail and where it stops. Create a limited service account and ask the API what it can do, as that identity:

kubectl create namespace tenant-a
kubectl create serviceaccount limited -n tenant-a

# Grant only Ingress management in one namespace.
kubectl create role ing-mgr -n tenant-a \
  --verb=get,list,create,update --resource=ingresses
kubectl create rolebinding ing-mgr-b -n tenant-a \
  --role=ing-mgr --serviceaccount=tenant-a:limited

# On paper this identity cannot read secrets anywhere.
kubectl auth can-i get secrets -n kube-system \
  --as=system:serviceaccount:tenant-a:limited          # -> no

Now install the ingress controller and inspect the identity the tenant can reach:

minikube addons enable ingress

# What can the controller's service account actually do?
kubectl auth can-i --list \
  --as=system:serviceaccount:ingress-nginx:ingress-nginx | grep -i secret

The can-i --list output is the finding. The tenant identity is denied secrets, and the controller identity it can influence is allowed them cluster-wide. That gap, not any exploit string, is the escalation. The lab stops at showing the gap deliberately; reproducing the snippet injection is unnecessary to make the risk legible and is left out.

Finding it in manifests

RBAC escalation is one of the few classes you can genuinely audit statically, because the power is written down.

# Wildcards, the escape-hatch verbs, and secret access.
grep -rniE "verbs:\s*\[?\s*[\"']?\*" .
grep -rniE "escalate|bind|impersonate" .
grep -rniE "resources:.*(secrets|serviceaccounts/token)" .

# Bindings to broad subjects, which multiply any of the above.
grep -rniE "system:authenticated|system:unauthenticated|system:serviceaccounts\b" .

# The ingress-nginx setting specifically.
grep -rniE "allow-snippet-annotations|enable-snippets" .

Read every ClusterRoleBinding twice: the role tells you the power, the subject tells you who holds it, and the danger is in the product of the two. A modest role bound to system:authenticated is a cluster-wide grant. Treat allow-snippet-annotations: "true" as a decision to let anyone who can create an Ingress run configuration as the controller.

Fixing it

Least privilege, no wildcards. Enumerate resources and verbs. A role that needs to read config maps should say configmaps and get,list, not *. Split broad roles into the two or three narrow ones the workloads actually use.

Guard the escape-hatch verbs. escalate, bind, and impersonate should be held by a countable set of cluster administrators and nothing else. Audit for them by name.

Constrain shared controllers. Keep snippet annotations disabled (the documented default in current releases), and where a controller must hold wide permissions, restrict who can create the objects it consumes. If tenants can create Ingress, they can reach the controller, so scope the controller's Secret access to the namespaces it truly serves rather than the whole cluster where the platform allows it.

Apply Pod Security Standards and admission control. Restricting who can create privileged pods closes the workload-identity path, and an admission policy can reject the wildcard roles and dangerous annotations before they are stored.

Detecting it

The Kubernetes audit log is the primary source, and the events worth alerting on are specific.

  • Writes to RBAC objects. create or update on roles, clusterroles, rolebindings, and clusterrolebindings, especially outside a known GitOps service account. A human editing bindings directly is either an operator or an intruder.
  • Use of impersonate. Impersonation requests carry the impersonated user in the audit event. Any impersonation by a subject that is not a known controller deserves review.
  • Recon. A burst of auth can-i or selfsubjectaccessreviews from one identity is enumeration. It is cheap for an attacker and loud in the log if you watch for it.
  • Off-profile secret reads. The ingress controller reading Secrets is normal; the ingress controller reading Secrets in namespaces it serves no ingress for is not. Baseline the controller and alert on the deviation.

Take this away

RBAC escalation is a graph problem, not a permission-list problem. The question is not "what can this identity do", it is "what can this identity reach that can do more." CVE-2021-25742 answered that question the hard way: a tenant who could only touch Ingress objects reached a service account that could read the whole cluster's secrets. Audit the escape-hatch verbs, kill the wildcards, and for every shared controller, assume its inputs are an escalation surface until you have proven otherwise.

Further reading

Was this useful?

Share

Tags

  • container security
  • authorization
  • cve analysis
  • detection engineering

Get the next write-up by email

New technical write-ups by email when we publish. No sales sequence, and every email has an unsubscribe link.

Prefer a feed? RSS. How we handle your address: privacy notice.

Comments

Loading comments…

Leave a comment

Comments are read and approved by hand before they appear, so yours will not show up straight away. Your email address is optional, is never published, and is only used if we need to reply to you directly.

0/5000

Related service

API Penetration Testing

Authorisation, object-level access and abuse testing against your API surface.

If you want to know whether what you have just read applies to your own systems, that is the engagement that answers it.