Skip to content

kms: EnableKeyRotation and DisableKeyRotation succeed against a disabled key, where AWS publishes DisabledException/400 #949

Closed

Description

@scttfrdmn

EnableKeyRotation and DisableKeyRotation publish DisabledException, and substrate does not check whether the key is enabled — both answer 200 against a disabled key.

Surfaced while verifying #923's statuses page by page. It is a missing refusal rather than a wrong status, which is why it was deliberately not folded into that PR: #923 changed what a status is worth and this changes whether a request is refused at all.

What AWS publishes

API_EnableKeyRotation and API_DisableKeyRotation both list DisabledException at HTTP 400:

The request was rejected because the specified KMS key is not enabled.

API_EnableKeyRotation's own prose is explicit about the state requirement: "The KMS key that you use for this operation must be in a compatible key state."

Note the asymmetry, which is the reason this needs a per-operation check rather than a shared one: API_GetKeyRotationStatus does not publish DisabledException, and neither does API_EnableKey. So reading the rotation status of a disabled key is fine, and enabling or disabling rotation on one is not.

What substrate does

enableKeyRotation (emulator/kms_plugin.go:646) and disableKeyRotation (:673) both resolve the key, refuse a missing one with NotFoundException, then write RotationEnabled and answer 200. Neither reads key.Enabled.

The three sites that do check it — encrypt, decrypt, generateDataKey — go through kmsKeyDisabled (emulator/kms_errors.go), so the code and status are already right and in one place; this is two call sites, not a new error path. kmsKeyDisabled's doc comment already names this gap.

Consequence for a consumer

A test that disables a key and then asserts its rotation cannot be changed passes against AWS and fails against substrate — the wrong direction, since the whole point is that a substrate run predicts an AWS run. Worse, the write succeeds: RotationEnabled flips on a key that cannot perform a cryptographic operation, so a later GetKeyRotationStatus reports a state real KMS would never have produced. That is state divergence rather than a missing error, which is why it is worth an issue rather than a note.

Acceptance criteria

  • EnableKeyRotation against a disabled key answers DisabledException/400, through kmsKeyDisabled.
  • DisableKeyRotation against a disabled key answers DisabledException/400, through kmsKeyDisabled.
  • Neither writes RotationEnabled when it refuses — asserted by reading GetKeyRotationStatus afterwards through the wire and finding the value unchanged, not by inspecting state.
  • GetKeyRotationStatus against a disabled key still answers 200, because API_GetKeyRotationStatus does not publish DisabledException. A test pins this, so a later "check Enabled everywhere" sweep cannot quietly break it.
  • A key in PendingDeletion is considered: KMSInvalidStateException/400 is published on both operations, and whether substrate's ScheduleKeyDeletion leaves a key that these two must refuse needs checking rather than assuming. Either implement it or record why the state is not reachable.
  • Wire tests assert the status and the code, per fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923's finding that a code alone let a wrong status stand.
  • docs/services.md's KMS error section — added by fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923 — has this row moved out of "named rather than closed".

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