Skip to content

fix(kms): CreateKey refuses the key-material parameters it does not model (#984) - #1044

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/984-kms-create-key-origin
Sep 18, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/984-kms-create-key-origin

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #984.

CreateKey decoded none of Origin, CustomKeyStoreId or XksKeyId. All three were accepted and thrown away, so CreateKey with Origin: "EXTERNAL" — the first call of every key-import workflow — answered 200 with Origin: "AWS_KMS", KeyState: "Enabled" and Enabled: true. A consumer got a fully usable key where AWS answers one in PendingImport that no cryptographic operation will touch, so the workflow passed at step one and failed at step two, where GetParametersForImport turns out not to exist either. That is #765's failure mode spread across three calls.

The decision

Substrate models neither imported key material nor a custom key store, and per CLAUDE.md's boundary that is defensible — the key material itself is resource-internal. The request parameters are not, so the choice was between modeling them, refusing them, and what substrate was doing. Accepting a parameter and discarding it is the worst of the three, because it is the only one a caller cannot detect. This is the issue's option 1.

Two refusals, two codes

Both are 400, so the code is the only thing that can say which — and they answer different questions about whether the caller did anything wrong.

Request Answer Whose refusal
Origin outside the published four ValidationError/400 AWS's — a malformed member, from CommonErrors.html, the reading #977 recorded for a misspelled KeySpec
XksKeyId with any Origin but EXTERNAL_KEY_STORE ValidationError/400 AWS's — the page says it itself: "it is not valid for KMS keys with any other Origin value"
Origin published and not AWS_KMS UnsupportedOperationException/400 Substrate's — real KMS honors it, and the message says so
CustomKeyStoreId, any value UnsupportedOperationException/400 Substrate's, same reason

The XksKeyId check is ordered before the origin's own support, so AWS_KMS + XksKeyId reads AWS's refusal while EXTERNAL_KEY_STORE + XksKeyId — the one combination AWS accepts — falls through and is told the truth about the store. That ordering is asserted.

CustomKeyStoreNotFoundException is the near miss and is deliberately unused although API_CreateKey publishes it: it says no store has this ID, which invites the caller to create one, and CreateCustomKeyStore does not exist either.

Recorded rather than implemented

Three published constraints are unreachable by construction — CustomKeyStoreId's 1–64 length, XksKeyId's 1–128 length and pattern, and the spec-dependent conditions on Origin itself. A constraint no request can reach is not enforcement, and writing one implies the parameter is modeled. The resolver is nevertheless ordered after the key spec resolves, so whichever of those is ever modeled has a resolved spec to read.

Five of #974's absent KeyMetadata members — ExpirationModel, ValidTo, CloudHsmClusterId, CustomKeyStoreId, XksKeyConfiguration — are now unreachable by construction rather than because nothing read the parameter. That is what keeps Origin a constant, and kms_key_metadata.go and docs/services.md now say so.

Premise corrections

Posted on the issue before this PR opened (comment 5723096717): createKey decodes six members, not five; five response members hang off this, not eight; the refusal is two refusals rather than one; and the two store parameters' length and pattern constraints become unreachable.

Verification

The nine-command gate is green — gofmt/build/vet, golangci-lint run ./... (0 issues), make test, GOTOOLCHAIN=go1.26.6 make test, make coverage at 85.1% emulator / 84.6% total (baseline held), make docs-reference docs-reference-check docs-versions authz-reference-check, npm --prefix docs run build, and the e2e suite.

Five new tests, all over the wire (#765) with the status asserted beside every code (#923): the supported origin accepted explicitly and by default; every other published origin refused; the unpublished/unsupported code split asserted as a pair; both store parameters including XksKeyId's two cases; and that a refusal mints no key, checked through ListKeys before and after.

…odel (#984)

CreateKey decoded none of Origin, CustomKeyStoreId or XksKeyId, so all three
were accepted and thrown away: CreateKey with Origin: "EXTERNAL" answered 200
with Origin: "AWS_KMS", KeyState "Enabled" and Enabled true. A consumer's
import workflow passed at step one and failed at step two, where
GetParametersForImport turns out not to exist either.

The three members are now decoded, and what substrate does not model is
refused with a code API_CreateKey publishes. The refusal is two refusals with
two codes: ValidationError/400 for the ones real KMS would also make (an
Origin outside the published four, and an XksKeyId sent with any origin but
EXTERNAL_KEY_STORE, which the page refuses itself), and
UnsupportedOperationException/400 for the ones substrate makes because it
models nothing behind the parameter (a published non-AWS_KMS Origin, any
CustomKeyStoreId). Both are 400, so the code is the only thing that tells a
caller a typo from a boundary of the emulator.

Five of #974's absent KeyMetadata members are now unreachable by construction
rather than because nothing read the parameter, which is what keeps Origin a
constant.
@codecov

codecov Bot commented Sep 18, 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 490817b into main Sep 18, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/984-kms-create-key-origin branch September 18, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kms: CreateKey decodes neither Origin, CustomKeyStoreId nor XksKeyId, so a key asked for with no key material comes back fully usable

1 participant