Repository navigation
Description
CreateKey's Policy parameter is decoded by nobody, and GetKeyPolicy answers {"Version":"2012-10-17","Statement":[]} for any key that has never had PutKeyPolicy called on it. So no key created through substrate has a key policy that grants anything, and a caller that attached one at creation time cannot read it back.
Found while verifying API_CreateKey for #977.
What substrate does today
createKey (emulator/kms_plugin.go) decodes five members — Description, KeyUsage, KeySpec, MultiRegion, Tags — and Policy is not among them. Nothing writes kmsPolicyKey(...) except putKeyPolicy.
getKeyPolicy (emulator/kms_plugin.go:653-681) falls back to an empty-statement document:
policy := `{"Version":"2012-10-17","Statement":[]}`
if data != nil {
policy = string(data)
}So there are two defects with one cause:
CreateKey'sPolicyis silently dropped. A caller that creates a key with a policy and then reads it back gets a document it did not send — the response-member analogue of cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765, aimed at a request parameter this time.- A key with no explicit policy reports a policy that grants nothing, where AWS attaches a default that grants the account root full access to the key.
What AWS publishes
API_CreateKey's Policy parameter, verbatim: "The key policy to attach to the KMS key. … If you do not provide a key policy, AWS KMS attaches a default key policy to the KMS key." Type String, length 1–32768, pattern [\u0009\u000A\u000D\u0020-\u00FF]+.
API_CreateKey publishes MalformedPolicyDocumentException/400 — "the request was rejected because the specified policy is not syntactically or semantically correct" — and LimitExceededException/400 for a length constraint, with the parameter's own note: "if the key policy exceeds the length constraint, AWS KMS returns a LimitExceededException."
The Default key policy page states what the default document contains: a single statement with Sid Enable IAM User Permissions, Principal the account root ARN, Action kms:* and Resource *. Verify the exact document against that page before implementing, since the empty-statement stand-in is currently the only thing distinguishing a substrate key policy from AWS's.
API_CreateKey also notes a substrate-relevant asymmetry worth recording rather than implementing: "If either of the required Resource or Action elements are missing from a key policy statement, the policy statement has no effect. When a key policy statement is missing one of these elements, the AWS KMS console correctly reports an error, but the CreateKey and PutKeyPolicy API requests succeed." So the semantic check AWS advertises is narrower than it looks.
Why the default document matters beyond fidelity
A key policy is the only place a KMS key's own permissions live — an IAM policy cannot grant access to a key whose key policy does not delegate to IAM. Substrate's authz work (#671 and the authzref data) reads IAM; if a key policy is ever consulted, an empty-statement default would deny every principal, so the stand-in is not a neutral placeholder. It is a document that says the opposite of AWS's default.
putKeyPolicy (:683-702) has the same class of gap and belongs in the same PR: it validates no length, refuses no malformed document, checks no key state, and ignores PolicyName (AWS supports only default, and getKeyPolicy already hardcodes that value in its response).
Acceptance criteria
-
CreateKeyrecords thePolicyit was given, readable throughGetKeyPolicyover the wire. - A key created with no
Policyreports AWS's default key policy, with the exact document verified against the Default key policy page at implementation time and any deviation recorded as substrate's reading. -
Policylength outside 1–32768 answersLimitExceededException/400 on bothCreateKeyandPutKeyPolicy, per the parameter's own note. - A document that is not syntactically valid JSON answers
MalformedPolicyDocumentException/400. Semantic validation beyond that is decided and recorded — AWS's own page says a statement missingActionorResourcestill succeeds, so "semantically correct" is narrower than it reads. -
PutKeyPolicyrefuses a key pending deletion, per the key-state table, or the omission is recorded with the footnote that permits it. -
PolicyNamehandling is decided: AWS supports onlydefault, andgetKeyPolicyalready answers that string unconditionally. - Tests go over the wire (cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765) and assert the status alongside the code (fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923).
Activity
scttfrdmn commentedon Sep 18, 2026
Premise corrections before the PR opens, all verified against the tree at
bd0e338and against the AWS pages today.The cited lines have drifted, and one of them names the wrong count.
createKeydecodes six members, not the five listed — #985 addedCustomerMasterKeySpecand #984 addedOrigin,CustomKeyStoreIdandXksKeyId, so the current set isDescription,KeyUsage,KeySpec,CustomerMasterKeySpec,Origin,CustomKeyStoreId,XksKeyId,MultiRegion,Tags.Policyis still absent from it, which is the defect.getKeyPolicyis atkms_plugin.go:689-717(not:653-681) andputKeyPolicyat:719-738(not:683-702).The default document does not need a developer-guide trip.
API_GetKeyPolicy's own Example Response carries it in full, which is a stronger source than the Default key policy page the issue points at:Note the
"Id" : "key-default-1"member, which the developer-guide prose does not mention and which the issue's summary of the document therefore omits.Two gaps the issue does not name.
loadKey, so neither answersNotFoundExceptionfor a key that does not exist — both pages publish it at 400. This is already recorded in the tree, atkms_error_status_test.go:102-103: "GetKeyPolicy and PutKeyPolicy are absent because substrate does not check the key exists on either — a separate gap, not a status." That table entry and its comment change with this issue.BypassPolicyLockoutSafetyCheckis decoded nowhere, on eitherCreateKeyorPutKeyPolicy. It only matters if the lockout check exists to be bypassed, which decides the scope question below.Correction to the fifth acceptance criterion: there is no key-state refusal to add. The criterion asks for
PutKeyPolicyto refuse a key pending deletion "per the key-state table, or the omission recorded with the footnote that permits it". The key-state table permits it: thePutKeyPolicyandGetKeyPolicyrows are a green checkmark in all seven state columns — Enabled, Disabled, Pending deletion / Pending replica deletion, Pending import, Unavailable, Creating, Updating — with no footnote marker on any of them. CompareTagResource, two rows down, which is an X at Pending deletion carrying footnote [3]. So the correct outcome is that substrate adds no key-state check here, andKMSInvalidStateExceptionstays unreachable on both operations even though both publish it. That is a published-but-unreachable code rather than an omission, and it is recorded rather than implemented.This also disposes of the trap the release plan flagged: since no key-state refusal is added, neither
kmsKeyStateErrornorkmsInvalidKeyStateis called from either handler. (kmsKeyStateErrorwould have been wrong regardless — it can answerDisabledException, whichPutKeyPolicydoes not publish.)PolicyNamefor a value other thandefaultresolves toNotFoundException/400. Both pages state "The only valid value isdefault" and both publishNotFoundException, glossed "the specified entity or resource could not be found" — a policy name that names no policy is squarely that, and it keeps the refusal on the page rather than reaching forCommonErrors. Recording it as a one-step reading.Scope: the lockout safety check is not implemented, so
BypassPolicyLockoutSafetyCheckstays undecoded. The check AWS describes is "the key policy must allow the calling principal to make a subsequentPutKeyPolicyrequest on the KMS key" — that is a policy evaluation against the caller's principal, which is #671's authorization machinery and not something this issue can reach. With no lockout check,trueandfalseproduce identical observable behaviour, so decoding the member would add a value read by nobody: exactly the defect class #984 just closed. It is recorded as an omission on both operations instead.Semantic validation is syntax plus "the document is a JSON object". The issue is right that AWS's own page narrows "semantically correct" almost to nothing — "if either of the required
ResourceorActionelements are missing from a key policy statement … theCreateKeyandPutKeyPolicyAPI requests succeed, even though the policy statement is ineffective" — so no statement-level check is defensible. Substrate refuses a body that is not valid JSON and a body that is valid JSON but not an object ([],"x",5), on the IAM JSON Policy Reference's terms, and records thatPolicy's published pattern (the printable-ASCII-plus-Latin-1 character class, tab/LF/CR included) stays unenforced because neither page publishes a code for a pattern violation.InvalidArnException— "a specified ARN, or an ARN in a key policy, is not valid" — likewise stays unreachable, since nothing walks the principals.The default is synthesised at read time rather than written at create time. Observationally identical for a key created after this ships, and it also means every key created before it reports the default rather than the empty-statement stand-in — no migration, and no state write on a path AWS describes as attaching a document.