AWS KMS密钥删除失败,因未等待待删除期结束
AWS KMS key deletion failed due to pending deletion without waiting period
ID: security/aws-kms-key-deletion-without-wait-period
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| AWS KMS API 2014-11-01 | active | — | — | — |
| AWS SDK for Python (boto3) 1.26.0 | active | — | — | — |
| AWS CLI 2.x | active | — | — | — |
| Terraform AWS Provider 5.0.0 | active | — | — | — |
根因分析
AWS KMS要求在计划删除密钥后必须等待一个强制等待期(默认7-30天)才能实际删除密钥;在等待期内尝试删除会导致失败。
English
AWS KMS requires a mandatory waiting period (default 7-30 days) after scheduling key deletion before the key is actually deleted; attempting to delete immediately or within the waiting period results in a failure.
官方文档
https://docs.aws.amazon.com/kms/latest/developerguide/deleting-keys.html解决方案
-
Schedule key deletion and wait for the waiting period. In AWS CLI: aws kms schedule-key-deletion --key-id 1234abcd-12ab-34cd-56ef-1234567890ab --pending-window-in-days 7 Then wait 7 days before the key is actually deleted. To cancel deletion, use: aws kms cancel-key-deletion --key-id 1234abcd-12ab-34cd-56ef-1234567890ab
-
Use Terraform to manage key lifecycle with a 'deletion_window_in_days' parameter: resource "aws_kms_key" "my_key" { description = "Example KMS key" deletion_window_in_days = 7 } Terraform will schedule deletion and wait, but you must ensure the resource is destroyed after the window. -
If immediate deletion is required, create a new key and rotate usage to it, then schedule the old key for deletion. This avoids downtime while waiting for the deletion period.
无效尝试
常见但无效的做法:
-
Force delete the key by disabling it first and then deleting
95% 失败
Disabling a key does not bypass the deletion waiting period; the key must still be scheduled for deletion and wait.
-
Use the AWS CLI 'delete-key' command with '--force' flag (which does not exist)
100% 失败
The AWS CLI does not have a force delete option for KMS keys; the command will fail with an invalid parameter error.
-
Delete the CloudFormation stack that created the key, assuming it will cascade delete
80% 失败
CloudFormation does not force delete KMS keys; it will schedule deletion and wait, causing stack deletion to hang or fail.