Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are step‑by‑step console instructions to find and safely remove/disallow specific AWS KMS CMKs.
If you share the exact policy requirement (e.g., “no CMKs in account X”, or “no CMKs with alias starting with X”), I can tailor the console steps and example IAM/SCP snippets to that specific control.
1. Identify the specific CMKs
- Sign in to the AWS Management Console.
- Go to Key Management Service (KMS):
- In the search bar, type KMS and select Key Management Service.
- In the left navigation, choose Customer managed keys.
- Use filters/search to locate the specific CMKs by:
- Key ID, Key ARN, or
- Alias (e.g.,
alias/old-key,alias/disallowed-key).
- Key ID / ARN
- Region
- Alias
- Key type (symmetric/asymmetric, single‑Region/multi‑Region)
2. Check what uses the key (to avoid breaking workloads)
For each CMK you plan to remove:- In KMS, click the key ID to open the key details.
- Review:
- Key policy – see which IAM principals can use it.
- Key rotation and tags – may hint at usage/owner.
- Check Key usage tab (if available) or use AWS services consoles to see dependencies:
- EBS: EC2 → Volumes → check Encryption column and KMS key field.
- RDS / Aurora: RDS → DB instances → each instance’s Configuration → KMS key.
- S3: S3 → Bucket → Properties → Default encryption → KMS key.
- CloudTrail: CloudTrail → Trails → Storage → KMS key.
- CloudWatch Logs, EFS, EKS, Lambda env vars, Secrets Manager, SSM Parameter Store: open each resource and confirm which KMS key is configured.
- Make a list of all resources still using this key.
3. Create or select an allowed replacement CMK (if needed)
If your policy requires different or restricted CMKs:- In KMS console, under Customer managed keys, choose Create key.
- Choose:
- Key type: symmetric (most common) or asymmetric as needed.
- Key usage: e.g., Encrypt and decrypt.
- Configure:
- Key administrators (who can manage the key).
- Key users (who can use it to encrypt/decrypt).
- Any key policy requirements from your security standard.
- Add a clear alias (e.g.,
alias/standard-data-key). - Complete creation.
4. Migrate services off the disallowed CMK
For each service that uses the disallowed CMK, update it to use the new/approved key:Example patterns (AWS console)
-
EBS volumes (new):
EC2 → Launch instance → Advanced details → Encryption → select new KMS key. -
EBS volumes (existing; snapshot‑based):
- Create a snapshot of the encrypted volume.
- Copy the snapshot and choose Encrypt with the new CMK.
- Create a new volume from the copied snapshot.
- Attach the new volume and migrate data (or use AMI based approach for root volumes).
-
RDS:
- You cannot change KMS key on an existing encrypted DB directly.
Typical approach:- Take a snapshot of the DB.
- Copy the snapshot and choose the new CMK for encryption.
- Restore a new DB instance from the copied snapshot.
- Cut over your application to the new DB.
- You cannot change KMS key on an existing encrypted DB directly.
-
S3 default bucket encryption:
- S3 → select bucket → Properties.
- Under Default encryption, click Edit.
- Choose AWS KMS key and select the new CMK.
- For existing objects, use S3 Batch Operations or lifecycle/automation to re‑encrypt if required by policy.
-
CloudTrail:
- CloudTrail → Trails → select trail → Edit.
- Under Log file SSE-KMS encryption, select the new KMS key.
- Save changes.
-
CloudWatch Logs:
- CloudWatch → Log groups → select log group.
- Actions → Edit (or Edit encryption).
- Select the new KMS key.
-
Secrets Manager:
- Secrets Manager → select secret.
- Edit → choose Encryption key → select new CMK → save.
-
SSM Parameter Store (SecureString):
- For each parameter: Edit the parameter and choose the new CMK. (Some may require re‑creation; check the console options.)
5. Disable key usage (soft stop) for the disallowed CMKs
Once you are sure no active workloads need the CMK:- KMS → Customer managed keys → select the specific CMK.
- On the key details page, click Disable.
- Confirm Disable.
- New encrypt/decrypt operations will fail with this key.
- Existing encrypted data remains encrypted; you can still re‑enable the key if you discover a missed dependency.
6. Schedule CMK deletion (hard removal)
When fully confident the key is no longer needed:- In KMS → Customer managed keys, select the CMK.
- On the key details page, choose Schedule key deletion.
- Choose a waiting period (7–30 days; choose the maximum allowed if you want a safer rollback window).
- Confirm.
- The key material and metadata are permanently deleted.
- Any data still encrypted under this key becomes unrecoverable.
7. Prevent future creation/use of disallowed CMKs
To keep the environment compliant:- Use IAM policies and/or Service Control Policies (SCPs) (if using AWS Organizations) to:
- Deny creation of CMKs that don’t adhere to your standards (based on tags, aliases, or regions).
- Deny use of specific key ARNs (the ones you just removed or disallowed patterns).
- Optionally:
- Centralize key creation and management to a limited admin group.
- Enforce tagging or alias conventions for approved keys.
If you share the exact policy requirement (e.g., “no CMKs in account X”, or “no CMKs with alias starting with X”), I can tailor the console steps and example IAM/SCP snippets to that specific control.
Using CLI
Using CLI
Below are step‑by‑step AWS CLI–based instructions to remediate a finding that flags the existence of specific AWS KMS customer managed keys (CMKs) (for example: legacy, unused, non‑compliant, or shadow keys).I’ll assume the goal is to identify those CMKs and securely decommission them (disable → schedule deletion), while avoiding breaking workloads.
For each key, get details and tags (to identify the “specific” ones):Common filters you might apply:
Or search for the key ARN instead of KEY_ID if you have it.If you see recent
Verify:If something breaks after disabling, you can re‑enable:
Verify:If you scheduled deletion by mistake and need to cancel it:
If you share one example Key ARN or the exact rule text (e.g., from Security Hub or a CSPM), I can give you precise CLI commands tailored to that specific misconfiguration.
1. Identify the Specific CMKs
If you already have the Key IDs / ARNs from the finding, you can skip to step 3. Otherwise, list and filter.- Key alias (e.g.,
alias/legacy-*,alias/test-*) - Tags (e.g.,
Environment=Dev,Owner=DeprecatedApp) - Creation date (
CreationDateindescribe-keyoutput) - Key state (
Enabled,Disabled, etc.)
2. Confirm No Active Dependencies
Before disabling or deleting a key, verify nothing critical uses it.2.1. Check CloudTrail for usage (recent period)
Encrypt, Decrypt, GenerateDataKey, etc., you must first migrate dependent workloads to another key (e.g., update services to use a new CMK).3. Disable the Specific CMKs (Safe First Step)
Disabling is reversible and is safer than immediate deletion.4. Schedule Deletion (Permanent Remediation)
Once you’ve confirmed the CMK is not needed:5. Remove or Update Aliases Pointing to These CMKs
If the finding is related to aliases pointing to non‑compliant keys, repoint or delete aliases.5.1. Repoint alias to a compliant CMK
5.2. Delete alias if not needed
6. (Optional) Enforce Future Compliance
If the finding is about certain “types” of CMKs existing (e.g., keys without rotation, with bad policies):- Enable rotation on compliant keys:
- Restrict who can create CMKs via IAM policies.
- Use tags and config rules / Security Hub controls to detect non‑compliant CMKs early.
If you share one example Key ARN or the exact rule text (e.g., from Security Hub or a CSPM), I can give you precise CLI commands tailored to that specific misconfiguration.
Using Python
Using Python
Below is a concise, step‑by‑step way to remediate disallowed / misconfigured AWS KMS CMKs using Python (boto3). Adjust to your policy (e.g., delete specific CMKs, disable them, or remove aliases).
Configure AWS credentials with permissions for KMS (e.g.,
Replace
If you share your exact policy (e.g., “any CMK not tagged
1. Prerequisites
kms:ListKeys, kms:DescribeKey, kms:DisableKey, kms:ScheduleKeyDeletion, kms:DeleteAlias, etc.).2. Identify the CMKs to Remediate
You need a rule to detect “bad” CMKs, for example:- Keys with a specific alias name/pattern (e.g.,
alias/bad-key-*) - Keys in a certain account/region that must not exist
- Keys with specific tags or key policies
2.1. List all CMKs and filter by criteria
alias_prefix or add your own detection logic.3. Disable the CMKs (Immediate Risk Reduction)
Disabling stops cryptographic operations but preserves the key for investigation.4. (Optional) Remove Disallowed Aliases
If your policy requires removing specific aliases instead of (or prior to) deleting keys:5. Schedule Deletion of the CMKs (Permanent Remediation)
Warning: After the waiting period, key material is permanently deleted and any data encrypted under these CMKs that doesn’t have a re‑encrypted copy becomes unrecoverable.6. (Optional) Enforce “Good” CMK Configuration Instead
If the misconfiguration is about how CMKs are configured (not just their existence), you may:-
Ensure rotation is enabled:
-
Fix key policies or tags via
put_key_policyandtag_resource.
7. End‑to‑End Script Skeleton
If you share your exact policy (e.g., “any CMK not tagged
Environment=Prod must be deleted”), I can adapt the detection and remediation logic precisely to that.Using Terraform
Using Terraform
SPECIFIC_KMS_CMK/SPECIFIC_KMS_CMK_ALIASwith your Terraform resource names.SPECIFIC_PURPOSE,YOUR_ENVIRONMENT,YOUR_TEAM, andalias/YOUR_EXPECTED_ALIAS_NAMEwith your required values so that the expected CMKs and aliases “exist” as required by your control.
customer_master_key_spec), which would force replacement and could cause outage for workloads using the old key.Verification: terraform plan should show + create for the aws_kms_key and aws_kms_alias resources corresponding to the keys that were previously missing.
