Repository navigation
fix(kms): rotation checks the key type, and reports when the next one is (#972, #973) - #981
Merged
scttfrdmn merged 1 commit intoSep 17, 2026
Conversation
… is (#972, #973) EnableKeyRotation and DisableKeyRotation checked the period's range (#964) and the key state (#949) and never checked what kind of key they were pointed at, so EnableKeyRotation on an RSA key answered 200 and wrote the flag — after which GetKeyRotationStatus reported a rotation schedule for a key AWS will never rotate. Both now answer UnsupportedOperationException/400, with the key type checked before the key state: a key state has a remedy and a key type has none, so answering the state first would send a caller round a loop that cannot terminate. The discriminator is KeySpec rather than KeyUsage, so one comparison covers every family AWS names and the two it implies. GetKeyRotationStatus answered two of its five published members, and one of the two answers was wrong. NextRotationDate is now reported as the enable date plus the period — KMSKey gained the enable date for this and nothing else — as Unix seconds, matching DescribeKey's DeletionDate; AWS's own page types the member number and renders it ISO-8601 in its sample, so keeping one convention is substrate's reading. A key pending deletion now reports false, per the sentence AWS publishes for that state, and the status is derived at read time rather than written by ScheduleKeyDeletion, because the second half of the same sentence requires CancelKeyDeletion to have something to restore. The period and the date follow the reported status, so a key pending deletion reports neither. GetKeyRotationStatus is deliberately not refused for a key that cannot rotate, and a test pins that: the sentence forbids enabling rotation, not asking about it.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
scttfrdmn
deleted the
feat/kms-rotation-key-type-and-next-rotation-date
branch
September 17, 2026 04:24
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.
Closes #972.
Closes #973.
The rotation trio owed three conditions and checked one and a half. #964 added the period's range, #949 added the key state, and neither issue looked at the key type — nor at what
GetKeyRotationStatusactually answers, which turned out to be wrong in one state rather than merely incomplete. Both halves touch the same two handlers and the same response builder, so they ship together.#972 — a key type can forbid rotation permanently
EnableKeyRotationon an RSA key answered200and wroteRotationEnabled, after whichGetKeyRotationStatusreported a rotation schedule for a key AWS will never rotate. AWS states the restriction twice onAPI_EnableKeyRotationand repeats it verbatim onAPI_DisableKeyRotationandAPI_GetKeyRotationStatus: "automatic key rotation is supported only on symmetric encryption KMS keys. You cannot enable automatic rotation of asymmetric KMS keys, HMAC KMS keys, KMS keys with imported key material, or KMS keys in a custom key store."Both operations now answer
UnsupportedOperationException/400 — the inadmissible-resource case whose gloss #964 declined to borrow for an out-of-range number.DisableKeyRotationrefuses it too, although turning rotation off on a key that will never rotate looks harmless; that is the argument #949 rejected for the key state, and the pages carry the identical sentence and the identical seven-error list.Three decisions worth naming:
KeySpec, notKeyUsage. One equality test againstSYMMETRIC_DEFAULTcovers every family AWS names and the two it implies — asymmetric encryption, asymmetric signing,SM2, HMAC, ML-DSA — where aKeyUsagetest would let anENCRYPT_DECRYPTRSA key through. The message names the spec it found, because the code is otherwise indistinguishable from the AWS-managed-key refusal a caller might expect.EnableKey, orCancelKeyDeletionthenEnableKey) and a key type has none, so telling a caller with a disabled RSA key to enable the key sends it round a loop that cannot terminate. Same request-before-resource principle as kms: EnableKeyRotation decodes only KeyId, so RotationPeriodInDays is accepted and discarded #964's range check.GetKeyRotationStatusis deliberately not refused for such a key, and a test pins that. The sentence forbids enabling rotation, not asking whether it rotates; the operation's key-state row permits the read; andfalsefor a key that will never rotate is a true answer.Three of AWS's five restrictions stay unenforced because they are unreachable rather than unguarded — imported key material, a custom key store and an AWS managed key each need a
KMSKeymember substrate does not model, so no request can produce one. Every non-symmetric key in the tests is created through the gap #977 records (CreateKeyvalidatesKeySpecagainst nothing), which is why #977 has to re-verify these tests when it closes it.#973 —
NextRotationDate, and the answer for a key pending deletionThe member was missing entirely, and it is the one rotation-monitoring code reads. AWS defines it on
API_EnableKeyRotationrather than where it is reported — "the rotation period defines the number of days after you enable automatic key rotation that AWS KMS will rotate your key material, and the number of days between each automatic rotation thereafter" — so it is the enable date plus the period, and substrate held only the period.KMSKeygainedRotationEnabledDatefor this and nothing else. It is reported as Unix seconds, matching whatDescribeKeydoes withDeletionDate.A second
EnableKeyRotationoverwrites the enable date, which AWS does not address. The alternative argues for it: a key enabled with 2560 days and re-enabled with 90 would otherwise report a next rotation date roughly six years in the past.DisableKeyRotationleaves both the period and the date alone; what changes is whether they are reported.A key pending deletion reported the stored flag, and AWS publishes
false: "while a KMS key is pending deletion, its key rotation status isfalseand AWS KMS does not rotate the key material. If you cancel the deletion, the original key rotation status returns totrue." A caller polling a key it had scheduled for deletion was told rotation was still on. That was a wrong value rather than a missing refusal, which is the distinction that kept it out of #949 — that issue read the same two sentences as a reason not to guard the operation and stopped there.The second sentence forces the shape of the fix. The reported status is derived from the stored flag and the key state at read time rather than written by
ScheduleKeyDeletion, because there has to be something left to restore from. An implementation that cleared the flag on the way in would satisfy the first sentence and make the second unimplementable, and no state inspection would tell the two apart — so the test walks enable → schedule → cancel and asserts the original date comes back rather than a fresh one counted from the cancel. The period and the date follow the reported status, so a key pending deletion reports neither: answering a schedule beside afalsestatus would describe a rotation AWS has just said will not happen.OnDemandRotationStartDatestays absent, and every read in the new test file asserts that rather than one test doing so. It reports an in-progressRotateKeyOnDemand, which substrate does not implement, so no request can set it and a zero timestamp would report a rotation nobody started.Two existing tests changed, and why that is the finding
kms_rotation_key_state_test.gowas asserting the wrong one of the two documented values: it read the stored flag back in both states and required it unchanged in both, which is right forDisabledand wrong for pending deletion. Both assertions now follow the sentence for each state, and theDisableKeyRotationhalf goes one step further — it cancels the deletion and readstrueback, so the stored flag is still shown to have survived the refusal in the state where the read-back would otherwise see only #973's derivedfalse. Without that step the strongest half of #949's third criterion would be invisible in exactly the state where the guard is newest.Provenance
UnsupportedOperationException/400 and its gloss; the pending-deletionfalseand its restoration on cancel;NextRotationDate's definition, viaAPI_EnableKeyRotation's definition of a rotation period; the 90–2560 range at both ends of the round trip.numberin its Response Syntax and rendering"2024-02-14T18:14:33.587000+00:00"in its sample, so one KMS timestamp convention is a choice rather than a match.Verification
Nine-command gate green. Coverage 84.4% emulator / 83.9% total, above the 84.3/83.8 baseline. Five mutants introduced and all five caught: swapping the two guards' order, reporting the stored flag instead of deriving it, keeping the first enable date on a re-enable, dropping the key-spec guard from
DisableKeyRotation, and reporting the schedule while rotation is off.