Repository navigation
fix(kms): data-key generation refuses a key that is not a symmetric encryption key (#988) - #1045
Merged
Merged
Conversation
…ncryption key (#988) GenerateDataKey and GenerateDataKeyWithoutPlaintext checked KeyUsage and key state only, never the key spec, so an RSA_2048 key created with KeyUsage ENCRYPT_DECRYPT — a pair AWS publishes and CreateKey must accept — was handed a wrapped data key and a 200. Both pages state the restriction four times over, twice in a description and twice on the KeyId parameter itself: "you cannot use an asymmetric KMS key to encrypt data keys", and "You cannot specify an asymmetric KMS key or a KMS key in a custom key store". kmsDataKeyKeySpecError reuses kmsIsSymmetricEncryptionKey, so the refusal and the two key-material omissions read one published condition in one place, and is shared by both operations so they cannot diverge — the #961 precedent. It runs after the usage check and before the key state, because a spec is permanent where a state has a remedy. InvalidKeyUsageException/400 is substrate's reading of an unsplit bullet: it is the only published code about a key being the wrong kind, and the KeyUsage is the one thing such a key is right about. The message therefore leads with the spec rather than the usage, and names GenerateDataKeyPair — the operation AWS directs such a caller to — as unimplemented rather than redirecting a caller to an unknown-action error. #978's omission at these two sites becomes a guard: the request that reached it is now refused, so kms_key_material_id_test.go asserts the refusal in place of the absent member. Closes #988
5 tasks
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.
What
GenerateDataKeyandGenerateDataKeyWithoutPlaintextrequire a symmetric encryption KMS key. Substrate checkedKeyUsageand key state only, so anRSA_2048key created withKeyUsage: ENCRYPT_DECRYPT— a pair AWS publishes andCreateKeymust accept — passed both checks and was handed a wrapped data key at 200.Both pages state the restriction four times over, twice in a description and twice on
KeyIditself:The plural in "data keys" is load-bearing: it is why this is a condition on the two
GenerateDataKey*operations and not onEncrypt, which AWS explicitly permits under an asymmetric key.Scope
Only what the API model states (#671). The custom-key-store half of the restriction is unreachable — #984 refuses
CustomKeyStoreIdatCreateKey— and that is recorded rather than coded.SYMMETRIC_DEFAULTRSA_2048/RSA_3072/RSA_4096/SM2+ENCRYPT_DECRYPTInvalidKeyUsageException/ 400, naming the specHMAC_*, signing and key-agreement specsInvalidKeyUsageException/ 400 from the usage check, which runs first — unreachable hereThe code is substrate's reading
InvalidKeyUsageException/400 on three grounds, argued inkmsInvalidKeySpecForDataKey: it is the only code either page publishes about a key being the wrong kind; the restriction is published four times so the refusal itself is not a reading; and the operation's wrap algorithm is fixed, so the code's second gloss bullet fits with the member elided. Neither of its two bullets describes this condition exactly, because theKeyUsageis the one thing such a key is right about — so the message leads with the spec, and namesGenerateDataKeyPair, the operation AWS directs such a caller to, as unimplemented. Redirecting a caller to an unknown-action error would be worse than the truth.Ordering
After
kmsKeyUsageError, beforekmsKeyStateError: a spec and a usage are permanent where a key state has a remedy, so a disabled RSA encryption key hears "has key spec" rather thanDisabledException, which would imply that enabling it would help. Both sides are asserted through the message, since the usage neighbor shares this code and the state neighbor shares the 400.One helper shared by both operations, per #961 — the issue that found
GenerateDataKeyWithoutPlaintextrefusing nothing its four siblings refused.kmsIsSymmetricEncryptionKeyis reused, so this refusal and #978's two key-material omissions read one published condition in one place.#978's omission becomes a guard
kmsReportsKeyMaterialIDreturned noKeyMaterialIdat these two sites for an asymmetric key, as a workaround for substrate accepting a request AWS refuses. The request is now refused, soTestKMSKeyMaterialID_TheTwoOperationsThatReportNonenarrows to…TheOneOperationThatReportsNone(Encrypt) and the asymmetric case moves toTestKMSDataKeySpec_AnAsymmetricKeyIsRefused, which asserts the refusal in place of the absent member. The guard is kept and documented as one.Tests
New
emulator/kms_data_key_spec_test.go, five assertions, every call over the wire (#765) and every refusal pairing the code with the status (#923): a symmetric key still wraps a data key at both operations with both published members intact; all four reachable specs × both operations are refused; the error body carries neitherCiphertextBlobnorPlaintext, which is the observable form of the check running before the mint; both neighbors are ordered against; and the two operations' messages are compared to each other, which is what holds the shared helper in place.Premise corrections
Posted on the issue before this PR (comment 5723154565):
kmsKeyUsageErrorlives inkms_key_specs.go, notkms_errors.go; the pages publish nine errors, not ten; the quote is "…encrypt data keys".Verification
Nine-command gate, all green:
gofmt/build/vet,golangci-lint,make test,GOTOOLCHAIN=go1.26.6 make test, coverage,docs-reference/docs-reference-check/docs-versions/authz-reference-check,npm --prefix docs run build, and the e2e suite. Coverage holds at 85.1% emulator / 84.6% total.Closes #988