Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Sure, here are the step by step instructions to remediate the KMS Keys Scheduled for Deletion should be recovered misconfiguration in AWS using the AWS console:
- Open the AWS Management Console and navigate to the KMS service.
- In the left navigation pane, click on “Scheduled Deletion”.
- Check the list of keys scheduled for deletion and identify the key that needs to be recovered.
- Select the key by clicking on the checkbox next to it.
- Click on the “Recover” button on the top of the page.
- In the confirmation dialog box, click on the “Recover” button again to confirm the recovery.
- Once the key is recovered, it will be available for use again.
Using CLI
Using CLI
Sure, here are the step-by-step instructions to remediate the KMS Keys Scheduled for Deletion should be Recovered issue in AWS using AWS CLI:Note: Replace Note: Replace
- Open the AWS CLI on your local machine.
- Run the following command to list all the KMS keys that are scheduled for deletion:
<key-id> with the ID of the KMS key that is scheduled for deletion.- Review the output of the command and identify the Grant IDs of the grants that are scheduled for deletion.
- Run the following command to recover the grants that are scheduled for deletion:
<key-id> with the ID of the KMS key that is scheduled for deletion and <grant-id> with the ID of the grant that you want to recover.- Repeat steps 4 and 5 for all the grants that are scheduled for deletion.
- Once you have recovered all the grants that were scheduled for deletion, recheck the status of the KMS key to ensure that the issue has been resolved.
Using Python
Using Python
To remediate this issue in AWS using Python, you can use the AWS SDK for Python (Boto3) to recover the KMS keys that are scheduled for deletion. Here are the steps to do so:This Python script will cancel the scheduled deletion for all KMS keys that are in the “PendingDeletion” state. You can run this script periodically to ensure that any KMS keys that are scheduled for deletion are recovered.
- Import the required Boto3 libraries:
- Create a Boto3 client for the KMS service:
- Use the
list_grantsAPI to get the list of all KMS keys that are scheduled for deletion:
- For each grant that is scheduled for deletion, use the
cancel_key_deletionAPI to cancel the scheduled deletion:
Using Terraform
Using Terraform
PendingDeletion state (the aws kms cancel-key-deletion and subsequent aws kms enable-key operations) is not exposed by the Terraform AWS provider, so it cannot be remediated directly in Terraform; you must:-
In CLI/Console, run the verified fix:
aws kms cancel-key-deletion --key-id YOUR_KEY_ID --region YOUR_REGIONaws kms enable-key --key-id YOUR_KEY_ID --region YOUR_REGION- Heed the warnings: only cancel deletion if it wasn’t intentional.
-
Import the key into Terraform (if not already managed) and ensure your
aws_kms_keyconfiguration does not schedule its deletion again:terraform import aws_kms_key.EXISTING_KEY YOUR_KEY_ID
terraform plan should then show either:- No changes (if the config matches the recovered key), or
- Only configuration drift being reconciled (description, tags, etc.), and specifically no actions that schedule the key for deletion.

