Repository navigation
fix(kms): a KeyId resolves from its own ARN, and the tagging API reaches a key (#922) (#835) - #924
Merged
Merged
Conversation
…hes a key resolveKeyID split the identifier on "/" and returned the last component, and its eighteen callers keyed the load and the store by the caller's own account and Region. So a foreign-account, foreign-Region key ARN addressed the caller's own key of that ID: TagResource wrote onto the wrong key and UntagResource stripped it, both answering 200. The type match was unanchored too, so an alias ARN resolved to its last path component -- and AWS's own example of an AWS managed key's alias is alias/aws/s3, which resolved to the key ID "s3". The cut is now on the first "/" only, and a slashed identifier is refused for a key alone, because a key ID is a UUID or "mrk-" plus a de-hyphenated one. kmsParseARN takes no *RequestContext, so the rule is structural. The five KMS key builders become free functions, so the resolver and the plugin cannot produce two layouts of one key. decrypt deliberately keeps the request context: its key ID comes out of the ciphertext, not out of a KeyId parameter. Fixing the resolution is what made the cross-account case reachable, so the refusal lands in the same commit: all three tagging operations publish "Cross-account use: No", but while the account came from the request context the prohibition had nothing to refuse. The same context-free parser gives the tagging API its kms arm, the third row of #835. An alias ARN is refused there rather than followed, per the developer guide's list of what cannot be tagged. The merge is the first over an array-shaped tags member -- KMS spells its fields TagKey/TagValue -- so mergeRecordTagListTags takes the field names as parameters and sorts by key per #862, and its guard tests a colon-terminated prefix because "key" is a prefix of key_ids and key_policy. Closes #922. Part of #835.
5 tasks
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5 tasks
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 #922. Part of #835 — the third of its eleven rows; eight remain.
Why one PR and not two
KMSPlugin.resolveKeyIDsplit aKeyIdon/and returned the last component, and its eighteen callers then keyed the load and the store by the caller's ownAccountID/Region. The tagging row of #835 needs the same key layout from an ARN alone, so the two are one change seen from two sides — a resolver that re-derived the layout would be a second producer of it, the drift #826 found for SQS and #918 for CloudFront.More decisively: fixing the resolution is what makes the cross-account case reachable. All three KMS tagging operations publish "Cross-account use: No", but while the account came from the request context a foreign-account key ARN could only ever hit the caller's own record, so the prohibition had nothing to refuse. Honouring the ARN's account without adding the refusal would have turned a wrong-record write into a genuine cross-account write. Hence
kmsRequireLocal, and hence one commit.What changes
Resolution.
kmsParseARNtakes no*RequestContext, so the rule #826/#845/#910/#918 established is structural rather than remembered. The cut is on the first/and the remainder is not required to be a single segment — AWS's own example of an AWS managed key's alias isalias/aws/s3, which resolved today to the key IDs3, and a parser refusing a slashed identifier outright would reject a legal ARN. For akeythe extra segment is refused, because a key ID is a UUID (ormrk-plus a de-hyphenated one) and carries no/. An alias ARN is followed through the pointer stored in the account and Region the ARN names;CreateAlias/UpdateAliasrefuse aTargetKeyIdoutside the caller's own. A bare key ID and a barealias/name still resolve against the caller's context, becauseKeyIddocuments four forms and two are not ARNs. The five KMS key builders become free functions with no receiver state.decryptdeliberately keeps the request context, and says so: its key ID comes out of the ciphertext, not out of aKeyIdparameter, so there is no ARN to take an account from.The #835 row. Resolver arm, merge arm and scanner, sharing the parser above. An alias ARN is refused at the tagging API rather than followed — the developer guide's "You cannot tag aliases, custom key stores, AWS managed keys, AWS owned keys, or KMS keys in other AWS accounts" — since resolving it would tag a resource AWS says cannot be tagged and the caller would read the tag back off the key. The merge is the first over an array-shaped tags member (KMS spells its fields
TagKey/TagValue, alone among the remaining rows), somergeRecordTagListTagstakes the field names as parameters, is written once for the rows that follow, and re-emits sorted by key per #862. Its guard tests a colon-terminated prefix — the third namespace to need one — becausekeyis a prefix ofkey_ids/key_policyandaliasofalias_names, andkey_idsis a JSON array a bare-prefix test would report taggable.Account isolation at the tagging arm is emergent rather than guarded, as ACM's is: the resolver builds an account- and Region-qualified key, so a foreign-account ARN builds a key nothing is stored at and the merge fails "resource not found".
Deliberately left, and recorded
NotFoundExceptionat HTTP 404 at fifteen pre-existing sites where KMS publishes 400 — filed as fix(kms): NotFoundException is HTTP 400, and InvalidRequest is not a KMS code #923, the split ACM tagging: ResourceNotFoundException is published at 400, not 404, and InvalidArnException is unmodelled #921 took for ACM. A test pins the current status so the follow-up has something to change.KeyIdoperations do not enforce the Region.DescribeKeyon a foreign-Region key ARN now answers with that key rather than a local impostor — strictly better, but real KMS would refuse. AWS publishes no per-operation statement to cite for the other fifteen. Pinned by a named test.KMSInvalidStateExceptionfor tagging a key pending deletion — unmodelled at either arm.Provenance
The ARN formats, the
alias/aws/s3example, the four acceptedKeyIdforms, theTagKey/TagValuefield names,InvalidArnException/400,NotFoundException/400 and "Cross-account use: No" are quoted from the KMS developer guide's Key identifiers and Tagging keys pages and fromAPI_Tag,API_TagResource,API_UntagResourceandAPI_ListResourceTags. Mapping the cross-account prohibition ontoNotFoundExceptionis substrate's reading: AWS publishes the prohibition and the code but does not join them.Compatibility
A
TagResource/UntagResource/ListResourceTagsnaming a key outside the caller's account or Region now answersNotFoundExceptionwhere it previously reached the caller's own key of that ID and answered200. An alias ARN presented to anyKeyIdoperation now resolves through the alias pointer rather than to its last path component.TagResourceandListResourceTagsreturn tags ordered by key.Verification
Nine-command gate, all green; coverage holds at 84.1% emulator / 83.6% total. 17 new wire tests through
StartTestServer, with every tag read back through KMS's ownListResourceTagsper #765 and in the other direction throughGetResources.