More Info:
KMS keys should not be in a pending deletion or deleted state. Deleted keys cannot decrypt previously encrypted data, potentially causing permanent data loss.Risk Level
MediumAddress
Compliance, SecurityCompliance Standards
- APRA CPS 234 (Australia)
- AWS Well Architected Framework
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- HIPAA
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To remediate “OCI Encryption KMS Keys Should Not Be Pending Deletion” using the OCI Console:
-
Sign in and go to Key Management
- Open the OCI Console.
- From the top-left menu, go to: Identity & Security → Vault.
- Select the compartment where your vault is located.
-
Open the affected Vault
- Click the Vault that contains the KMS key in “Pending deletion” state.
- In the vault details page, go to the Keys tab.
-
Locate keys in Pending Deletion
- In the keys list, look at the Lifecycle state column.
- Identify keys with state “Pending deletion”.
-
Cancel key deletion
- Click the name of the affected key.
- On the key details page, click More Actions (or the action menu) and choose Cancel Deletion (or Cancel key deletion).
- Confirm the cancellation in the dialog.
-
Verify encryption/monitoring configurations
- Go to the OCI services using KMS (Block Volumes, Object Storage, Databases, Logging/Monitoring resources, etc.).
- For critical resources, confirm:
- They reference the restored key (if they were already using it), or
- They use a different active key if you truly intend to decommission this one later.
-
(Optional) Plan proper key rotation/deletion
- If a key still needs to be retired:
- Create a new key in the same vault.
- Update all dependent resources to use the new key.
- Only after confirming no dependencies, schedule the old key for deletion again.
- If a key still needs to be retired:
Using CLI
Using CLI
Below are the concrete remediation steps using the OCI CLI to handle KMS keys that are in
If you have multiple vaults and want to check all of them in a compartment:Note the Key OCIDs you want to rescue.
Explanation of Lifecycle state should move from
Use this only if you are sure every
You can then:
If you share whether you want automatic cancellation vs just detection/alerting, I can refine the exact CLI/cron or shell script pattern.
PENDING_DELETION and should not be.1. Prerequisites
- Make sure OCI CLI is installed and configured:
- Ensure you have:
- Permissions on the Vault and Keys (policy allowing
MANAGE keys/MANAGE vaultsas appropriate). - The compartment OCID where the vault/keys live.
- Permissions on the Vault and Keys (policy allowing
2. Identify KMS Keys in PENDING_DELETION
First, list all keys in a given compartment and filter onPENDING_DELETION.If you know the vault OCID:3. Cancel Deletion for Keys That Should Not Be Deleted
For each key inPENDING_DELETION that you want to keep:--endpoint:- KMS operations require the vault management endpoint, not the generic region endpoint.
- The above command dynamically fetches it from the vault.
PENDING_DELETION to ENABLED or DISABLED depending on previous state.4. Bulk Remediation (Optional)
To automatically cancel deletion for all keys inPENDING_DELETION in a compartment:PENDING_DELETION key should be rescued.5. (Optional) Monitoring via CLI Script
To periodically check and alert on keys inPENDING_DELETION using a simple CLI script (for cron or an automation server):- Run via cron and alert if
OUTPUTis non-empty. - Or parse
OUTPUTand integrate with your monitoring system.
If you share whether you want automatic cancellation vs just detection/alerting, I can refine the exact CLI/cron or shell script pattern.
Using Python
Using Python
Below is how to (1) detect KMS keys in
Use this for monitoring:
PENDING_DELETION state and (2) optionally cancel their deletion, using Python and the OCI SDK.1. Prerequisites
-
Install OCI Python SDK:
-
Configure OCI CLI config (if not already):
This creates
~/.oci/configwith:- tenancy
- user
- fingerprint
- key_file
- region
-
Ensure the user has permissions like:
(You only need
manageif you want to cancel deletion.)
2. Python: List Keys Pending Deletion (Monitoring)
This script lists all KMS keys inPENDING_DELETION in a given compartment and vault. You can wire it to cron / a scheduler or a monitoring system.- Feed output to a log/alerting system (e.g., send email/Slack if list not empty).
- Run periodically (cron, OCI Functions, etc.).
3. Python: Cancel Deletion for Keys (Remediation)
If you want to automatically remediate by cancelling deletion for all such keys:4. Recommended Workflow
- Monitoring script: Run periodically to detect keys in
PENDING_DELETION. - Alert first: Prefer to notify a security/ops team rather than auto-restore, for change control.
- Optional auto-remediation: Use the
cancel_key_deletionscript in a controlled environment, with logging and approvals if required.
Using Terraform
Using Terraform
terraform plan will only show normal create/update/destroy operations for oci_kms_key resources that Terraform already manages; it will not (and cannot) show cancellation of a pending key deletion, since that operation is not exposed via the Terraform provider.
