AWS CodeBuild projects are inspected for plaintext environment variables (PLAINTEXT) that resemble secrets (keys, tokens, passwords).
Such values indicate sensitive data is stored directly in environment variables instead of being sourced securely.
Risk
Plaintext secrets in environment variables reduce confidentiality: values can be viewed in consoles/CLI and may leak into build logs or public outputs. Compromised credentials enable unauthorized AWS actions, artifact tampering, and lateral movement, causing data exfiltration and CI/CD supply-chain compromise.
prowler aws --checks codebuild_project_no_secrets_in_variables
Recommendation
Store secrets outside the build and reference them via AWS Secrets Manager or AWS Systems Manager Parameter Store instead of PLAINTEXT variables.
- Enforce least privilege on the build role
- Rotate secrets; prefer short-lived credentials
- Avoid logging or exporting secret values and never embed them in artifacts
Remediation
- In AWS Console, go to CodeBuild > Build projects and open your project
- Click Edit in the Environment section
- Under Environment variables, for each sensitive variable with Type = Plaintext, change Type to Secrets Manager (or Parameter store)
- Select the secret (or parameter) that holds the value, then Save
- If the secret/parameter does not exist, create it in Secrets Manager or Systems Manager Parameter Store first, then repeat steps 3-4
Source Code
Resource Type
AwsCodeBuildProject
References
- https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
- https://www.learnaws.org/2022/11/18/aws-codebuild-secrets-manager/
- https://www.learnaws.org/2023/08/23/codebuild-env-vars/
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environmentvariable.html
- https://docs.aws.amazon.com/codebuild/latest/userguide/change-project.html
- https://docs.aws.amazon.com/securityhub/latest/userguide/codebuild-controls.html#codebuild-2
- https://pasmichal.medium.com/how-to-handle-secrets-in-aws-codebuild-6e1b96013712
- https://medium.com/@odofing/aws-codepipeline-how-to-securely-store-environment-variables-in-ssm-paramater-store-and-aws-9a96d7083b3c