Repository navigation
Description
EnableKeyRotation and DisableKeyRotation publish DisabledException, and substrate does not check whether the key is enabled — both answer 200 against a disabled key.
Surfaced while verifying #923's statuses page by page. It is a missing refusal rather than a wrong status, which is why it was deliberately not folded into that PR: #923 changed what a status is worth and this changes whether a request is refused at all.
What AWS publishes
API_EnableKeyRotation and API_DisableKeyRotation both list DisabledException at HTTP 400:
The request was rejected because the specified KMS key is not enabled.
API_EnableKeyRotation's own prose is explicit about the state requirement: "The KMS key that you use for this operation must be in a compatible key state."
Note the asymmetry, which is the reason this needs a per-operation check rather than a shared one: API_GetKeyRotationStatus does not publish DisabledException, and neither does API_EnableKey. So reading the rotation status of a disabled key is fine, and enabling or disabling rotation on one is not.
What substrate does
enableKeyRotation (emulator/kms_plugin.go:646) and disableKeyRotation (:673) both resolve the key, refuse a missing one with NotFoundException, then write RotationEnabled and answer 200. Neither reads key.Enabled.
The three sites that do check it — encrypt, decrypt, generateDataKey — go through kmsKeyDisabled (emulator/kms_errors.go), so the code and status are already right and in one place; this is two call sites, not a new error path. kmsKeyDisabled's doc comment already names this gap.
Consequence for a consumer
A test that disables a key and then asserts its rotation cannot be changed passes against AWS and fails against substrate — the wrong direction, since the whole point is that a substrate run predicts an AWS run. Worse, the write succeeds: RotationEnabled flips on a key that cannot perform a cryptographic operation, so a later GetKeyRotationStatus reports a state real KMS would never have produced. That is state divergence rather than a missing error, which is why it is worth an issue rather than a note.
Acceptance criteria
-
EnableKeyRotationagainst a disabled key answersDisabledException/400, throughkmsKeyDisabled. -
DisableKeyRotationagainst a disabled key answersDisabledException/400, throughkmsKeyDisabled. - Neither writes
RotationEnabledwhen it refuses — asserted by readingGetKeyRotationStatusafterwards through the wire and finding the value unchanged, not by inspecting state. -
GetKeyRotationStatusagainst a disabled key still answers 200, becauseAPI_GetKeyRotationStatusdoes not publishDisabledException. A test pins this, so a later "checkEnabledeverywhere" sweep cannot quietly break it. - A key in
PendingDeletionis considered:KMSInvalidStateException/400 is published on both operations, and whether substrate'sScheduleKeyDeletionleaves a key that these two must refuse needs checking rather than assuming. Either implement it or record why the state is not reachable. - Wire tests assert the status and the code, per fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923's finding that a code alone let a wrong status stand.
-
docs/services.md's KMS error section — added by fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923 — has this row moved out of "named rather than closed".
Activity
fix(kms): the five cryptographic operations check a key state, and Re…
fix(kms): rotation checks the key type, and reports when the next one…