Triage and Remediation
- Remediation
Remediation
Using Console
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
- Sign in to the AWS Management Console.
- Go to Secrets Manager:
Services → Security, Identity, & Compliance → Secrets Manager. - 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
- On the secret’s details page, click Rotate secret (or edit rotation from the Rotation tab/section).
- Check Enable automatic rotation.
- Under Rotation schedule, choose the rotation period (e.g., 30 days).
-
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.
- Save/confirm the Lambda creation (if you created a new one) and return to the Rotate secret configuration.
3. Configure rotation schedule and save
- 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.
- Click Save or Schedule rotation.
4. (Optional) Test rotation
- On the secret’s page, use Rotate secret immediately (or Test rotation) if available.
- 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).
Using CLI
Using CLI
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.
In the output, note the
Look at
Notes:
Confirm
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
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:KmsKeyId field. That is the KMS key you must configure.2. Check current rotation status of the KMS key
KeyRotationEnabled:false→ rotation not enabled (this triggers your finding).true→ rotation already enabled.
3. Enable automatic rotation for the KMS key
- 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
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.Using Python
Using Python
Below is a practical, minimal set of steps and Python snippets to enable automatic rotation for AWS Secrets Manager secrets that use KMS.
Attach this policy to the role.
Package this as a ZIP and deploy as a Lambda (via console or CLI).
Set:
If the Lambda is already associated and you just want to turn rotation on/update schedule:
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 (
1. Prerequisites
- A secret already exists in AWS Secrets Manager (e.g.
my-db-secret). - The secret is encrypted with a KMS key (default or customer-managed).
- You have:
awsclior AWS Console accessboto3installed 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.):
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):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)
Userotate_secret or enable_rotation from boto3: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).Using Terraform
Using Terraform
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.
