Repository navigation
Description
CreateKey decodes neither Origin, CustomKeyStoreId nor XksKeyId, so a caller asking for a key with no key material — the first step of every import workflow — gets a fully usable AWS_KMS key instead, and a caller asking for a key in a custom key store gets an ordinary one.
Found while verifying API_CreateKey for #977, and it is the request-side cause of eight response members #974 recorded as unreachable.
What substrate does today
createKey (emulator/kms_plugin.go) decodes five members — Description, KeyUsage, KeySpec, MultiRegion, Tags — and none of the three above. KMSKey has no Origin field, and kmsKeyMetadata (emulator/kms_key_metadata.go, #974) answers the constant AWS_KMS for exactly that reason.
So:
CreateKeywithOrigin: "EXTERNAL"answers200withOrigin: "AWS_KMS",KeyState: "Enabled"andEnabled: true. AWS answers a key inPendingImportthat no cryptographic operation will accept untilImportKeyMaterialruns.CreateKeywithCustomKeyStoreIdanswers200and ignores it, where AWS refuses an ID it cannot find (CustomKeyStoreNotFoundException/400) or one whose store is notCONNECTED(CustomKeyStoreInvalidStateException/400).CreateKeywithXksKeyIdand noOriginanswers200, where AWS requires the parameter only forEXTERNAL_KEY_STOREand states it "is not valid for KMS keys with any otherOriginvalue".
A consumer's import workflow therefore passes against substrate at step one and fails at step two, because GetParametersForImport and ImportKeyMaterial are not implemented either — which is the same failure shape #765 exists to catch, spread across three calls instead of one.
What AWS publishes
API_CreateKey, Origin, verbatim: "The source of the key material for the KMS key. You cannot change the origin after you create the KMS key. The default is AWS_KMS, which means that AWS KMS creates the key material." Valid Values AWS_KMS | EXTERNAL | AWS_CLOUDHSM | EXTERNAL_KEY_STORE, and "the EXTERNAL origin value is valid only for symmetric KMS keys". For AWS_CLOUDHSM and EXTERNAL_KEY_STORE, "the KeySpec value must be SYMMETRIC_DEFAULT" and CustomKeyStoreId is required.
CustomKeyStoreId: length 1–64, "the ConnectionState of the custom key store must be CONNECTED", and "this parameter is valid only for symmetric encryption KMS keys in a single Region. You cannot create any other type of KMS key in a custom key store."
XksKeyId: length 1–128, pattern ^[a-zA-Z0-9-_.]+$, "this parameter is required for a KMS key with an Origin value of EXTERNAL_KEY_STORE. It is not valid for KMS keys with any other Origin value."
The published errors for these paths are all on API_CreateKey: CustomKeyStoreNotFoundException/400, CustomKeyStoreInvalidStateException/400, CloudHsmClusterInvalidConfigurationException/400, XksKeyAlreadyInUseException/400, XksKeyInvalidConfigurationException/400, XksKeyNotFoundException/400, and UnsupportedOperationException/400 for an unsupported parameter combination.
The scope question this issue exists to settle
Substrate models no custom key store and no imported key material, and per CLAUDE.md's boundary that is defensible — the key material itself is resource-internal. But the request parameters are observable through an API call, and today they are accepted and discarded, which is the worst of the three available answers. The options, in increasing cost:
- Refuse what substrate does not model.
Originother thanAWS_KMS, or anyCustomKeyStoreId/XksKeyId, answersUnsupportedOperationException/400 — the code whose own gloss is "a specified parameter is not supported or a specified resource is not valid for this operation". A consumer's import workflow then fails at step one with a published code instead of passing three steps and failing on the fourth. - Model
Origin: EXTERNALas a key state.KMSKeygainsOrigin, a key createdEXTERNALisPendingImport, every cryptographic operation refuses it with the key-state error that state already implies, andImportKeyMaterial/GetParametersForImport/DeleteImportedKeyMaterialbecome their own issue. This also makesExpirationModelandValidToreachable and unblocks kms: EnableKeyRotation and DisableKeyRotation accept an asymmetric or HMAC key, where AWS publishes UnsupportedOperationException/400 #972's "KMS keys with imported key material" rotation restriction, which is currently recorded as unreachable. - Model a custom key store.
CreateCustomKeyStoreand its six siblings, aConnectionStatemachine, andCloudHsmClusterId/CustomKeyStoreId/XksKeyConfigurationbecome reachable. Much larger, and its own milestone.
Option 1 is the recommendation for this issue, with 2 and 3 filed separately if they are wanted at all. A refusal is honest about what substrate does not model; silently discarding the parameter is not. Note that option 1 makes three of #974's absent members unreachable by construction rather than by omission, which is a stronger statement than the one that file records today.
Acceptance criteria
-
CreateKeydecodesOrigin,CustomKeyStoreIdandXksKeyId, and a value outsideOrigin's published four answers a refusal rather than being stored. - The decision between the three options above is made and recorded in
docs/services.md, with the chosen code cited toAPI_CreateKeyand any reading stated as substrate's. - Whatever is refused is refused with a code
API_CreateKeypublishes, and the status is asserted alongside it (fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923). -
kms_key_metadata.go's anddocs/services.md's statements thatOriginis a constant and thatExpirationModel/ValidTo/XksKeyConfigurationare unreachable are updated to say why — by refusal or by modelling — rather than left as "no request can produce one". - Tests go over the wire (cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765).
Activity
scttfrdmn commentedon Sep 18, 2026
Premise corrections found while verifying this issue at
96c375b(v0.118.0), before opening the PR. The substance stands; four details in the body do not.1.
createKeydecodes six members, not five. #985 addedCustomerMasterKeySpecas a request parameter (kms_plugin.go:293-302), so the decoded set isDescription,KeyUsage,KeySpec,CustomerMasterKeySpec,MultiRegion,Tags. Same correction applies to #983's body.2. Five response members hang off this, not eight.
docs/services.md:11061-11062andkms_key_metadata.go:277-284list them:ExpirationModelandValidTo(published only forOrigin: EXTERNAL), andCloudHsmClusterId,CustomKeyStoreId,XksKeyConfiguration(need a key store). The other three the body counts —MultiRegionConfiguration,PendingDeletionWindowInDays,RotationEnabled— are absent for unrelated reasons: the first needs a modelled replica, the second is confined toPendingReplicaDeletion, and the third is absent becauseAPI_KeyMetadatadoes not publish it at all (#971).3. The refusal is two refusals, and they should not share a code. The body's option 1 collapses them. Splitting them is what lets a caller tell a typo from a scope boundary, exactly as
kmsUnknownKeySpec(kms_errors.go:251) andkmsInadmissibleKeyUsage(:373) already do for the adjacent pair:Originoutside the published four is a malformed member →ValidationError/400, from CommonErrors, the same reading kms: CreateKey validates neither KeySpec nor KeyUsage, and no cryptographic operation refuses a key whose KeyUsage is not ENCRYPT_DECRYPT #977 recorded for a misspelledKeySpec. AndXksKeyIdsent with anOriginthat is notEXTERNAL_KEY_STOREis refused on AWS's own sentence — "It is not valid for KMS keys with any otherOriginvalue" — which holds on real AWS and has nothing to do with what substrate models.Originthat is notAWS_KMS, and anyCustomKeyStoreId→UnsupportedOperationException/400, the code published onAPI_CreateKeyand glossed "a specified parameter is not supported or a specified resource is not valid for this operation".4.
CustomKeyStoreId's 1–64 length andXksKeyId's 1–128 length and^[a-zA-Z0-9-_.]+$pattern become unreachable once any non-empty value is refused. That is worth recording as unreachable-by-construction rather than implementing a constraint no request can reach, and it is the same shape of statement AC 4 asks for about theOriginconstant.Option 1 is the decision, with the two-code split above. The resolver lands beside
kmsResolveKeySpecAndUsage(kms_key_specs.go:164) and runs after the spec resolves, becauseOrigin: EXTERNALis "valid only for symmetric KMS keys" andAWS_CLOUDHSM/EXTERNAL_KEY_STORErequireSYMMETRIC_DEFAULT— conditions stated in terms of a spec that has to be resolved first.fix(kms): CreateKey refuses the key-material parameters it does not m…