Skip to main content

Triage and Remediation

Remediation

Using Console

Below are the minimal console steps to enable rotation for an AWS Secrets Manager secret that’s encrypted with a KMS key.
Note: Secrets rotation is configured per secret. The KMS key only encrypts the secret; enabling rotation is done in Secrets Manager, not on the KMS key itself.

1. Identify the secret

  1. Sign in to the AWS Management Console.
  2. Go to Secrets Manager:
    Services → Security, Identity, & Compliance → Secrets Manager.
  3. On Secrets, click the secret you want to enable rotation for (it can be encrypted with a customer-managed KMS key).

2. Set up (or select) a rotation Lambda function

  1. On the secret’s details page, click Rotate secret (or edit rotation from the Rotation tab/section).
  2. Check Enable automatic rotation.
  3. Under Rotation schedule, choose the rotation period (e.g., 30 days).
  4. Under Rotation function, choose one of:
    • Use an existing Lambda function (if you already have a rotation function for this secret’s type).
    • Or Create a new Lambda function (recommended if you don’t have one):
      • Choose the database/service type (e.g., RDS, DocumentDB, etc.).
      • Provide a name for the new Lambda function.
      • AWS will create a Lambda from a template and an IAM role with required permissions.
  5. Save/confirm the Lambda creation (if you created a new one) and return to the Rotate secret configuration.

3. Configure rotation schedule and save

  1. Set Rotation schedule:
    • Choose Automatic rotation.
    • Set the rotation interval (e.g., 30, 60, or 90 days).
    • (Optional) Configure a specific start time if needed.
  2. Click Save or Schedule rotation.

4. (Optional) Test rotation

  1. On the secret’s page, use Rotate secret immediately (or Test rotation) if available.
  2. Confirm that:
    • The Lambda function completes without errors.
    • The target resource (DB, service, etc.) can be accessed using the updated secret value.
    • The secret remains encrypted with your intended KMS key (check Secret details → Encryption key).
This remediates the “Secrets Manager secrets rotation disabled” issue for a KMS-encrypted secret via the AWS Console.
To fix this finding using AWS KMS via AWS CLI, you typically need to enable automatic rotation on the KMS keys that encrypt your Secrets Manager secrets.Below are the step‑by‑step commands.

1. Identify the KMS key used by the secret

If you already know the KMS key ID/ARN, skip to step 2.Otherwise, get the secret’s details:
In the output, note the KmsKeyId field. That is the KMS key you must configure.

2. Check current rotation status of the KMS key

Look at KeyRotationEnabled:
  • false → rotation not enabled (this triggers your finding).
  • true → rotation already enabled.

3. Enable automatic rotation for the KMS key

Notes:
  • This can only be done for symmetric customer managed keys (CMKs), not AWS‑managed keys.
  • Rotation interval is fixed at 1 year for KMS automatic rotation.

4. Re‑verify rotation status

Confirm KeyRotationEnabled is now true.
If you also need Secrets Manager secret rotation (rotating the secret value itself, e.g., database password), I can give you the separate CLI steps for setting up a rotation Lambda and enabling rotate-secret.
Below is a practical, minimal set of steps and Python snippets to enable automatic rotation for AWS Secrets Manager secrets that use KMS.

1. Prerequisites

  1. A secret already exists in AWS Secrets Manager (e.g. my-db-secret).
  2. The secret is encrypted with a KMS key (default or customer-managed).
  3. You have:
    • awscli or AWS Console access
    • boto3 installed for Python
    • IAM permissions for:
      • secretsmanager:*
      • lambda:*
      • iam:PassRole

2. Create an IAM Role for the Rotation Lambda

Create a role (e.g. SecretsRotationRole) with:
  • Trust policy (principal is Lambda):
  • Permissions policy for Secrets Manager, KMS, logging, and your target resource (e.g. DB, API, etc.):
Attach this policy to the role.

3. Write the Rotation Lambda in Python

A rotation Lambda must implement these steps:
createSecret, setSecret, testSecret, finishSecret.
Below is a minimal template (you must customize the actual secret-change logic, e.g., DB password rotation):
Package this as a ZIP and deploy as a Lambda (via console or CLI).
Set:
  • Runtime: Python 3.x
  • Role: SecretsRotationRole
  • Timeout: long enough for rotation (e.g. 15–30 seconds; more if needed).

4. Enable Rotation on the Secret Using Python (boto3)

Use rotate_secret or enable_rotation from boto3:
If the Lambda is already associated and you just want to turn rotation on/update schedule:

5. Verify Rotation Status


This remediates the misconfiguration by programmatically enabling secret rotation for a KMS-encrypted secret in AWS using Python; you only need to fill in the target-specific rotation logic in the Lambda (setSecret and testSecret).
Replace EXAMPLE_KEY with your key name and adjust description/usage/spec as needed.
This change does not force replacement of the KMS key; Terraform will update it in place.
To verify, terraform plan should show an in-place update with enable_key_rotation changing from false (or null) to true.