Skip to main content

More Info:

This rule ensures that logging is enabled for the environment of an AWS CodeBuild project by checking if at least one log option is enabled. Logging provides valuable insights into build execution, errors, and debugging information. Failing to enable logging can hinder troubleshooting efforts and impact the visibility of build activities.

Risk Level

Medium

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • Cloudanix Best Practice
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • Essential 8
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • Reserve Bank of India (RBI) Cyber Security Framework
  • Reserve Bank of India (RBI) Master Direction – Information Technology Framework
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • Securities and Exchange Board of India (SEBI) - Cloud Security Adoption Framework
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

To remediate “Logging should be enabled for CodeBuild project environment” using the AWS Management Console:
  1. Sign in and open CodeBuild
    • Go to AWS Management Console → search for CodeBuild → open AWS CodeBuild.
  2. Select the project
    • In the left pane, click Build projects.
    • Click the name of the project you want to fix.
  3. Edit the project
    • On the project details page, click Edit (top right).
    • Scroll down to the Logs or Build logs section.
  4. Enable CloudWatch Logs
    • Under CloudWatch logs, select Enabled.
    • Choose a Log group:
      • Either pick an existing CloudWatch Log group, or
      • Click the option to Create new and give it a name (e.g., /aws/codebuild/<project-name>).
    • (Optional but recommended) Set a stream name format or accept the default.
  5. Enable S3 Logs (optional but recommended)
    • Under S3 logs, select Enabled.
    • Choose or create an S3 bucket to store logs.
    • (Optional) Specify a bucket prefix (e.g., codebuild-logs/<project-name>/).
  6. Verify service role permissions
    • Note the Service role listed in the project configuration (e.g., codebuild-<project-name>-service-role).
    • In a new tab, go to IAMRoles → open that role.
    • Confirm it has permissions like:
      • For CloudWatch Logs:
        • logs:CreateLogGroup
        • logs:CreateLogStream
        • logs:PutLogEvents
      • For S3 logs:
        • s3:PutObject (for the chosen bucket/prefix)
    • If missing, attach or update a policy to include these actions for the relevant Log Group and S3 bucket.
  7. Save the project
    • Go back to the Edit build project page.
    • Scroll to the bottom and click Update build project (or Save).
  8. Validate logging
    • Start a new build for that project.
    • Go to:
      • CloudWatch → Logs → Log groups → open your log group → verify build logs appear.
      • S3 → your log bucket → verify log files are being created (if S3 logs enabled).
Once these steps are done, the “logging should be enabled” finding for that CodeBuild project should be remediated.
Below are concise, step-by-step AWS CLI instructions to enable logging for an existing AWS CodeBuild project.Assumptions:
  • You already have a CodeBuild project named MY-CODEBUILD-PROJECT.
  • You want to enable CloudWatch Logs (and optionally S3 logs).

1. Get the current project configuration

You need the full current config so you can pass it back into update-project (CodeBuild requires most fields, not just logs).
Inspect project.json and locate the entry under "projects" → first object. That is the full project definition.
Pick a log group name, e.g. /codebuild/MY-CODEBUILD-PROJECT:
If it already exists, you can ignore any “resource already exists” error.

3. (Optional) Create an S3 bucket for logs

If you also want S3 logs, create / choose a bucket, e.g. my-codebuild-logs-bucket:

4. Build the logsConfig JSON

You will use --logs-config in update-project.

4.1 Example: Enable only CloudWatch Logs

4.2 Example: Enable both CloudWatch Logs and S3 logs


5. Extract required fields from the existing project

From project.json, extract each of the following values from the project object:
  • name
  • description (if present)
  • source
  • artifacts
  • environment
  • serviceRole
  • timeoutInMinutes (if present)
  • queuedTimeoutInMinutes (if present)
  • encryptionKey (if present)
  • tags (if present)
  • vpcConfig (if present)
  • badgeEnabled (if present)
  • buildTimeout, queuedTimeout (old fields) as applicable
  • Any other fields you see that are set (you should generally re-supply them).
You can also pull them programmatically with jq, but the safest is to reuse everything from that object.Example using jq to extract common fields:

6. Run update-project with the new logs config

Here is a generic example that includes the most common parameters and sets logsConfig from logs-config.json.
If you prefer to do it manually (without jq), just plug the JSON fragments directly, e.g.:
Make sure all fields match your existing project values; only logsConfig should be changing.

7. Verify logging is enabled

You should see:
(or your S3 configuration if you enabled it).If you share your current project.json (redacted), I can give you an exact aws codebuild update-project command for your environment.
To remediate “Logging should be enabled for CodeBuild project environment” with Python, you need to:
  1. Identify the project(s)
  2. Enable at least one logging destination (CloudWatch Logs or S3) in logsConfig
  3. Update the CodeBuild project via boto3
Below is a minimal, end‑to‑end example.

1. Prerequisites

  • boto3 installed:
  • AWS credentials configured (env vars, ~/.aws/credentials, or an attached IAM role).
  • IAM permissions for:
    • codebuild:BatchGetProjects
    • codebuild:UpdateProject
    • logs:CreateLogGroup (if you need to create the group)
    • logs:DescribeLogGroups

2. Decide logging configuration

Example: enable CloudWatch Logs for a project:
  • Log group name: /aws/codebuild/my-project-logs
  • Stream name: codebuild-log-stream
You can also enable S3 logs similarly.

3. Python script to enable CloudWatch Logs


4. To enable S3 logging (optional or in addition)

Adjust the logsConfig block:
Make sure the CodeBuild service role has permission to write to that S3 bucket.
This script can be run once per project (or loop over all projects) to remediate the “logging disabled” finding programmatically.
Changing only logs_config is an in-place update and does not force replacement of the CodeBuild project, but it will overwrite any existing logs configuration in the same way as the CLI command (including disabling S3 logs if you do not also configure s3_logs here).To verify, terraform plan should show an update to aws_codebuild_project.this.logs_config.cloudwatch_logs with status changing to ENABLED (and group_name/stream_name set as specified), with no destroy/create replacement of the project resource.

Additional Reading: