Skip to content

fix(kms): store EnableKeyRotation's period, and stop DescribeKey inventing a member (#964, #971) - #975

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/kms-rotation-period
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/kms-rotation-period

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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 — EnableKeyRotation discarded RotationPeriodInDays

The handler decoded KeyId and nothing else, so a caller could set a custom rotation period, receive
200, 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_GetKeyRotationStatus publishes RotationPeriodInDays as a response
element 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.

GetKeyRotationStatus also gained the KeyId member it never answered. It is the bare key ID
whichever 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 ScheduleKeyDeletion and ReEncrypt use for theirs — and the page's sample renders
1234abcd-…. 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, from CommonErrors, reached exactly as #963's
waiting-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 in
one plugin answering two different codes would be the divergence #923 exists to prevent.
UnsupportedOperationException is the near miss and is declined with its reason recorded: its gloss
describes 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
ValidationError rather than NotFoundException — the value is wrong on the face of the request, and
pointing 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 *int where ScheduleKeyDeletion's PendingWindowInDays stays an int,
and the asymmetry is the point: 0 is well below the published minimum of 90, so collapsing an
explicit 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. PendingWindowInDays does not need the
same treatment because AWS's default there coincides with the maximum a caller could plausibly have
meant.

DisableKeyRotation leaves the stored period alone — AWS documents no clearing — but
GetKeyRotationStatus stops reporting it while rotation is off, per #827's honest-empty rule.

#971 — DescribeKey reported a member KeyMetadata does not publish

API_KeyMetadata publishes 26 members and RotationEnabled is not one of them; the string does
not 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.RotationEnabled against 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 false one, which is the
whole 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 only
one. 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 false
while a key is pending deletion — belong to GetKeyRotationStatus and would all be bypassed.

A wrong claim this release inherited, corrected on the record

kms_plugin.go and docs/services.md both carried, from #949, the justification that
GetKeyRotationStatus needs no key-state guard because "API_GetKeyRotationStatus publishes neither
DisabledException nor KMSInvalidStateException"
. 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 … If
you cancel the deletion, the original key rotation status returns to true"
— and an operation that
documents 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

Tests

emulator/kms_rotation_period_test.go, eight tests, every call over the wire per #765 and every
refusal pairing code with status per #923:

  • the period round-trips at both published bounds, at 365 and at AWS's own example value of 180;
  • an absent member reports as 365;
  • 0, -1, 89, 2561 and 30 are each refused with the range named, and rotation is still off
    afterwards
    — a handler validating after the write would satisfy the code assertion and still have
    turned rotation on;
  • a bad period against an absent key answers ValidationError, not NotFoundException;
  • a second call modifies the period, and a second call omitting it resets to 365;
  • KeyId is the bare key ID whether the caller sent an ID or an ARN;
  • the period is absent before the first enable, present while on, absent once disabled, and 365 on a
    re-enable that omits it — all read from raw JSON, since presence is the assertion;
  • DescribeKey reports no RotationEnabled, before and after enabling.

kmsCryptoRefusal was renamed kmsRefusal (10 sites) rather than duplicated: a range violation has
to 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 restoring RotationEnabled on DescribeKey
are each caught.

Verification

The nine-command gate passes. Coverage 84.4% emulator / 83.9% total, above the 84.3% / 83.8%
baseline.

Compatibility

  • An out-of-range RotationPeriodInDays now answers ValidationError/400 where it previously
    answered 200.
  • GetKeyRotationStatus gains KeyId and, while rotation is on, RotationPeriodInDays.
  • DescribeKey's KeyMetadata no longer carries RotationEnabled. A caller reading it must call
    GetKeyRotationStatus and read KeyRotationEnabled instead.

…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.
@scttfrdmn scttfrdmn added this to the v0.118.0 milestone Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 3fdb724 into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/kms-rotation-period branch September 17, 2026 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant