Skip to content

kms: EnableKey and DisableKey check no key state, so EnableKey revives a key pending deletion in one call #968

Closed

Description

@scttfrdmn

EnableKey and DisableKey check no key state, so EnableKey on a key pending deletion succeeds — routing around the two-step recovery #963 just established.

Found while implementing #963. It is the last member of the key-state class in this package: #949 fixed the rotation pair, #961 covers the three cryptographic operations, #963 the deletion pair, and these two are what remains.

Why this one matters more than a missing refusal usually does

#963 made CancelKeyDeletion leave a key Disabled, because API_CancelKeyDeletion says recovery from a scheduled deletion is two calls: "when this operation succeeds, the key state of the KMS key is Disabled. To enable the KMS key, use EnableKey."

But EnableKey refuses nothing, so a caller can skip the first call entirely: EnableKey against a key in PendingDeletion answers 200 and writes KeyState: Enabled, Enabled: true. That is a one-call path from pending deletion to usable, which AWS does not have — and it means the guarantee #963 added can be routed around by an operation in the same file.

It also leaves substrate's own state readable in a way AWS's is not: the deletion is silently abandoned with no record that it ever existed, because #963's setKeyState clears DeletionDate on the way through.

What AWS publishes, verified

Both operations have identical rows in the developer guide's Key states of AWS KMS keys table:

Key state EnableKey / DisableKey Footnote
Enabled permitted —
Disabled permitted —
PendingDeletion (and PendingReplicaDeletion) refused [3] — KMSInvalidStateException: <key ARN> is pending deletion (or pending replica deletion).
PendingImport refused [5] — KMSInvalidStateException: <key ARN> is pending import because no key material has ever been imported or one of the imported key materials is deleted or expired.
Unavailable permitted [12] — "The operation succeeds, but the key state of the KMS key does not change until it becomes available."
Creating refused [14] — KMSInvalidStateException: <key ARN> is creating.
Updating refused [15] — KMSInvalidStateException: <key ARN> is updating.

PendingDeletion is the only refused row substrate can reach; ScheduleKeyDeletion remains its sole writer of anything but Enabled or Disabled, so the other four are unreachable and belong on the record rather than in code — the disposition #949 and #963 both took.

Note the Unavailable row is a success with a deferred effect, not a refusal. It is the one row in this table for these two operations that is neither a plain ✓ nor an ✗, and it is unreachable here for the same reason — worth recording so a later sweep does not read [12] as a refusal.

What substrate does

enableKey and disableKey both delegate to setKeyState (kms_plugin.go), which resolves the key, loads it, refuses only a missing key, and then assigns whatever state it was handed. #963 gave cancelKeyDeletion its own body precisely because that helper checks nothing; these two still go through it.

The guard is one condition and it is the same one on both, so unlike #963 this is a small change. The design question it raises is where the check belongs: in setKeyState, which both callers share, or in each handler. setKeyState has exactly two callers and both want the identical refusal, so the shared helper looks right — but it is also the helper #963 deliberately stopped using, so a note saying why it is the right home here (both callers refuse the same single state, where CancelKeyDeletion required the opposite state and a different body) is worth more than the code.

Acceptance criteria

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