Skip to content

Commit 1fe2215

Browse files
authoredNov 25, 2021
fix(docdb): secret rotation ignores excluded characters in password (#17609)
We need to pass whatever `excludeCharacters` were passed to the generated Secret to the application responsible for the rotation. Fixes #17347 Fixes #17575 ------ *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 2d19e15 commit 1fe2215

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed
 

‎packages/@aws-cdk/aws-docdb/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ your instances will be launched privately or publicly:
2121
const cluster = new DatabaseCluster(this, 'Database', {
2222
masterUser: {
2323
username: 'myuser' // NOTE: 'admin' is reserved by DocumentDB
24-
excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/"
24+
excludeCharacters: '\"@/:', // optional, defaults to the set "\"@/" and is also used for eventually created rotations
2525
secretName: '/myapp/mydocdb/masteruser', // optional, if you prefer to specify the secret name
2626
},
2727
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),

‎packages/@aws-cdk/aws-docdb/lib/cluster.ts

+2
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
491491
secret: this.secret,
492492
automaticallyAfter,
493493
application: DatabaseCluster.SINGLE_USER_ROTATION_APPLICATION,
494+
excludeCharacters: (this.node.tryFindChild('Secret') as DatabaseSecret)._excludedCharacters,
494495
vpc: this.vpc,
495496
vpcSubnets: this.vpcSubnets,
496497
target: this,
@@ -508,6 +509,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
508509
secret: options.secret,
509510
masterSecret: this.secret,
510511
automaticallyAfter: options.automaticallyAfter,
512+
excludeCharacters: (this.node.tryFindChild('Secret') as DatabaseSecret)._excludedCharacters,
511513
application: DatabaseCluster.MULTI_USER_ROTATION_APPLICATION,
512514
vpc: this.vpc,
513515
vpcSubnets: this.vpcSubnets,

‎packages/@aws-cdk/aws-docdb/lib/database-secret.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ export interface DatabaseSecretProps {
4848
* @resource AWS::SecretsManager::Secret
4949
*/
5050
export class DatabaseSecret extends Secret {
51+
52+
/**
53+
* the excluded characters for this Secret
54+
* @internal
55+
*/
56+
public readonly _excludedCharacters: string;
57+
5158
constructor(scope: Construct, id: string, props: DatabaseSecretProps) {
59+
const excludedCharacters = props.excludeCharacters ?? '"@/';
60+
5261
super(scope, id, {
5362
secretName: props.secretName,
5463
description: `Generated by the CDK for stack: ${Aws.STACK_NAME}`,
@@ -68,8 +77,10 @@ export class DatabaseSecret extends Secret {
6877
masterarn: props.masterSecret?.secretArn,
6978
}),
7079
generateStringKey: 'password',
71-
excludeCharacters: props.excludeCharacters ?? '"@/',
80+
excludeCharacters: excludedCharacters,
7281
},
7382
});
83+
84+
this._excludedCharacters = excludedCharacters;
7485
}
7586
}

‎packages/@aws-cdk/aws-docdb/test/cluster.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ describe('DatabaseCluster', () => {
684684
],
685685
},
686686
functionName: 'DatabaseRotationSingleUser458A45BE',
687+
excludeCharacters: '\"@/',
687688
vpcSubnetIds: {
688689
'Fn::Join': [
689690
'',
@@ -796,6 +797,7 @@ describe('DatabaseCluster', () => {
796797
],
797798
},
798799
functionName: 'DatabaseRotation0D47EBD2',
800+
excludeCharacters: '\"@/',
799801
vpcSubnetIds: {
800802
'Fn::Join': [
801803
'',

‎packages/@aws-cdk/aws-docdb/test/integ.cluster-rotation.lit.expected.json

+1
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@
785785
]
786786
},
787787
"functionName": "awscdkdocdbclusterrotationDatabaseRotationSingleUser7DAE65BE",
788+
"excludeCharacters": "\"@/",
788789
"vpcSubnetIds": {
789790
"Fn::Join": [
790791
"",

0 commit comments

Comments
 (0)
Please sign in to comment.