All checks
Critical CodeBuild · regional

CodeBuild project environment variables should not contain clear text credentials

Checks that no CodeBuild project environment variable named exactly AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, PASSWORD or TOKEN has the plain-text type; other names, such as DB_PASSWORD, are not read. A plain-text value is readable by anyone who can read the project, so it needs rotating as well as moving.

service
CodeBuild
severity
Critical
scope
evaluated in every region

How to fix it

  • Can break clients: Grant the service role secretsmanager:GetSecretValue or ssm:GetParameters on the secret or parameter first (and kms:Decrypt for a customer managed key), or every build fails.

In the console

CodeBuild → Build projects → the project → Edit → Environment → Additional configuration → Environment variables

Type
Secrets Manager or Parameter, with Value naming the secret or parameter instead of holding the credential
Environment variables
Remove AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY where you can: builds already get the service role's credentials

With Terraform

resource "aws_codebuild_project" "this" {
  name         = var.project_name
  service_role = var.service_role_arn

  artifacts {
    type = var.artifacts_type
  }

  source {
    type = var.source_type
  }

  environment {
    compute_type = var.compute_type
    image        = var.build_image
    type         = var.environment_type

    environment_variable {
      name  = var.credential_variable_name
      value = var.secret_id
      type  = "SECRETS_MANAGER"
    }
  }
}

See which of your accounts this check is failing on.

Book a live scan