Skip to content
Access control Write-up Intermediate

Exploiting GCP Cloud Build for Privilege Escalation

An attacker with write access to a source repository connected to GCP Cloud Build can modify the build configuration to run a malicious step that reads the attached service account's OAuth token from the metadata service and sends it to an attacker-controlled webhook. This allows the attacker to act as that service account and potentially escalate to more privileged accounts and resources.

Ayush Singh Follow

Published on blog.pwnedlabs.io

GCP Cloud Build can be abused for privilege escalation when an attacker can change the build configuration of a connected source repository. A build runs with an attached service account and can read that account's token from the metadata service, so a malicious build step can act as the service account and chain to…

Ayush Singh (@Hac10101), on blog.pwnedlabs.io

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

An attacker could steal OAuth tokens of service accounts, escalate privileges, and move laterally within the GCP environment, potentially gaining control over any service account in the project.

What the attacker needed

Write access to a connected source repository; Cloud Build trigger configured; service account with cloudbuild.builds.create permission

The fix

Apply least privilege to build service accounts, require manual approval for build triggers, remove unnecessary trigger-creation permissions, and monitor build activity.

How it was found

  1. Obtain write access to a source repository linked to Cloud Build.
  2. Modify the cloudbuild.yaml file to add a step that retrieves the service account email and OAuth token from the metadata service and sends them to an attacker-controlled webhook.
  3. Push the modified cloudbuild.yaml to the repository, triggering Cloud Build to execute the malicious step.
  4. Use the stolen OAuth token to act as the service account, and if it has cloudbuild.builds.create permission, create a new trigger with a more privileged service account.
  5. Repeat the token theft for the more privileged service account.
  6. If the new service account can deploy services like Cloud Run, deploy a backdoored service with an attached service account to steal its token.

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 write-up has not been written yet. The Original tab links to the source.

Cloud Build is a service that runs automated build steps for code. If an attacker can change the build instructions, they can make the build fetch a secret token that belongs to the build's service account (a special account used by the build) and send it to themselves. With that token, the attacker can pretend to be that service account and access other cloud resources.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Google (GCP)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.