Repository navigation
Description
EnableKey and DisableKey check no key state, so EnableKey on a key pending deletion succeeds — routing around the two-step recovery #963 just established.
Found while implementing #963. It is the last member of the key-state class in this package: #949 fixed the rotation pair, #961 covers the three cryptographic operations, #963 the deletion pair, and these two are what remains.
Why this one matters more than a missing refusal usually does
#963 made CancelKeyDeletion leave a key Disabled, because API_CancelKeyDeletion says recovery from a scheduled deletion is two calls: "when this operation succeeds, the key state of the KMS key is Disabled. To enable the KMS key, use EnableKey."
But EnableKey refuses nothing, so a caller can skip the first call entirely: EnableKey against a key in PendingDeletion answers 200 and writes KeyState: Enabled, Enabled: true. That is a one-call path from pending deletion to usable, which AWS does not have — and it means the guarantee #963 added can be routed around by an operation in the same file.
It also leaves substrate's own state readable in a way AWS's is not: the deletion is silently abandoned with no record that it ever existed, because #963's setKeyState clears DeletionDate on the way through.
What AWS publishes, verified
Both operations have identical rows in the developer guide's Key states of AWS KMS keys table:
| Key state | EnableKey / DisableKey |
Footnote |
|---|---|---|
Enabled |
permitted | — |
Disabled |
permitted | — |
PendingDeletion (and PendingReplicaDeletion) |
refused | [3] — KMSInvalidStateException: <key ARN> is pending deletion (or pending replica deletion). |
PendingImport |
refused | [5] — KMSInvalidStateException: <key ARN> is pending import because no key material has ever been imported or one of the imported key materials is deleted or expired. |
Unavailable |
permitted | [12] — "The operation succeeds, but the key state of the KMS key does not change until it becomes available." |
Creating |
refused | [14] — KMSInvalidStateException: <key ARN> is creating. |
Updating |
refused | [15] — KMSInvalidStateException: <key ARN> is updating. |
PendingDeletion is the only refused row substrate can reach; ScheduleKeyDeletion remains its sole writer of anything but Enabled or Disabled, so the other four are unreachable and belong on the record rather than in code — the disposition #949 and #963 both took.
Note the Unavailable row is a success with a deferred effect, not a refusal. It is the one row in this table for these two operations that is neither a plain ✓ nor an ✗, and it is unreachable here for the same reason — worth recording so a later sweep does not read [12] as a refusal.
What substrate does
enableKey and disableKey both delegate to setKeyState (kms_plugin.go), which resolves the key, loads it, refuses only a missing key, and then assigns whatever state it was handed. #963 gave cancelKeyDeletion its own body precisely because that helper checks nothing; these two still go through it.
The guard is one condition and it is the same one on both, so unlike #963 this is a small change. The design question it raises is where the check belongs: in setKeyState, which both callers share, or in each handler. setKeyState has exactly two callers and both want the identical refusal, so the shared helper looks right — but it is also the helper #963 deliberately stopped using, so a note saying why it is the right home here (both callers refuse the same single state, where CancelKeyDeletion required the opposite state and a different body) is worth more than the code.
Acceptance criteria
-
EnableKeyandDisableKeyagainst a key inPendingDeletionanswerKMSInvalidStateException/400, per footnote[3]. The existingkmsInvalidKeyStatehelper (kms_errors.go) is the constructor — footnote[3]names the state, so no sibling is needed as it was for[4]. - The refusal wrote nothing: the key is still
PendingDeletion, still has itsDeletionDate, and the date is unchanged — read back throughDescribeKey, per cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765 and kms: ScheduleKeyDeletion and CancelKeyDeletion check no key state, and CancelKeyDeletion leaves the key Enabled where AWS leaves it Disabled #963's ordering rule that the check precedes the write. - The documented recovery still works and is the only path:
CancelKeyDeletionthenEnableKeysucceeds, and a test showsEncryptrefusing between the two steps and succeeding after — so the two-step sequence is asserted end to end rather than each step in isolation. - The nominal paths are untouched:
EnableKeyandDisableKeystill succeed fromEnabledand fromDisabled, in both directions and repeatedly, so the guard is a function of the current state rather than of anything the key remembers. - Where the check lives is decided and the reason recorded, given that kms: ScheduleKeyDeletion and CancelKeyDeletion check no key state, and CancelKeyDeletion leaves the key Enabled where AWS leaves it Disabled #963 moved one caller off
setKeyState. -
PendingImport,CreatingandUpdatingare recorded as unreachable, andUnavailableis recorded as a permitted-but-deferred row rather than a refusal, so footnote[12]is not later mistaken for one. - Tests assert the status and the code, per fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923, and go over the wire, per cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765.
-
docs/services.md's KMS section records these two rows beside the key-state sections kms: EnableKeyRotation and DisableKeyRotation succeed against a disabled key, where AWS publishes DisabledException/400 #949 and kms: ScheduleKeyDeletion and CancelKeyDeletion check no key state, and CancelKeyDeletion leaves the key Enabled where AWS leaves it Disabled #963 added, and notes that the class is then complete except for kms: Encrypt, Decrypt and GenerateDataKey answer DisabledException for a key pending deletion, where AWS publishes KMSInvalidStateException #961.
Activity
fix(kms): the five cryptographic operations check a key state, and Re…
fix(kms): EnableKey and DisableKey refuse a key pending deletion (#968)…