Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-rds): addProxy can use kms encrypted secrets #28848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ export class DatabaseProxy extends DatabaseProxyBase

for (const secret of props.secrets) {
secret.grantRead(role);
if (secret.encryptionKey !== undefined) {
secret.encryptionKey.grantDecrypt(role);
}
}

const securityGroups = props.securityGroups ?? [
Expand Down
46 changes: 46 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Match, Template } from '../../assertions';
import * as ec2 from '../../aws-ec2';
import { AccountPrincipal, Role } from '../../aws-iam';
import { Key } from '../../aws-kms';
import * as secretsmanager from '../../aws-secretsmanager';
import * as cdk from '../../core';
import * as cxapi from '../../cx-api';
Expand Down Expand Up @@ -371,6 +372,51 @@ describe('proxy', () => {
}).toThrow(/When the Proxy contains multiple Secrets, you must pass a dbUser explicitly to grantConnect/);
});

test('new Proxy with kms encrypted Secrets has permissions to kms:Decrypt that secret using its key', () => {
// GIVEN
const cluster = new rds.DatabaseCluster(stack, 'Database', {
engine: rds.DatabaseClusterEngine.AURORA,
instanceProps: { vpc },
});

const kmsKey = new Key(stack, 'Key');

const kmsEncryptedSecret = new secretsmanager.Secret(stack, 'Secret', {encryptionKey: kmsKey});

// WHEN
new rds.DatabaseProxy(stack, 'Proxy', {
proxyTarget: rds.ProxyTarget.fromCluster(cluster),
vpc,
secrets: [kmsEncryptedSecret],
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', {
PolicyDocument: {
"Statement": [
{
"Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ],
"Effect": "Allow",
"Resource": {
"Ref": "SecretA720EF05"
}
},
{
"Action": "kms:Decrypt",
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": [
"Key961B73FD",
"Arn"
]
}
}
]
},
Roles: [ { "Ref": "ProxyIAMRole2FE8AB0F" } ]
});
});

test('DBProxyTargetGroup should have dependency on the proxy targets', () => {
// GIVEN
const cluster = new rds.DatabaseCluster(stack, 'cluster', {
Expand Down
Loading