Code inject via nginx.ingress.kubernetes.io/permanent-redirect annotation
The permanent-redirect annotation value is not sanitised and is inserted into the nginx configuration, allowing a user who can create ingress objects to inject arbitrary nginx configuration. This lets them run commands on the ingress-nginx-controller pod and use the mounted service account token to access the Kubernetes API and read secrets.
- Triaged in 21 days
- Fixed in 4 months
- Paid in 3 months
- Disclosed after 4 months
Report Submission Form
Summary:
The value of the nginx.ingress.kubernetes.io/permanent-redirect annotation will be not sanitized and passed into the nginx configuration. This leads into a code inject from any user that is allowed to create ingress objects.
Kubernetes Version:
v1.26.3 (minikube)
Component Version:
-------------------------------------------------------------------------------
NGINX Ingress controller
Release: v1.8.0
Build: 35f5082ee7f211555aaff431d7c4423c17f8ce9e
Repository: https://github.com/kubernetes/ingress-nginx
nginx version: nginx/1.21.6
-------------------------------------------------------------------------------
Steps To Reproduce:
-
Install ingress-nginx, using latest version and default values. For demo purpose, I set
allow-snippet-annotations=falseBash helm upgrade -i ingress-nginx ingress-nginx/ingress-nginx -f values.yaml # values.yaml is attached -
apply service and ingress object from attachments
Bash k apply -f ingress.yaml #ingress.yaml is attached -
Optional: If ingress-nginx is not exposed, run
kubectl port-forward deploy/ingress-nginx-controller 8080:80and continue step 4 in a separate shell. -
Validate, if the code is injected. This demo uses the hostname
kubernetes.api, use the--resolveparameter of curl to do an request for the hidden server instance. The code below expect that ingress-nginx is accessible trough 127.0.0.1:8080Bash curl -v --resolve "kubernetes.api:8080:127.0.0.1" http://kubernetes.api:8080/api/v1/namespaces/kube-system/secrets/
Supporting Material/References:
- values.yaml - Used in step 1
- ingress.yaml - Used in step 2
Impact
All users with access to create or update ingress objects, are able to running commands on ingress-nginx-controller pod. Since the token of the ServiceAccount is mounted on filesystem, a user can call the Kubernetes API and fetch all secrets or config maps from the cluster. Additionally, the user can read or write files to the filesystem.
Attachments
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
Impact
Users who can create or update ingress objects can run commands on the ingress-nginx-controller pod and, using the mounted service account token, call the Kubernetes API to fetch all secrets or config maps and read or write files on the filesystem.
What the attacker needed
Access to create or update ingress objects
How it was found
- Install ingress-nginx with default values, setting allow-snippet-annotations to false.
- Apply the provided service and ingress objects.
- If the controller is not exposed, port-forward the controller deployment to local port 8080.
- Send a request to the hostname defined in the ingress using curl with the --resolve option to confirm the injected code executes.
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.
An annotation is a note attached to a Kubernetes object that tells the ingress controller how to behave. Here, the controller takes the note's value and puts it directly into its nginx configuration file without checking it, so someone who can create such objects can sneak in extra configuration that runs commands. That gives them the pod's service account token, which they can use to read secrets from the cluster.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.