Skip to content

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

Closed

Description

@scttfrdmn

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:

  • CreateKey with Origin: "EXTERNAL" answers 200 with Origin: "AWS_KMS", KeyState: "Enabled" and Enabled: true. AWS answers a key in PendingImport that no cryptographic operation will accept until ImportKeyMaterial runs.
  • CreateKey with CustomKeyStoreId answers 200 and ignores it, where AWS refuses an ID it cannot find (CustomKeyStoreNotFoundException/400) or one whose store is not CONNECTED (CustomKeyStoreInvalidStateException/400).
  • CreateKey with XksKeyId and no Origin answers 200, where AWS requires the parameter only for EXTERNAL_KEY_STORE and states it "is not valid for KMS keys with any other Origin value".

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:

  1. Refuse what substrate does not model. Origin other than AWS_KMS, or any CustomKeyStoreId/XksKeyId, answers UnsupportedOperationException/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.
  2. Model Origin: EXTERNAL as a key state. KMSKey gains Origin, a key created EXTERNAL is PendingImport, every cryptographic operation refuses it with the key-state error that state already implies, and ImportKeyMaterial/GetParametersForImport/DeleteImportedKeyMaterial become their own issue. This also makes ExpirationModel and ValidTo reachable 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.
  3. Model a custom key store. CreateCustomKeyStore and its six siblings, a ConnectionState machine, and CloudHsmClusterId/CustomKeyStoreId/XksKeyConfiguration become 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

  • CreateKey decodes Origin, CustomKeyStoreId and XksKeyId, and a value outside Origin'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 to API_CreateKey and any reading stated as substrate's.
  • Whatever is refused is refused with a code API_CreateKey publishes, 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 and docs/services.md's statements that Origin is a constant and that ExpirationModel/ValidTo/XksKeyConfiguration are 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

  1. added this to the v0.119.0 milestone on Sep 17, 2026
  2. added
    type: bug
    on Sep 17, 2026
  3. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    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. createKey decodes six members, not five. #985 added CustomerMasterKeySpec as a request parameter (kms_plugin.go:293-302), so the decoded set is Description, 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-11062 and kms_key_metadata.go:277-284 list them: ExpirationModel and ValidTo (published only for Origin: EXTERNAL), and CloudHsmClusterId, 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 to PendingReplicaDeletion, and the third is absent because API_KeyMetadata does 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) and kmsInadmissibleKeyUsage (:373) already do for the adjacent pair:

    • A refusal AWS itself would make. An Origin outside 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 misspelled KeySpec. And XksKeyId sent with an Origin that is not EXTERNAL_KEY_STORE is refused on AWS's own sentence — "It is not valid for KMS keys with any other Origin value" — which holds on real AWS and has nothing to do with what substrate models.
    • A refusal substrate makes because it models nothing behind the parameter. A published Origin that is not AWS_KMS, and any CustomKeyStoreId → UnsupportedOperationException/400, the code published on API_CreateKey and glossed "a specified parameter is not supported or a specified resource is not valid for this operation".

    4. CustomKeyStoreId's 1–64 length and XksKeyId'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 the Origin constant.

    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, because Origin: EXTERNAL is "valid only for symmetric KMS keys" and AWS_CLOUDHSM/EXTERNAL_KEY_STORE require SYMMETRIC_DEFAULT — conditions stated in terms of a spec that has to be resolved first.

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