Skip to content

Commit f6947a8

Browse files
committed
fix(branch-keystore): modify AWS KMS configuration to only support single region key compatibility for now (#608)
* feat(branch-keystore): model AWS KMS configuration * feat(keystore): create class to model AWS KMS configuration for branch keystore * updated spec submodule to latest master * Update spec submodule to track master branch * feat(keystore): complete and test AWS KMS configuration class * chore: remove version file from branch-keystore-node module * chore: updated gitignore to ignore auto-generated version files in branch-keystore-node module * chore: removed changelog from branch-keystore-node module so that git can autogenerate it * added additional test for 100% coverage * made the fix and tested * remove duplicate compliance citations * specified compliance tests * fix compliance tests * fix duvet * remove duvet test annotations * add compliance tests for duvet * fix compliance tests for duvet * fix compliance tests for duvet * change lerna version * removed getParsedArn * separate kms config helpers from types * specified what's a 'bad arn' in tests * better error msg * no longer supressing errors from parseAwsKmsKeyArn * changed tests to assert for specific error messages * add a notice * sync lock file with package.json * consolidate helpers * compliance test citation * add additional flag methods to tell us config state * divide helper function tests and class method tests * add notice * Revert "change lerna version" This reverts commit a9ba112605c76295fb23cfda651f37eff9332e7b. * Update package-lock.json
1 parent b60ddee commit f6947a8

File tree

7 files changed

+305
-1079
lines changed

7 files changed

+305
-1079
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
export * from './kms_configuration'
4+
export * from './kms_config'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { getRegionFromIdentifier } from '@aws-crypto/kms-keyring'
5+
import { assertValidNotAliasArn } from './kms_config_helpers'
6+
7+
// a general interface that outlines common operations any of the 4 AWS KMS
8+
// configurations should perform
9+
export interface KmsConfig {
10+
/**
11+
* this method tells the user if the config is SRK/MRK compatibility
12+
* @returns a flag answering the method's purpose
13+
*/
14+
isKmsKeyArn(): boolean
15+
16+
/**
17+
* this method tells the user if the config is MrDiscovery
18+
* @returns a flag answering the method's purpose
19+
*/
20+
isMrDiscovery(): boolean
21+
22+
/**
23+
* this method tells the user if the config is Discovery
24+
* @returns a flag answering the method's purpose
25+
*/
26+
isDiscovery(): boolean
27+
28+
/**
29+
* this method tells the user if the config is compatible with an arn
30+
* @param otherArn
31+
* @returns a flag answering the method's purpose
32+
*/
33+
isCompatibleWithArn(otherArn: string): boolean
34+
}
35+
36+
// an interface to outline the common operations any of the 3 region-based AWS KMS
37+
// configurations should perform
38+
export interface RegionalKmsConfig extends KmsConfig {
39+
/**
40+
* this method tells the user the config's region
41+
* @returns the region
42+
*/
43+
getRegion(): string
44+
}
45+
46+
// an abstract class defining common behavior for operations that SRK and MRK compatibility
47+
// configs should perform
48+
export abstract class KmsKeyArnConfig implements RegionalKmsConfig {
49+
private _arn: string
50+
51+
//= aws-encryption-sdk-specification/framework/branch-key-store.md#aws-kms-configuration
52+
//# `KMS Key ARN` and `KMS MRKey ARN` MUST take an additional argument
53+
//# that is a KMS ARN.
54+
constructor(arn: string) {
55+
//= aws-encryption-sdk-specification/framework/branch-key-store.md#aws-kms-configuration
56+
//# This ARN MUST NOT be an Alias.
57+
//# This ARN MUST be a valid
58+
//# [AWS KMS Key ARN](./aws-kms/aws-kms-key-arn.md#a-valid-aws-kms-arn).
59+
assertValidNotAliasArn(arn)
60+
this._arn = arn
61+
}
62+
63+
getRegion(): string {
64+
return getRegionFromIdentifier(this._arn)
65+
}
66+
67+
isKmsKeyArn(): boolean {
68+
return true
69+
}
70+
71+
isMrDiscovery(): boolean {
72+
return false
73+
}
74+
75+
isDiscovery(): boolean {
76+
return false
77+
}
78+
79+
getArn(): string {
80+
return this._arn
81+
}
82+
83+
abstract isCompatibleWithArn(otherArn: string): boolean
84+
}
85+
86+
// a concrete class specifiying behavior for the SRK compatibility config
87+
export class SrkCompatibilityKmsConfig extends KmsKeyArnConfig {
88+
constructor(arn: string) {
89+
super(arn)
90+
}
91+
92+
//= aws-encryption-sdk-specification/framework/branch-key-store.md#aws-key-arn-compatibility
93+
//# For two ARNs to be compatible:
94+
95+
//# If the [AWS KMS Configuration](#aws-kms-configuration) designates single region ARN compatibility,
96+
//# then two ARNs are compatible if they are exactly equal.
97+
isCompatibleWithArn(otherArn: string): boolean {
98+
return this.getArn() === otherArn
99+
}
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { needs } from '@aws-crypto/material-management'
5+
import { ParsedAwsKmsKeyArn, parseAwsKmsKeyArn } from '@aws-crypto/kms-keyring'
6+
7+
/**
8+
* this utility function asserts that an arn is well-formed with all valid parts
9+
* as an AWS KMS resource, whose type is not alias
10+
* @param arn
11+
* @throws `${arn} must be a well-formed AWS KMS non-alias resource arn`
12+
* @throws 'Malformed.'
13+
*/
14+
export function assertValidNotAliasArn(arn: string): void {
15+
const errorMessage = `${arn} must be a well-formed AWS KMS non-alias resource arn`
16+
const parsedArn = parseAwsKmsKeyArn(arn)
17+
needs(parsedArn, errorMessage)
18+
const { ResourceType } = parsedArn as ParsedAwsKmsKeyArn
19+
needs(ResourceType !== 'alias', errorMessage)
20+
}

modules/branch-keystore-node/src/kms_configuration.ts

-224
This file was deleted.

0 commit comments

Comments
 (0)