|
1 | 1 | import { Match, Template } from '../../assertions'; |
2 | 2 | import * as ec2 from '../../aws-ec2'; |
3 | 3 | import { AccountPrincipal, Role } from '../../aws-iam'; |
| 4 | +import { Key } from '../../aws-kms'; |
4 | 5 | import * as secretsmanager from '../../aws-secretsmanager'; |
5 | 6 | import * as cdk from '../../core'; |
6 | 7 | import * as cxapi from '../../cx-api'; |
@@ -371,6 +372,51 @@ describe('proxy', () => { |
371 | 372 | }).toThrow(/When the Proxy contains multiple Secrets, you must pass a dbUser explicitly to grantConnect/); |
372 | 373 | }); |
373 | 374 |
|
| 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 | + |
374 | 420 | test('DBProxyTargetGroup should have dependency on the proxy targets', () => { |
375 | 421 | // GIVEN |
376 | 422 | const cluster = new rds.DatabaseCluster(stack, 'cluster', { |
|
0 commit comments