Repository navigation
feat(kms): one KeyMetadata builder, and the sixteen members it stopped withholding (#974) - #982
Merged
Merged
Conversation
…d withholding (#974) DescribeKey answered 10 of API_KeyMetadata's 26 members and CreateKey answered 9 from a second map of its own. Five of the absent ones are sent by AWS on every call for a plain customer symmetric key — AWSAccountId, KeyManager, Origin, EncryptionAlgorithms and the deprecated CustomerMasterKeySpec — so a consumer reading any of them got a missing field where AWS always has a value. Nothing added here is a simulation: three of the five are constants for every key substrate can create and the other two are functions of KeySpec and KeyUsage, both of which the key already carried, which makes this the same finding as #971 read from the other side. The builder is shared because AWS shares the shape, its page naming CreateKey, DescribeKey and ReplicateKey as the three operations that answer it — and substrate's two maps had already drifted, #963 having added DeletionDate to one and not the other. A test compares the two responses member by member on raw bytes. ReplicateKey is unimplemented; when it arrives it builds from the same place. KeyManager is a constant because substrate mints no AWS managed key, which is also why #972's AWS-managed restriction is unreachable rather than unenforced; Origin is one because neither ImportKeyMaterial nor any custom key store exists, which is why ExpirationModel, ValidTo and XksKeyConfiguration stay absent. The four algorithm members are mutually exclusive on KeyUsage, and KeyAgreementAlgorithms' condition is substrate's reading — the other three publish one and it publishes none, so reporting ECDH on a NIST-curve signing key would offer DeriveSharedSecret on a key AWS reserves for Sign. An empty list is omitted rather than sent as [], because #977 lets a key carry a usage and a spec AWS would never pair. CustomerMasterKeySpec is answered but omitted for the four specs outside its own narrower thirteen-value enum, AWS documenting no answer for a case its deprecation predates. Ten members stay absent and all ten are asserted absent, RotationEnabled included.
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 #974.
API_KeyMetadatapublishes 26 members.DescribeKeyanswered 10 of them andCreateKeyanswered 9 from a second map of its own. Five of the absent ones are sent by AWS on every call for a plain customer symmetric key —AWSAccountId,KeyManager,Origin,EncryptionAlgorithmsand the deprecatedCustomerMasterKeySpec— so a consumer reading any of them got a missing field from substrate where AWS always has a value. That is #765's failure mode aimed at a response shape.Nothing added here is a simulation. Three of the five are constants for every key substrate can create and the other two are functions of
KeySpecandKeyUsage, both of which the key already carried. Every member added is a value substrate already knew and withheld — which is what makes this and #971 the same finding read from two sides: that issue removed the one member substrate emitted and AWS does not publish, this one adds the members AWS publishes and substrate did not emit.One builder, because AWS has one shape
The type's page says it "is used as a response element for the
CreateKey,DescribeKey, andReplicateKeyoperations", and substrate's two hand-built maps had already drifted: #963 addedDeletionDatetoDescribeKey's and leftCreateKey's alone, so two operations disagreed about one documented type. That is the defect class #952 catalogues, and neither operation's own test could see it, because each asserted its own response against the page rather than against the other. A test now compares the two responses member by member on raw bytes.ReplicateKeyis the third caller AWS names and substrate does not implement it. When it arrives it must build from here rather than grow a third map, and the file's preamble says so.Three constants, each recording a limit
AWSAccountIdDescribeKeyseparates, so that is the call the test makes (#737's distinction aimed at a response member)KeyManagerCUSTOMEROriginAWS_KMSImportKeyMaterialnor any custom key store exists, which is whyExpirationModel,ValidToandXksKeyConfigurationstay absent for the same single reason rather than three separate onesOne algorithm list, selected by the key usage
Each of the four algorithm members names a
KeyUsageas its presence condition, and a key has exactly one usage — so theswitchis what makes them mutually exclusive rather than four independent branches. Contents come from the developer guide's key spec reference, the same table #969 read for encryption: the six RSA signing algorithms shared by all three RSA specs, one per NIST curve,ECC_NIST_EDWARDS25519's two,ML_DSA_SHAKE_256for all three ML-DSA specs (stated in prose, not the table), the HMAC bijection AWS explains with "the length of the key determines the MAC algorithm", andECDHfor the NIST curves andSM2.Two decisions worth naming:
KeyAgreementAlgorithms' presence condition is substrate's reading. The other three publish one; this member publishes none at all — its whole description is "the key agreement algorithm used to derive a shared secret".KEY_AGREEMENTis a publishedKeyUsageand a key has one usage, so following the pattern of the three that do state a condition is the narrowest reading available. The case that separates the readings is a NIST-curve key withKeyUsageSIGN_VERIFY: its spec admitsECDH, and reporting it would tell a callerDeriveSharedSecretwas available on a key AWS reserves forSign. A test pins it.[]. kms: CreateKey validates neither KeySpec nor KeyUsage, and no cryptographic operation refuses a key whose KeyUsage is not ENCRYPT_DECRYPT #977 lets a key carry a usage and a spec AWS would never pair, and such a key admits nothing. An empty array claims "this key supports no encryption algorithms", which AWS never says about a key it accepted; the absent member says nothing, per cfn: Ref returns the physical ID for every type, but AWS returns an ARN for an ELBv2 load balancer and target group #827. The two are indistinguishable once decoded, which is why every assertion in the new file is on raw JSON.CustomerMasterKeySpec, answered and then omitted outside its own enumAWS still sends it — "the
KeySpecandCustomerMasterKeySpecfields have the same value… to avoid breaking changes, AWS KMS supports both fields" — so dropping it as obsolete would omit a member AWS sends, which is the defect this issue is about. But its enum is narrower thanKeySpec's: 13 valid values against 17. The four specs added since the deprecation —ML_DSA_44,ML_DSA_65,ML_DSA_87,ECC_NIST_EDWARDS25519— appear only underKeySpec, so a key with one of those has no admissible value for the older member. Substrate omits it there. AWS documents no answer for a case its own deprecation predates, so that is a reading; the alternative puts a value outside the member's published set on the wire.The ten that stay absent, asserted absent
Six fall out of the two constants above. The rest need a custom key store (
CloudHsmClusterId,CustomKeyStoreId), a replica (MultiRegionConfiguration— substrate stores the flag but models no replica, so it would report a primary with an emptyReplicaKeyslist), thePendingReplicaDeletionstate (PendingDeletionWindowInDays, whose range is 1–365 rather thanScheduleKeyDeletion's 7–30, so reporting the waiting period under it would be wrong twice over), or a key material identity (CurrentKeyMaterialId, #978).RotationEnabledis asserted absent beside them, and that is deliberate: adding sixteen members from a page is exactly the moment someone working from the struct rather than the page would put #971's member back.Every non-symmetric key in the new tests is created through the gap #977 records, which is why #977 must re-verify this file when it closes it — the same note
kms_rotation_key_type_test.goandkms_encryption_algorithm_test.goalready carry.Provenance
KeyManager's andOrigin's valid values and glosses; the deprecation sentence andCustomerMasterKeySpec's 13 valid values againstKeySpec's 17; every per-spec signing, MAC and key-agreement algorithm list, including the ML-DSA prose and the two ECC specs excluded from key agreement;DeletionDate's andPendingDeletionWindowInDays' conditions and the latter's 1–365 range.KeyAgreementAlgorithms' presence condition (AWS publishes none); omittingCustomerMasterKeySpecfor the four specs outside its enum (AWS documents no answer); omitting an empty algorithm list rather than sending[](cfn: Ref returns the physical ID for every type, but AWS returns an ARN for an ELBv2 load balancer and target group #827);KeyManagerandOriginas constants, each stated with the operation that would have to exist to make it a stored field.Verification
Nine-command gate green. Coverage 84.4% emulator / 83.9% total, holding the level #972/#973 set. Seven mutants introduced and all seven caught: emitting
CustomerMasterKeySpecunconditionally, emitting an empty algorithm list, reporting the key as AWS managed, reportingECDHon a signing key, dropping one member fromCreateKey's copy of the shape, collapsing Edwards' two signing algorithms to one, and reportingDeletionDatewhatever the key state.