Skip to content

Commit 304aac0

Browse files
committed
fix(aws-rds): addProxy can use kms encrypted secrets
1 parent 169fd91 commit 304aac0

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/aws-cdk-lib/aws-rds/lib/proxy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ export class DatabaseProxy extends DatabaseProxyBase
457457

458458
for (const secret of props.secrets) {
459459
secret.grantRead(role);
460+
if (secret.encryptionKey !== undefined) {
461+
secret.encryptionKey.grantDecrypt(role);
462+
}
460463
}
461464

462465
const securityGroups = props.securityGroups ?? [

packages/aws-cdk-lib/aws-rds/test/proxy.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Match, Template } from '../../assertions';
22
import * as ec2 from '../../aws-ec2';
33
import { AccountPrincipal, Role } from '../../aws-iam';
4+
import { Key } from '../../aws-kms';
45
import * as secretsmanager from '../../aws-secretsmanager';
56
import * as cdk from '../../core';
67
import * as cxapi from '../../cx-api';
@@ -371,6 +372,51 @@ describe('proxy', () => {
371372
}).toThrow(/When the Proxy contains multiple Secrets, you must pass a dbUser explicitly to grantConnect/);
372373
});
373374

375+
test('new Proxy with kms encrypted Secrets has permissions to kms:Decrypt that secret using its key', () => {
376+
// GIVEN
377+
const cluster = new rds.DatabaseCluster(stack, 'Database', {
378+
engine: rds.DatabaseClusterEngine.AURORA,
379+
instanceProps: { vpc },
380+
});
381+
382+
const kmsKey = new Key(stack, 'Key');
383+
384+
const kmsEncryptedSecret = new secretsmanager.Secret(stack, 'Secret', {encryptionKey: kmsKey});
385+
386+
// WHEN
387+
new rds.DatabaseProxy(stack, 'Proxy', {
388+
proxyTarget: rds.ProxyTarget.fromCluster(cluster),
389+
vpc,
390+
secrets: [kmsEncryptedSecret],
391+
});
392+
393+
// THEN
394+
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
395+
PolicyDocument: {
396+
"Statement": [
397+
{
398+
"Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ],
399+
"Effect": "Allow",
400+
"Resource": {
401+
"Ref": "SecretA720EF05"
402+
}
403+
},
404+
{
405+
"Action": "kms:Decrypt",
406+
"Effect": "Allow",
407+
"Resource": {
408+
"Fn::GetAtt": [
409+
"Key961B73FD",
410+
"Arn"
411+
]
412+
}
413+
}
414+
]
415+
},
416+
Roles: [ { "Ref": "ProxyIAMRole2FE8AB0F" } ]
417+
});
418+
});
419+
374420
test('DBProxyTargetGroup should have dependency on the proxy targets', () => {
375421
// GIVEN
376422
const cluster = new rds.DatabaseCluster(stack, 'cluster', {

0 commit comments

Comments
 (0)