Skip to main content

Triage and Remediation

Remediation

Using Console

Below are the exact console steps to ensure a CloudWatch Log Group is encrypted with a customer-managed KMS key (CMK).

Prerequisites: Create or identify a CMK

  1. Sign in to the AWS Management Console.
  2. Go to Key Management Service (KMS):
    • In the search bar, type KMS, choose Key Management Service.
  3. Create a new CMK (if you don’t already have one for logs):
    • In the left pane, choose Customer managed keys.
    • Click Create key.
    • Key type: Symmetric.
    • Key usage: Encrypt and decrypt.
    • Click Next and:
      • Set an alias (e.g., alias/cloudwatch-logs-key).
      • Choose key administrators and key users (IAM roles/users that need to write/read logs).
    • Complete the steps and click Finish.
Note: Ensure the IAM roles/services that write to CloudWatch Logs (e.g., Lambda, ECS, EC2, etc.) are added as Key users so they can use the CMK.

Step-by-step: Encrypt an existing CloudWatch Log Group with CMK

  1. In the AWS console, go to CloudWatch.
  2. In the left navigation pane, select Log groups.
  3. Find and click the log group you want to encrypt.
  4. At the top right, choose ActionsEdit (or Edit encryption depending on UI).
  5. Under Encryption:
    • Check/enable Encrypt log group (if shown).
    • For KMS key, choose:
      • Select KMS key and pick your customer-managed key (e.g., alias/cloudwatch-logs-key), not aws/logs (the AWS-managed key).
  6. Click Save changes.
CloudWatch Logs will now store new log data in that log group encrypted using your CMK.

Step-by-step: Set CMK encryption by default for new log groups (optional)

There is no global “default CMK for all log groups” setting in the console, but you can:
  • Create log groups manually (instead of auto-created), and during creation:
    1. In CloudWatch → Log groups → Create log group.
    2. Enter Log group name.
    3. Under Encryption, choose your CMK.
    4. Click Create.
  • Or enforce via automation (CloudFormation, Terraform, or a Lambda that:
    • Monitors for new log groups.
    • Calls AssociateKmsKey to attach your CMK to them.)

Validate encryption

  1. In CloudWatch → Log groups, click the log group.
  2. Check the Encryption section:
    • It should show KMS with your CMK alias/ARN.
  3. Optionally, in KMS → Customer managed keys, select your key and:
    • Check Key usage and CloudTrail logs to confirm encryption operations.
Below are AWS CLI steps to ensure CloudWatch Log Groups are encrypted with a customer-managed KMS CMK.

1. (Optional) Create a KMS CMK for CloudWatch Logs

If you don’t already have a CMK you want to use:
Note the KeyId from the output. You can also create an alias:
You can then use either the KeyId or the alias ARN as the --kms-key-id.

2. Identify Log Groups Without CMK Encryption

List all log groups:
Filter those without a kmsKeyId using jq (recommended):
This will output the names of log groups that are not using CMK encryption.

3. Associate a CMK with a Single Log Group

Use associate-kms-key to enable CMK encryption:
Or directly with the KeyId/KeyArn:

4. Apply CMK Encryption to All Unencrypted Log Groups (Batch)

Example Bash loop for all unencrypted log groups:

5. (Important) KMS Key Policy Permissions

Ensure the CMK key policy allows CloudWatch Logs and any writers/readers to use it. Minimal example snippet in the KMS key policy:
Update policy via:

6. Verify Encryption

Check a specific log group:
You should see kmsKeyId populated with the CMK ARN.
Below is a concise, step‑by‑step way to remediate “CloudWatch Log Groups should be encrypted with CMK” using Python (boto3).

1. Prerequisites

  • Python 3.x
  • boto3 installed:
  • AWS credentials configured (via ~/.aws/credentials, environment variables, or instance profile).
  • Permissions:
    • logs:DescribeLogGroups, logs:AssociateKmsKey
    • kms:CreateKey, kms:DescribeKey, kms:ListAliases (if creating/using CMK)

2. Option A – Use an Existing KMS CMK

If you already have a KMS CMK (recommended), you just need its ARN or alias.

2.1. Find CMK by alias (optional helper)


3. Option B – Create a New CMK for CloudWatch Logs

Call this once to create the key:

4. Associate CMK with All (or Selected) Log Groups

This script:
  • Lists all CloudWatch log groups.
  • Identifies those without a kmsKeyId (i.e., not using CMK).
  • Associates them with the specified CMK.

5. Verify Encryption

Programmatically:

Summary of flow:
  1. Create or choose a KMS CMK (steps 2–3).
  2. Run the association script (step 4).
  3. Verify all log groups show kmsKeyId set (step 5).
  • Replace var.AWS_REGION with your region variable or hard-code the region string as needed.
  • If the log group already exists and is imported into Terraform, adding kms_key_id is an in-place update and does not force replacement.
Verification: terraform plan should show an in-place update on aws_cloudwatch_log_group.this with kms_key_id changing from null to the CMK ARN, and creation of aws_kms_key.cloudwatch_logs.