Skip to content

kms: EnableKeyRotation decodes only KeyId, so RotationPeriodInDays is accepted and discarded #964

Closed

Description

@scttfrdmn

EnableKeyRotation decodes only KeyId, so RotationPeriodInDays is accepted, discarded and unreportable.

Found while implementing #949, which fixes the same handler's missing key-state check. This is the other half of what the operation publishes and is a separate defect: #949 is about a refusal that never happened, this is about a parameter that is never read.

What AWS publishes

API_EnableKeyRotation takes two parameters:

  • KeyId — String, 1–2048, Required: Yes.
  • RotationPeriodInDays — Integer, Valid Range: Minimum value of 90. Maximum value of 2560, Required: No. "Specifies a custom period of time between each rotation date. If no value is specified, the default value is 365 days."

What substrate does

enableKeyRotation (kms_plugin.go) decodes exactly one member:

var input struct {
    KeyID string `json:"KeyId"`
}

So a caller specifying a 90-day rotation gets 200 and nothing recorded, and there is nowhere to read it back from: KMSKey (kms_types.go) has RotationEnabled bool and no period field, and GetKeyRotationStatus answers only KeyRotationEnabled.

That last point is worth checking before implementing rather than assuming — API_GetKeyRotationStatus publishes more response elements than substrate answers, and whether the period is among them decides whether recording it is observable at all. If it is not reportable through any operation substrate models, the honest fix may be to refuse an out-of-range value and record the rest as unobservable, rather than to store a value nothing can read — the reasoning #827 established for honest-empty behaviour, applied to a write.

Related and separate: ListKeyRotations and RotateKeyOnDemand are not implemented at all (they are absent from HandleRequest's switch, so they answer unknownActionError). Both appear in the key-state table with the same rows as EnableKeyRotation. They are not part of this issue.

Acceptance criteria

  • Determine from API_GetKeyRotationStatus and API_ListKeyRotations which response members carry the rotation period, and record the finding — it decides whether the value is observable.
  • RotationPeriodInDays outside 90–2560 is refused; 90 and 2560 are both accepted, so the refusal cannot be off by one. AWS publishes no code for the range violation on this page, so the code is substrate's reading and is stated as such.
  • An absent RotationPeriodInDays behaves as 365, per "if no value is specified, the default value is 365 days".
  • The value is either reportable through an operation substrate models, or recorded as accepted-and-unobservable with the reason — not stored where nothing can read it.
  • Tests assert the status and the code, per fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923, and go over the wire, per cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765.
  • docs/services.md's KMS section records the parameter and whatever the observability finding turns out to be.

Activity

  1. added this to the v0.118.0 milestone on Sep 17, 2026
  2. added
    type: bug
    on Sep 17, 2026
  3. scttfrdmn commented on Sep 17, 2026

    @scttfrdmn
    OwnerAuthor

    AC 1 is answered, and it resolves the fork in favour of storing the value

    The issue's first criterion asked whether RotationPeriodInDays is observable through any operation
    substrate models, because "if it is not reportable through any operation substrate models, the honest
    fix may be to refuse an out-of-range value and record the rest as unobservable"
    . It is reportable.
    API_GetKeyRotationStatus publishes it as a response element, verbatim:

    RotationPeriodInDays — The number of days between each automatic rotation. The default value is
    365 days.
    Type: Integer
    Valid Range: Minimum value of 90. Maximum value of 2560.

    The range matches EnableKeyRotation's request parameter exactly, and the page's own sample response
    carries it:

    {
        "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab",
        "KeyRotationEnabled": true,
        "NextRotationDate": "2024-02-14T18:14:33.587000+00:00",
        "RotationPeriodInDays": 365
    }

    So the value a caller writes through EnableKeyRotation is readable back through an operation substrate
    already implements. The honest-empty branch does not apply, and the fix is the full one: decode the
    member, range-check it, store it, and report it. AC 4 is satisfied by reporting it from
    GetKeyRotationStatus rather than by recording it as unobservable.

    API_EnableKeyRotation also settles a second thing the issue did not ask, and it is the reason the
    member is worth storing rather than merely validating — the parameter is not write-once:

    You can use the optional RotationPeriodInDays parameter to specify a custom rotation period when you
    enable key rotation, or you can use RotationPeriodInDays to modify the rotation period of a key
    that you previously enabled automatic key rotation on
    .

    A second EnableKeyRotation with a different period therefore changes the stored value, which is an
    assertable behaviour and will get its own test.

    AC 2: the code for a range violation is ValidationError/400, following the in-tree precedent

    AC 2 anticipated correctly that AWS publishes no code for the range violation on the operation page.
    API_EnableKeyRotation's seven errors are DependencyTimeoutException/500, DisabledException/400,
    InvalidArnException/400, KMSInternalException/500, KMSInvalidStateException/400,
    NotFoundException/400 and UnsupportedOperationException/400 — none of which is a range violation.

    UnsupportedOperationException is the near miss and is deliberately not chosen: its gloss is "a
    specified parameter is not supported or a specified resource is not valid for this operation"
    , which is
    about a parameter or resource being inadmissible, not about an admissible parameter carrying an
    out-of-range value. It is the code for the symmetric-only restriction instead (filed separately, below).

    The code is ValidationError/400 from CommonErrors.html, with a message naming both the value and the
    range — which is not a fresh decision but the existing one in this exact file. kmsInvalidPendingWindow
    (kms_errors.go:159-167) already does precisely this for ScheduleKeyDeletion's 7–30 window: same
    shape of defect, same protocol layer, same code. Two range violations in one plugin answering two
    different codes would be the divergence #923 exists to prevent, so this one follows it.

    90 and 2560 will both be accepted, per AC 2, so the bound cannot be off by one.

    A defect this turned up, which is the mirror image of #964

    While confirming where rotation state is observable, the opposite error turned out to be present:
    substrate reports rotation state where AWS does not publish it.

    DescribeKey's KeyMetadata (kms_plugin.go:389) renders a member RotationEnabled:

    metadata := map[string]interface{}{
    	...
    	"RotationEnabled": key.RotationEnabled,
    	...
    }

    API_KeyMetadata has no such member. Its Contents section lists 26 — KeyId, Arn,
    AWSAccountId, CloudHsmClusterId, CreationDate, CurrentKeyMaterialId, CustomerMasterKeySpec,
    CustomKeyStoreId, DeletionDate, Description, Enabled, EncryptionAlgorithms,
    ExpirationModel, KeyAgreementAlgorithms, KeyManager, KeySpec, KeyState, KeyUsage,
    MacAlgorithms, MultiRegion, MultiRegionConfiguration, Origin,
    PendingDeletionWindowInDays, SigningAlgorithms, ValidTo, XksKeyConfiguration — and
    RotationEnabled is not among them. The string does not appear on the page at all. Rotation state is
    reachable through GetKeyRotationStatus and ListKeyRotations only, which is exactly why
    API_EnableKeyRotation tells a caller "You can use the GetKeyRotationStatus operation to identify any
    in progress rotations"
    rather than pointing at DescribeKey.

    So substrate publishes rotation state on the one shape AWS omits it from, and omits the period from the
    one operation AWS publishes it on. That is one defect seen from two ends, and a consumer can be misled
    in a way worth spelling out: a caller who reads DescribeKey().KeyMetadata.RotationEnabled against
    substrate gets an answer, and against real AWS gets an absent field — a green test for code that cannot
    work. That is the #765 failure mode applied to a response member.

    Filed as its own issue rather than folded in silently, and the #964 PR will close both, because
    answering where rotation state is observable is the whole content of AC 1 and correcting the wrong
    place is the same change. No test asserts the member today — a repo-wide grep finds the KMS assertions
    all reading KeyRotationEnabled from GetKeyRotationStatus, which is correct — so removing it breaks
    nothing in tree. It is still a wire change and will be called out under Compatibility.

    Three further findings, filed separately, not in this issue's scope

    1. EnableKeyRotation and DisableKeyRotation accept a key type AWS refuses. Verbatim:

    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.

    UnsupportedOperationException/400 is published on both pages and is the code for it. Substrate reads
    neither KeySpec nor KeyUsage in either handler, so EnableKeyRotation on an RSA_4096 or
    HMAC_256 key answers 200 and records rotation on a key that cannot rotate. This is a missing refusal
    of the same class as #968, not a discarded parameter, so it is its own issue.

    2. GetKeyRotationStatus omits two more published members, and its pending-deletion behaviour is
    unmodelled.
    The response has five elements and substrate answers one. RotationPeriodInDays and
    KeyId come with this issue — a period reported without saying which key it belongs to is not a
    coherent body. NextRotationDate and OnDemandRotationStartDate do not: the first is derivable from
    the enable date plus the period against the simulated clock, the second requires RotateKeyOnDemand,
    which is not implemented. The same page also documents behaviour substrate does not have:

    Pending deletion: While a KMS key is pending deletion, its key rotation status is false and AWS KMS
    does not rotate the key material. If you cancel the deletion, the original key rotation status returns
    to true.

    Substrate answers the stored RotationEnabled in every state, so a key pending deletion reports true
    where AWS reports false, and the restore-on-cancel behaviour has nowhere to restore from. That is a
    state transition rather than a member, and it interacts with #963's deletion pair, so it is filed with
    the two members.

    3. kms:RotationPeriodInDays is a published condition key — "You can use the
    kms:RotationPeriodInDays condition key to further constrain the values that principals can specify in
    the RotationPeriodInDays parameter."
    Substrate's condition-key handling for KMS does not model it.
    Noted for the authorization work rather than filed against rotation; it only becomes meaningful once
    the parameter is decoded, which is what this issue does.

    Two corrections to this issue's own body

    Both minor, recorded because the issue will be read alongside the PR:

    • The RotationPeriodInDays quotation is accurate but partial. The full parameter entry adds the
      modify-an-existing-period sentence quoted above and the condition-key sentence, and the second
      paragraph — "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"
      — is what makes NextRotationDate derivable rather than arbitrary.
    • "ListKeyRotations and RotateKeyOnDemand are not implemented at all" is confirmed against the
      switch, and API_EnableKeyRotation's Related operations section lists both plus
      GetKeyRotationStatus, so the four form one cluster. Correctly excluded from this issue; the
      OnDemandRotationStartDate member above is blocked on RotateKeyOnDemand and is recorded that way.

    Nothing here changes AC 3, 5 or 6. AC 1 is answered, AC 2's code is chosen with its precedent, and AC 4
    resolves to reportable rather than to accepted-and-unobservable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions