CodeBuild project has CloudWatch Logs or S3 logging enabled
CodeBuild projects are assessed for logging configuration to Amazon CloudWatch Logs or S3, identifying when at least one destination is enabled for build logs and events.
Risk
Absence of build logging creates blind spots for integrity and accountability. Attackers or misconfigurations can alter artifacts, exfiltrate data, or misuse credentials with little trace, hindering forensics and incident response. Missing telemetry impedes correlation with other alerts, risking source code and secret confidentiality.
Run this check with Prowler
Run in Prowler Cloudprowler aws --checks codebuild_project_logging_enabledRecommendation
Enable a log destination for every project-CloudWatch Logs or S3 (preferably both). Enforce defense in depth: encrypt logs, set retention, and restrict access on a least-privilege basis. Centralize and monitor logs, alert on anomalies, and avoid sensitive data in output. Use immutable retention to preserve auditability.
Remediation
CLI
aws codebuild update-project --name <project-name> --logs-config "cloudWatchLogs={status=ENABLED}"Terraform
# Terraform: Enable logging on a CodeBuild project
resource "aws_codebuild_project" "<example_resource_name>" {
name = "<example_resource_name>"
service_role = "<example_resource_id>"
artifacts { type = "NO_ARTIFACTS" }
environment {
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/standard:5.0"
type = "LINUX_CONTAINER"
}
source { type = "NO_SOURCE" }
logs_config {
cloudwatch_logs {
status = "ENABLED" # Critical: Enables CloudWatch logging to pass the check
}
}
}NativeIaC
# CloudFormation: Enable logging on a CodeBuild project
Resources:
<example_resource_name>:
Type: AWS::CodeBuild::Project
Properties:
Name: <example_resource_name>
ServiceRole: <example_resource_id>
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:5.0
Source:
Type: NO_SOURCE
LogsConfig:
CloudWatchLogs:
Status: ENABLED # Critical: Enables CloudWatch logging to pass the checkOther
Check Code
from prowler.lib.check.models import Check, Check_Report_AWS
from prowler.providers.aws.services.codebuild.codebuild_client import codebuild_client
class codebuild_project_logging_enabled(Check):
def execute(self):
findings = []
for project in codebuild_client.projects.values():
report = Check_Report_AWS(metadata=self.metadata(), resource=project)
report.status = "PASS"
cw_logs_enabled = (
project.cloudwatch_logs and project.cloudwatch_logs.enabled
)
s3_logs_enabled = project.s3_logs and project.s3_logs.enabled
if cw_logs_enabled and s3_logs_enabled:
report.status_extended = f"CodeBuild project {project.name} has enabled CloudWatch logs in log group {project.cloudwatch_logs.group_name} and S3 logs in bucket {project.s3_logs.bucket_location}."
elif cw_logs_enabled:
report.status_extended = f"CodeBuild project {project.name} has CloudWatch logging enabled in log group {project.cloudwatch_logs.group_name}."
elif s3_logs_enabled:
report.status_extended = f"CodeBuild project {project.name} has S3 logging enabled in bucket {project.s3_logs.bucket_location}."
else:
report.status = "FAIL"
report.status_extended = (
f"CodeBuild project {project.name} does not have logging enabled."
)
findings.append(report)
return findingsReferences
- https://docs.aws.amazon.com/codebuild/latest/userguide/change-project.html#change-project-console-logs
- https://codefresh.io/learn/devops-tools/aws-codebuild-the-basics-and-a-quick-tutorial/
- https://asecure.cloud/a/cfgrule_codebuild-project-logging-enabled/
- https://support.icompaas.com/support/solutions/articles/62000233680-ensure-that-codebuild-projects-have-s3-or-cloudwatch-logging-enabled
- https://docs.aws.amazon.com/securityhub/latest/userguide/codebuild-controls.html#codebuild-4