Repository navigation
feat(kms): a key material identity, and the six members reporting it (#978) - #989
Merged
Merged
Conversation
…978) API_KeyMetadata publishes CurrentKeyMaterialId and five operation responses carry the same identity under four other names — Decrypt's KeyMaterialId, ReEncrypt's SourceKeyMaterialId and DestinationKeyMaterialId, and a KeyMaterialId on each of GenerateDataKey and GenerateDataKeyWithoutPlaintext. Substrate modeled no key material at all, so all six were absent. The value is stored on the key and read from it at every site, which is what makes it worth reporting: a caller compares what Decrypt reports against what DescribeKey reports and learns that the material which decrypted its data is the material the key holds. A value each site computed for itself would satisfy that comparison by construction. ReEncrypt is where it shows — its two members are the only two material identities in one response, and each follows its own key, so a re-encryption out of an asymmetric key into a symmetric one reports the destination member alone. Derived rather than drawn from crypto/rand: SHA-256 over the key's own ARN with a domain-separation prefix. All six members are fixed at length 64 with pattern ^[a-f0-9]+$, and a SHA-256 digest hex-encodes to exactly 64 lowercase hex characters, so nothing is truncated or reshaped. Encrypt publishes no such member, and a test asserts its three exactly, so a later sweep over the operations that report key material cannot add a site AWS does not have. Two readings are substrate's. Rotation mints no new material: nothing rotates, ListKeyRotations and RotateKeyOnDemand are unimplemented, and a second identity nothing can list or ask for would be a value no call could reach. And both GenerateDataKey* operations are held to the same symmetric-encryption-key condition as the other four although their pages state none, because both require a symmetric encryption key at AWS while substrate's check tests the usage rather than the spec — filed as #988.
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.
Closes #978.
API_KeyMetadatapublishesCurrentKeyMaterialId— "identifies the current key material… AWS KMS uses the current key material for both encryption and decryption, and the non-current key material for decryption operations only" — and five operation responses carry the same identity under four other names. Substrate modelled no key material at all, so all six members were absent.The member set is six, not five, and the conditions differ per page
The issue's table lists five members and says all five are "conditional on the key being a symmetric encryption key". Both claims are corrected on the record here; the issue itself flagged the two
GenerateDataKey*rows "Verify against each page before implementing", and that is what the verification found.CreateKey,DescribeKeyCurrentKeyMaterialIdAWS_KMSorEXTERNALorigin"DecryptKeyMaterialIdReEncryptSourceKeyMaterialIdReEncryptDestinationKeyMaterialIdGenerateDataKeyKeyMaterialIdRecipientparameter"GenerateDataKeyWithoutPlaintextKeyMaterialIdEncryptpublishes none. Its Response Syntax is exactlyCiphertextBlob,EncryptionAlgorithmandKeyId, which the issue asked be confirmed and recorded — a test now asserts those three exactly, so a later sweep over "the operations that report key material" cannot add a fifth site AWS does not have. The asymmetry is AWS's and is not obviously deliberate:Encryptnames the material it used no more thanDecryptnames the material that produced the ciphertext it was handed.Stored on the key, not computed per site
The material ID is minted once at
CreateKey, stored onKMSKey, and read from the key at all six sites. That is not an implementation preference — it is what makes the value worth reporting. AWS's member is named Current, and "current" is only meaningful against material that can change; more practically, a caller compares whatDecryptreports against whatDescribeKeyreports and learns that the material which decrypted its data is the material the key holds. A value each site computed for itself would satisfy that comparison by construction and prove nothing about the key.ReEncryptis where it shows. Its two members are the only two material identities in one response — AWS's own sample renders two different values — and each follows its own key, so a re-encryption out of an asymmetric key into a symmetric one reports the destination member alone. Reporting both from one key, or either from the wrong one, still produces two well-formed 64-hex values, which is why the test compares each against its own key'sDescribeKeyrather than against a literal.The derivation
SHA-256over the key's own ARN with a domain-separation prefix, notcrypto/rand. All six members are constrained to a fixed length of 64 with pattern^[a-f0-9]+$, and aSHA-256digest hex-encodes to exactly 64 lowercase hex characters — so unlikecfnDeterministicUUID, which reaches for the same hash and then reshapes it, nothing is truncated or re-encoded. The ARN already carries the account, the Region and the key ID, so two keys never collide; the derivation adds no nondeterminism of its own and becomes fully deterministic the day #856 reaches the key ID itself.The domain-separation prefix is not decoration: nothing else in the tree hashes a KMS key ARN today, a bare digest of one is the obvious thing for a later minter to reach for, and two identities that must differ colliding on one hash is not a failure any test would think to look for.
Two readings recorded as substrate's
Rotation mints no new material. Nothing rotates —
ListKeyRotationsandRotateKeyOnDemandare unimplemented, andKMSKey.RotationEnabledDatealready records that a rotation schedule here is a value reported to a caller rather than an event that fires. A second material identity nothing can list or ask for would be a value no call could reach, soCurrentis true in the trivial sense: it is the only material the key has ever had. The comment states the condition for changing this — minting on rotation means implementingListKeyRotationsalongside it, so the non-current identitiesDecryptis documented to still accept are observable.Both
GenerateDataKey*operations are held to the same symmetric-encryption-key condition as the other four, although their own pages state none. Both operations require a symmetric encryption key at AWS, which is why neither page needs a condition — but substrate's check tests the key usage rather than the key spec, so anRSA_2048key withKeyUsageENCRYPT_DECRYPTreaches both. That is filed as #988. Reporting unconditionally would put a material ID on a response AWS cannot produce, inventing a value for a state that exists only because of that defect; omitting says nothing about a request that should not have succeeded, which is #827's honest-empty reading. When #988 lands the condition stops carrying those two sites and becomes a guard at them, and the code says so.Note that "symmetric encryption key" is narrower than "symmetric key": the four
HMAC_*specs are symmetric, hold key material and encrypt nothing, so they report none. All seventeen key specs are walked by a test for exactly that reason — an implementation reading the condition as "not asymmetric" passes every other row and fails those four.CurrentKeyMaterialIdleaveskmsUnreachableMetadataMembers, which drops from nine members to eight, and thedocs/services.mdtable of absent members is corrected with it (its count was already loose, and each remaining row now names the members it covers).Verification
The nine-command gate passes. Coverage holds the baseline at 84.4% emulator / 83.9% total. Every assertion goes over the wire (#765).