Repository navigation
fix(kms): store EnableKeyRotation's period, and stop DescribeKey inventing a member (#964, #971) - #975
Merged
Conversation
…nting a member (#964, #971) EnableKeyRotation decoded KeyId and nothing else, so RotationPeriodInDays was accepted and discarded. API_GetKeyRotationStatus publishes it as a response element with the identical 90-2560 range, so it is a value AWS expects a caller to write and read back: it is now range-checked, stored on the key record, and reported. GetKeyRotationStatus also gained the KeyId member it never answered, as the bare key ID whichever of the four forms the caller used. DescribeKey rendered RotationEnabled, which API_KeyMetadata does not publish at all. Removed, with rotation state left observable through the operation AWS publishes it on.
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.
Two halves of one defect: substrate did not report rotation state on the operation AWS publishes it
on, and did report it on the shape AWS omits it from.
Closes #964.
Closes #971.
#964 —
EnableKeyRotationdiscardedRotationPeriodInDaysThe handler decoded
KeyIdand nothing else, so a caller could set a custom rotation period, receive200, and find no trace of it anywhere.The issue's fourth criterion allowed for the value being unobservable, in which case the honest fix
was to validate and discard it. It is observable, and that was settled on the issue before any
code was written:
API_GetKeyRotationStatuspublishesRotationPeriodInDaysas a responseelement with the identical Valid Range of 90 to 2560. A range stated at both ends of a round trip
is a value AWS expects a caller to write and read back, so the period is now range-checked, stored on
KMSKey, and reported.GetKeyRotationStatusalso gained theKeyIdmember it never answered. It is the bare key IDwhichever of the four forms the caller addressed the key by, because the element is glossed only
"identifies the specified symmetric encryption KMS key" — none of the "Amazon Resource Name (key
ARN)" wording
ScheduleKeyDeletionandReEncryptuse for theirs — and the page's sample renders1234abcd-…. Echoing the request would be wrong for an alias or an ARN, not merely lazy.Three decisions that are substrate's, not AWS's
The refusal code is
ValidationError/400, fromCommonErrors, reached exactly as #963'swaiting-period range check reaches it and deliberately reused rather than re-argued: none of
API_EnableKeyRotation's seven errors (DependencyTimeoutException,DisabledException,InvalidArnException,KMSInternalException,KMSInvalidStateException,NotFoundException,UnsupportedOperationException) describes a parameter value out of range. Two range violations inone plugin answering two different codes would be the divergence #923 exists to prevent.
UnsupportedOperationExceptionis the near miss and is declined with its reason recorded: its glossdescribes an inadmissible parameter or resource — an asymmetric key, which is #972 — not an
admissible parameter carrying a number out of range. The message names 90 and 2560, because a caller
that sent 30 by analogy from the deletion window cannot discover the range from a bare refusal.
The range is checked before the key is resolved, so a bad period against an absent key answers
ValidationErrorrather thanNotFoundException— the value is wrong on the face of the request, andpointing at a missing key would tell the caller to fix the wrong thing. Same precedence as the
waiting period. AWS publishes none.
An omitted period resets to 365 on every call, not only the first. AWS states "if no value is
specified, the default value is 365 days" unconditionally, and documents the parameter as able to
"modify the rotation period of a key that you previously enabled automatic key rotation on" — so a
second call is a legitimate change rather than a conflict to refuse, and one that omits the member
takes the default. The intuitive opposite reading is the one most likely to be "fixed" in later, so it
is pinned against a failing test.
The member decodes into a
*intwhereScheduleKeyDeletion'sPendingWindowInDaysstays anint,and the asymmetry is the point:
0is well below the published minimum of 90, so collapsing anexplicit zero into the default would accept a value AWS refuses and report a period the caller never
asked for — #964's defect one level down rather than fixed.
PendingWindowInDaysdoes not need thesame treatment because AWS's default there coincides with the maximum a caller could plausibly have
meant.
DisableKeyRotationleaves the stored period alone — AWS documents no clearing — butGetKeyRotationStatusstops reporting it while rotation is off, per #827's honest-empty rule.#971 —
DescribeKeyreported a memberKeyMetadatadoes not publishAPI_KeyMetadatapublishes 26 members andRotationEnabledis not one of them; the string doesnot occur on the page at all. This is #765's failure mode aimed at a response member rather than at
state: a consumer could branch on
DescribeKey().KeyMetadata.RotationEnabledagainst the emulator,pass, and read an absent field from AWS.
The member is removed. The test asserts its absence against raw JSON both before and after
enabling rotation — a decoded struct cannot tell an omitted member from a
falseone, which is thewhole distinction — and then asserts rotation state is still readable through
GetKeyRotationStatus, so the removal is shown to have removed a duplicate route rather than the onlyone. No test asserted the member; nothing else read it.
Restoring it under another name would be worse than the original defect, because the rules the real
operation carries — the symmetric-only restriction, the key-state refusals, the documented
falsewhile a key is pending deletion — belong to
GetKeyRotationStatusand would all be bypassed.A wrong claim this release inherited, corrected on the record
kms_plugin.goanddocs/services.mdboth carried, from #949, the justification thatGetKeyRotationStatusneeds no key-state guard because "API_GetKeyRotationStatuspublishes neitherDisabledExceptionnorKMSInvalidStateException". It publishes the second, among six errors.The decision survives the correction, on better grounds: the page documents an answer for a
pending-deletion key — "while a KMS key is pending deletion, its key rotation status is
false… Ifyou cancel the deletion, the original key rotation status returns to
true" — and an operation thatdocuments an answer for a state cannot also be refusing that state. So the published code belongs to
the four states substrate never writes. The claim is corrected rather than left standing, because it
was the stated reason for not guarding.
Scope deliberately cut, and filed
NextRotationDateneeds the date rotation was enabled, which nothing stores; and a key pendingdeletion reports its stored status where AWS documents
false— both kms: GetKeyRotationStatus omits NextRotationDate, and a key pending deletion reports its stored rotation status where AWS reports false #973.OnDemandRotationStartDateis blocked on the unimplementedRotateKeyOnDemand. AWS's own sampleresponse omits it too.
UnsupportedOperationException/400, arekms: EnableKeyRotation and DisableKeyRotation accept an asymmetric or HMAC key, where AWS publishes UnsupportedOperationException/400 #972.
KeyMetadatamembers substrate does not answer are kms: DescribeKey answers 10 of KeyMetadata's 26 members, omitting AWSAccountId, KeyManager and Origin #974.kms:RotationPeriodInDaysas a condition key, and theEnableKeyRotationNo /GetKeyRotationStatusYes cross-account asymmetry, are recorded indocs/services.mdand notmodelled.
Tests
emulator/kms_rotation_period_test.go, eight tests, every call over the wire per #765 and everyrefusal pairing code with status per #923:
afterwards — a handler validating after the write would satisfy the code assertion and still have
turned rotation on;
ValidationError, notNotFoundException;KeyIdis the bare key ID whether the caller sent an ID or an ARN;re-enable that omits it — all read from raw JSON, since presence is the assertion;
DescribeKeyreports noRotationEnabled, before and after enabling.kmsCryptoRefusalwas renamedkmsRefusal(10 sites) rather than duplicated: a range violation hasto name its range, so these tests need the same status/code/message triple for the same kind of
reason.
Mutation-tested: dropping the range check, preserving the period on an omitted member, reporting the
period unconditionally, echoing the ARN as
KeyId, and restoringRotationEnabledonDescribeKeyare each caught.
Verification
The nine-command gate passes. Coverage 84.4% emulator / 83.9% total, above the 84.3% / 83.8%
baseline.
Compatibility
RotationPeriodInDaysnow answersValidationError/400 where it previouslyanswered
200.GetKeyRotationStatusgainsKeyIdand, while rotation is on,RotationPeriodInDays.DescribeKey'sKeyMetadatano longer carriesRotationEnabled. A caller reading it must callGetKeyRotationStatusand readKeyRotationEnabledinstead.