Skip to content

Commit 8da006a

Browse files
feat(redshift): expose user.secret as property (#17520) (#20078)
This change will expose Redshift User.secret as property and close #17520 ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 82aec9d commit 8da006a

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

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

+21-18
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,6 @@ The endpoint to access your database cluster will be available as the `.clusterE
6060
cluster.clusterEndpoint.socketAddress; // "HOSTNAME:PORT"
6161
```
6262

63-
## Rotating credentials
64-
65-
When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:
66-
67-
```ts fixture=cluster
68-
cluster.addRotationSingleUser(); // Will rotate automatically after 30 days
69-
```
70-
71-
The multi user rotation scheme is also available:
72-
73-
```ts fixture=cluster
74-
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
75-
76-
cluster.addRotationMultiUser('MyUser', {
77-
secret: secretsmanager.Secret.fromSecretNameV2(this, 'Imported Secret', 'my-secret'),
78-
});
79-
```
80-
8163
## Database Resources
8264

8365
This module allows for the creation of non-CloudFormation database resources such as users
@@ -273,3 +255,24 @@ call to `grant` but the user does not have the specified permission.
273255

274256
Note that this does not occur when duplicate privileges are granted within the same
275257
application, as such privileges are de-duplicated before any SQL query is submitted.
258+
259+
## Rotating credentials
260+
261+
When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:
262+
263+
```ts fixture=cluster
264+
cluster.addRotationSingleUser(); // Will rotate automatically after 30 days
265+
```
266+
267+
The multi user rotation scheme is also available:
268+
269+
```ts fixture=cluster
270+
271+
const user = new User(this, 'User', {
272+
cluster: cluster,
273+
databaseName: 'databaseName',
274+
});
275+
cluster.addRotationMultiUser('MultiUserRotation', {
276+
secret: user.secret,
277+
});
278+
```

packages/@aws-cdk/aws-redshift/lib/user.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as kms from '@aws-cdk/aws-kms';
2+
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
23
import * as cdk from '@aws-cdk/core';
34
import { Construct } from 'constructs';
45
import { ICluster } from './cluster';
@@ -137,6 +138,12 @@ export class User extends UserBase {
137138
readonly databaseName: string;
138139
protected databaseProps: DatabaseOptions;
139140

141+
/**
142+
* The Secrets Manager secret of the user.
143+
* @attribute
144+
*/
145+
public readonly secret: secretsmanager.ISecret;
146+
140147
private resource: DatabaseQuery<UserHandlerProps>;
141148

142149
constructor(scope: Construct, id: string, props: UserProps) {
@@ -165,6 +172,7 @@ export class User extends UserBase {
165172
attachedSecret.grantRead(this.resource);
166173

167174
this.username = this.resource.getAttString('username');
175+
this.secret = secret;
168176
}
169177

170178
/**

packages/@aws-cdk/aws-redshift/test/user.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ describe('cluster user', () => {
9090
});
9191
});
9292

93+
it('secret property is exposed', () => {
94+
const user = new redshift.User(stack, 'User', databaseOptions);
95+
96+
expect(stack.resolve(user.secret.secretArn)).toStrictEqual({
97+
Ref: 'UserSecretE2C04A69',
98+
});
99+
});
100+
93101
it('uses username when provided', () => {
94102
const username = 'username';
95103

0 commit comments

Comments
 (0)