Skip to content

kms: ScheduleKeyDeletion and CancelKeyDeletion check no key state, and CancelKeyDeletion leaves the key Enabled where AWS leaves it Disabled #963

Closed

Description

@scttfrdmn

ScheduleKeyDeletion and CancelKeyDeletion check no key state, validate no waiting period, and answer bodies AWS does not publish. CancelKeyDeletion leaves the key in the wrong state.

Found while implementing #949, which fixes the key-state gap for the two rotation operations. The deletion pair has the same gap and four more besides, and they are one issue because they are each other's inverse and share setKeyState (kms_plugin.go:477-497).

CancelKeyDeletion leaves the key Enabled, where AWS leaves it Disabled

API_CancelKeyDeletion, first sentence: "Cancels the deletion of a KMS key. When this operation succeeds, the key state of the KMS key is Disabled. To enable the KMS key, use EnableKey."

Substrate's handler is return p.setKeyState(ctx, input.KeyID, "Enabled", true) (kms_plugin.go:538-546). So a consumer that cancels a deletion gets back a key it can immediately encrypt with, where AWS gives it one it must call EnableKey on first — and a test written against substrate for that two-step recovery would pass with the second step missing.

Neither checks the key state, and the pair is where the two states diverge most sharply

Both pages carry "the KMS key that you use for this operation must be in a compatible key state" and both publish KMSInvalidStateException/400. Their rows in the developer guide's Key states of AWS KMS keys table:

Operation Permitted from Refused from
ScheduleKeyDeletion every state but the two at right PendingDeletion — footnote [3], "is pending deletion"; Updating — footnote [15]
CancelKeyDeletion PendingDeletion only every other state — footnote [4], "KMSInvalidStateException: <key ARN> is not pending deletion"

Substrate refuses neither. So ScheduleKeyDeletion on an already-pending key re-stamps its deletion date — silently extending a window a consumer believes it set — and CancelKeyDeletion on a key that was never scheduled answers 200 and enables it, which is EnableKey under another name and reachable by a caller that has no permission for EnableKey.

Updating is unreachable in substrate (nothing writes it), so only the PendingDeletion row needs implementing on ScheduleKeyDeletion; record the other as unreachable, as #949 did for the four states it could not reach.

kmsInvalidKeyState (kms_errors.go, added by #949) is the helper. Note that CancelKeyDeletion's message is the negation — "is not pending deletion" — so the helper's state-naming message reads correctly for ScheduleKeyDeletion and may need a sibling or a detail parameter here.

Both response shapes are wrong

API_CancelKeyDeletion publishes exactly one response element: KeyId, "the Amazon Resource Name (key ARN) of the KMS key whose deletion is canceled", and its sample response is {"KeyId":"arn:aws:kms:us-east-2:111122223333:key/1234abcd-…"}. Substrate goes through setKeyState, which answers {} — so a consumer reading response['KeyId'] gets a KeyError, and one reading the ARN out of it gets nothing.

API_ScheduleKeyDeletion publishes four: DeletionDate, KeyId, KeyState and PendingWindowInDays. Substrate answers three (kms_plugin.go:530-534), omitting PendingWindowInDays — which AWS's own sample response does carry — and its KeyId is the bare key ID where the page says "the Amazon Resource Name (key ARN)" and the sample shows an ARN.

PendingWindowInDays is neither range-checked nor echoed

"This value is optional. If you include a value, it must be between 7 and 30, inclusive. If you do not include a value, it defaults to 30." Type Integer, Valid Range: Minimum value of 7. Maximum value of 30.

Substrate's days := input.PendingWindowInDays; if days <= 0 { days = 30 } (kms_plugin.go:520-523) gets the default right and the range not at all: 1, 365 and -5 are all accepted, the last silently becoming 30. AWS publishes no code for a range violation on this page, so the code is substrate's reading; ValidationError/400 from CommonErrors is the in-tree precedent (kmsInvalidBody), and #954 used the operation's own published parameter error where one existed — there is none here.

Also noted, not necessarily in scope

Both pages restrict KeyId to "the key ID or key ARN" — not an alias name or alias ARN, unlike Encrypt or DescribeKey, which list all four forms. Substrate resolves all four everywhere through resolveKeyTarget, so an alias reaches both operations. Decide and record rather than fix silently: refusing an alias here is a wire change, and the two pages state the restriction as a description of KeyId rather than publishing a code for violating it.

Acceptance criteria

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