Skip to content

Commit d1e7c67

Browse files
authored
Ensure different key ids use different client instances (#196)
1 parent 5e79eef commit d1e7c67

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

schemaregistry/rules/encryption/awskms/aws-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import {AwsCredentialIdentity, AwsCredentialIdentityProvider} from "@smithy/type
1010
export class AwsKmsClient implements KmsClient {
1111

1212
private kmsClient: KMSClient
13+
private keyUri: string
1314
private keyId: string
1415

1516
constructor(keyUri: string, creds?: AwsCredentialIdentity | AwsCredentialIdentityProvider) {
1617
if (!keyUri.startsWith(AwsKmsDriver.PREFIX)) {
1718
throw new Error(`key uri must start with ${AwsKmsDriver.PREFIX}`)
1819
}
20+
this.keyUri = keyUri
1921
this.keyId = keyUri.substring(AwsKmsDriver.PREFIX.length)
2022
const tokens = this.keyId.split(':')
2123
if (tokens.length < 4) {
@@ -29,7 +31,7 @@ export class AwsKmsClient implements KmsClient {
2931
}
3032

3133
supported(keyUri: string): boolean {
32-
return keyUri.startsWith(AwsKmsDriver.PREFIX)
34+
return this.keyUri === keyUri
3335
}
3436

3537
async encrypt(plaintext: Buffer): Promise<Buffer> {

schemaregistry/rules/encryption/azurekms/azure-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ export class AzureKmsClient implements KmsClient {
77
private static ALGORITHM: EncryptionAlgorithm = 'RSA-OAEP-256'
88

99
private kmsClient: CryptographyClient
10+
private keyUri: string
1011
private keyId: string
1112

1213
constructor(keyUri: string, creds: TokenCredential) {
1314
if (!keyUri.startsWith(AzureKmsDriver.PREFIX)) {
1415
throw new Error(`key uri must start with ${AzureKmsDriver.PREFIX}`)
1516
}
17+
this.keyUri = keyUri
1618
this.keyId = keyUri.substring(AzureKmsDriver.PREFIX.length)
1719
this.kmsClient = new CryptographyClient(this.keyId, creds)
1820
}
1921

2022
supported(keyUri: string): boolean {
21-
return keyUri.startsWith(AzureKmsDriver.PREFIX)
23+
return this.keyUri === keyUri
2224
}
2325

2426
async encrypt(plaintext: Buffer): Promise<Buffer> {

schemaregistry/rules/encryption/gcpkms/gcp-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ import {KeyManagementServiceClient} from "@google-cloud/kms";
55
export class GcpKmsClient implements KmsClient {
66

77
private kmsClient: KeyManagementServiceClient
8+
private keyUri: string
89
private keyId: string
910

1011
constructor(keyUri: string, creds?: GcpCredentials) {
1112
if (!keyUri.startsWith(GcpKmsDriver.PREFIX)) {
1213
throw new Error(`key uri must start with ${GcpKmsDriver.PREFIX}`)
1314
}
15+
this.keyUri = keyUri
1416
this.keyId = keyUri.substring(GcpKmsDriver.PREFIX.length)
1517
this.kmsClient = creds != null
1618
? new KeyManagementServiceClient({credentials: creds})
1719
: new KeyManagementServiceClient()
1820
}
1921

2022
supported(keyUri: string): boolean {
21-
return keyUri.startsWith(GcpKmsDriver.PREFIX)
23+
return this.keyUri === keyUri
2224
}
2325

2426
async encrypt(plaintext: Buffer): Promise<Buffer> {

schemaregistry/rules/encryption/hcvault/hcvault-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import NodeVault from "node-vault";
55
export class HcVaultClient implements KmsClient {
66

77
private kmsClient: NodeVault.client
8+
private keyUri: string
89
private keyId: string
910
private keyName: string
1011

1112
constructor(keyUri: string, namespace?: string, token?: string) {
1213
if (!keyUri.startsWith(HcVaultDriver.PREFIX)) {
1314
throw new Error(`key uri must start with ${HcVaultDriver.PREFIX}`)
1415
}
16+
this.keyUri = keyUri
1517
this.keyId = keyUri.substring(HcVaultDriver.PREFIX.length)
1618
let url = new URL(this.keyId)
1719
let parts = url.pathname.split('/')
@@ -28,7 +30,7 @@ export class HcVaultClient implements KmsClient {
2830
}
2931

3032
supported(keyUri: string): boolean {
31-
return keyUri.startsWith(HcVaultDriver.PREFIX)
33+
return this.keyUri === keyUri
3234
}
3335

3436
async encrypt(plaintext: Buffer): Promise<Buffer> {

0 commit comments

Comments
 (0)