Repository navigation
fix(kms): CreateKey refuses the key-material parameters it does not model (#984) - #1044
Merged
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #984.
CreateKeydecoded none ofOrigin,CustomKeyStoreIdorXksKeyId. All three were accepted and thrown away, soCreateKeywithOrigin: "EXTERNAL"— the first call of every key-import workflow — answered200withOrigin: "AWS_KMS",KeyState: "Enabled"andEnabled: true. A consumer got a fully usable key where AWS answers one inPendingImportthat no cryptographic operation will touch, so the workflow passed at step one and failed at step two, whereGetParametersForImportturns 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.Originoutside the published fourValidationError/400CommonErrors.html, the reading #977 recorded for a misspelledKeySpecXksKeyIdwith anyOriginbutEXTERNAL_KEY_STOREValidationError/400Originvalue"Originpublished and notAWS_KMSUnsupportedOperationException/400CustomKeyStoreId, any valueUnsupportedOperationException/400The
XksKeyIdcheck is ordered before the origin's own support, soAWS_KMS+XksKeyIdreads AWS's refusal whileEXTERNAL_KEY_STORE+XksKeyId— the one combination AWS accepts — falls through and is told the truth about the store. That ordering is asserted.CustomKeyStoreNotFoundExceptionis the near miss and is deliberately unused althoughAPI_CreateKeypublishes it: it says no store has this ID, which invites the caller to create one, andCreateCustomKeyStoredoes 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 onOriginitself. 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
KeyMetadatamembers —ExpirationModel,ValidTo,CloudHsmClusterId,CustomKeyStoreId,XksKeyConfiguration— are now unreachable by construction rather than because nothing read the parameter. That is what keepsOrigina constant, andkms_key_metadata.goanddocs/services.mdnow say so.Premise corrections
Posted on the issue before this PR opened (comment 5723096717):
createKeydecodes 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 coverageat 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 throughListKeysbefore and after.