Skip to content

Commit ab9c8e4

Browse files
jumicTikiTDO
authored andcommitted
feat(docdb): add the ability to exclude characters when generating passwords (aws#17262)
Add property `excludeCharaters` to provide the ability to exclude characters when generating passwords in DocumentDB. Requested in aws#15732. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b67ee4c commit ab9c8e4

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +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 "\"@/"
2425
},
2526
instanceType: ec2.InstanceType.of(ec2.InstanceClass.R5, ec2.InstanceSize.LARGE),
2627
vpcSubnets: {

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

+1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export class DatabaseCluster extends DatabaseClusterBase {
352352
secret = new DatabaseSecret(this, 'Secret', {
353353
username: props.masterUser.username,
354354
encryptionKey: props.masterUser.kmsKey,
355+
excludeCharacters: props.masterUser.excludeCharacters,
355356
});
356357
}
357358

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ export interface DatabaseSecretProps {
3232
* @default - no master secret information will be included
3333
*/
3434
readonly masterSecret?: ISecret;
35+
36+
/**
37+
* Characters to not include in the generated password.
38+
*
39+
* @default "\"@/"
40+
*/
41+
readonly excludeCharacters?: string;
3542
}
3643

3744
/**
@@ -61,7 +68,7 @@ export class DatabaseSecret extends Secret {
6168
masterarn: props.masterSecret?.secretArn,
6269
}),
6370
generateStringKey: 'password',
64-
excludeCharacters: '"@/',
71+
excludeCharacters: props.excludeCharacters ?? '"@/',
6572
},
6673
});
6774
}

packages/@aws-cdk/aws-docdb/lib/props.ts

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export interface Login {
5353
* @default default master key
5454
*/
5555
readonly kmsKey?: kms.IKey;
56+
57+
/**
58+
* Specifies characters to not include in generated passwords.
59+
*
60+
* @default "\"@/"
61+
*/
62+
readonly excludeCharacters?: string;
5663
}
5764

5865
/**

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect as expectCDK, haveResource, ResourcePart, arrayWith } from '@aws-cdk/assert-internal';
1+
import { expect as expectCDK, haveResource, ResourcePart, arrayWith, haveResourceLike, objectLike } from '@aws-cdk/assert-internal';
22
import * as ec2 from '@aws-cdk/aws-ec2';
33
import * as kms from '@aws-cdk/aws-kms';
44
import * as cdk from '@aws-cdk/core';
@@ -293,6 +293,29 @@ describe('DatabaseCluster', () => {
293293
}));
294294
});
295295

296+
test('creates a secret with excludeCharacters', () => {
297+
// GIVEN
298+
const stack = testStack();
299+
const vpc = new ec2.Vpc(stack, 'VPC');
300+
301+
// WHEN
302+
new DatabaseCluster(stack, 'Database', {
303+
masterUser: {
304+
username: 'admin',
305+
excludeCharacters: '"@/()[]',
306+
},
307+
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
308+
vpc,
309+
});
310+
311+
// THEN
312+
expectCDK(stack).to(haveResourceLike('AWS::SecretsManager::Secret', {
313+
GenerateSecretString: objectLike({
314+
ExcludeCharacters: '\"@/()[]',
315+
}),
316+
}));
317+
});
318+
296319
test('create an encrypted cluster with custom KMS key', () => {
297320
// GIVEN
298321
const stack = testStack();

0 commit comments

Comments
 (0)