Repository navigation
fix(kms): EnableKeyRotation and DisableKeyRotation check the key state (#949) - #962
Merged
Merged
Conversation
#949) Both operations carry the sentence "the KMS key that you use for this operation must be in a compatible key state" and publish an identical seven-error list, and substrate checked nothing: it wrote RotationEnabled and answered 200 whatever the key was. #923 recorded the gap while correcting DisabledException's status and named it as a missing refusal rather than folding it into a status change. The two forbidding states answer different codes, and that is the whole of the fix. The developer guide's "Key states of AWS KMS keys" table gives these two operations one row each with identical contents: a Disabled key is footnote [1], "DisabledException: <key ARN> is disabled", while a key pending deletion is footnote [3], "KMSInvalidStateException: <key ARN> is pending deletion". Both states are reachable in substrate, because ScheduleKeyDeletion writes the state and clears the enabled flag in a single write, so a lone !key.Enabled test would have answered DisabledException for a key pending deletion — the wrong one of the two codes AWS publishes, and one that points a caller at the wrong remedy: enable the key and retry, versus cancel the deletion and retry. PendingDeletion is checked first, and a new KMSInvalidStateException helper joins the four kms_errors.go already had. The check runs before the write, so a refused call leaves RotationEnabled as it was. That is asserted by reading it back through GetKeyRotationStatus over the wire rather than by inspecting state, since a guard placed after the assignment would answer the right code while having already changed the value. GetKeyRotationStatus is deliberately not guarded, and a test pins it. Its row in the same table permits Enabled, Disabled and PendingDeletion alike and API_GetKeyRotationStatus publishes neither code, so a later sweep guarding "every key-state-sensitive operation" cannot quietly introduce a refusal AWS does not have. The four remaining states AWS's table refuses — PendingImport, Unavailable, Creating, Updating — are recorded as unreachable rather than implemented, because ScheduleKeyDeletion is substrate's only writer of a state other than Enabled or Disabled: no caller can reach them, and a guard for them could only be exercised by fabricating a key record. Left open by the same reading and filed as #961: Encrypt, Decrypt and GenerateDataKey answer DisabledException for a key pending deletion, where their pages publish KMSInvalidStateException beside it. Widening this change to three cryptographic operations would put a separate wire change in the same diff. kmsKeyStatePendingDeletion becomes a constant while Enabled and Disabled stay literals, because it is the one key state substrate compares against rather than only writes: a typo in either the writer or the guard would silently stop the guard from firing instead of failing to compile. Compatibility: EnableKeyRotation and DisableKeyRotation against a disabled key now answer DisabledException/400 where they answered 200, and against a key scheduled for deletion KMSInvalidStateException/400. A caller that turned rotation on or off before disabling or scheduling the key sees no change, and neither does GetKeyRotationStatus in any state. Mutation-checked: dropping the PendingDeletion arm, and moving enableKeyRotation's guard to after the assignment, fail 9 of these tests between them; all pass against the change. Coverage: 84.4% emulator / 83.9% total, unchanged. Closes #949.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both operations carry the sentence "the KMS key that you use for this operation must be in a compatible key state" and publish an identical seven-error list, and substrate checked nothing: it wrote
RotationEnabledand answered200whatever the key was. #923 recorded the gap while correctingDisabledException's status and named it as a missing refusal rather than folding it into a status change.The two forbidding states answer different codes, and that is the whole of the fix
The developer guide's Key states of AWS KMS keys table gives these two operations one row each with identical contents:
Enabled200DisabledDisabledException/400[1]— "DisabledException:<key ARN>is disabled"PendingDeletionKMSInvalidStateException/400[3]— "KMSInvalidStateException:<key ARN>is pending deletion (or pending replica deletion)"Both states are reachable in substrate, because
ScheduleKeyDeletionwritesKeyStateand clearsEnabledin a single write. So a lone!key.Enabledtest — the obvious reading of the issue title — would have answeredDisabledExceptionfor a key pending deletion: the wrong one of the two codes AWS publishes, and one that points a caller at the wrong remedy (enable the key and retry versus cancel the deletion and retry).PendingDeletionis therefore checked first, and a newKMSInvalidStateExceptionhelper joins the fourkms_errors.goalready had.The check runs before the write, so a refused call leaves
RotationEnabledas it was — asserted by reading it back throughGetKeyRotationStatusover the wire rather than by inspecting state, since a guard placed after the assignment would answer the right code while having already changed the value.GetKeyRotationStatusis deliberately not guardedIts row in the same table permits
Enabled,DisabledandPendingDeletionalike, andAPI_GetKeyRotationStatuspublishes neither code. A test pins that, so a later sweep guarding "every key-state-sensitive operation" for consistency with its two siblings cannot quietly introduce a refusal AWS does not have.Recorded rather than implemented
The four remaining states AWS's table refuses —
PendingImport,Unavailable,Creating,Updating— are unreachable:ScheduleKeyDeletionis substrate's only writer of a state other thanEnabledorDisabled, so no caller can reach them and a guard for them could only be exercised by fabricating a key record, which proves nothing about the wire.Out of scope, and filed:
Encrypt,DecryptandGenerateDataKeyanswerDisabledExceptionfor a key pending deletion, where their own pages publishKMSInvalidStateExceptionat 400 beside it and their table rows are footnote[3]too. That is #961; widening this change to three cryptographic operations would put a separate wire change in the same diff.kmsKeyStatePendingDeletionbecomes a constant whileEnabledandDisabledstay literals, because it is the one key state substrate compares against rather than only writes: a typo in either the writer or the guard would silently stop the guard from firing instead of failing to compile.Tests
emulator/kms_rotation_key_state_test.go— every call over the wire, every state reached through the operation a consumer would use (DisableKey,ScheduleKeyDeletion) rather than by writing a key record, per #765.DisableKeyRotationis refused, so a handler that assigned before guarding reports the wrong value where no ordering of a correct implementation does.GetKeyRotationStatusanswers200against a disabled and a pending-deletion key, and still reports the value set before the state changed.RotationEnabledinstead of the key state would refuse), and a key re-enabled afterDisableKeyrotates again — so the refusals are a function of the current state rather than of anything the key remembers. Without this, a handler refusing every key would satisfy every other assertion in the file.Mutation-checked: dropping the
PendingDeletionarm, and movingenableKeyRotation's guard to after the assignment, fail 9 of these tests between them; all pass against the change.Coverage: 84.4% emulator / 83.9% total, unchanged.
Compatibility
EnableKeyRotationandDisableKeyRotationagainst a disabled key now answerDisabledException/400 where they answered200, and against a key scheduled for deletionKMSInvalidStateException/400. A caller that turned rotation on or off before disabling or scheduling the key sees no change, and neither doesGetKeyRotationStatusin any state.Closes #949.