feat(rds): support native Secrets Manager integration for RDS Cluster and Instance #35734
feat(rds): support native Secrets Manager integration for RDS Cluster and Instance #35734
Conversation
|
|
||||||||||||||
|
|
||||||||||||||
| writer: rds.ClusterInstance.serverlessV2('writer'), | ||
| vpc, | ||
| manageMasterUserPassword: true, | ||
| credentials: { |
There was a problem hiding this comment.
The rest of the RDS README uses Credentials.fromUsername() for credential creation. Using a plain object literal here works but is inconsistent with the established pattern. Consider:
credentials: rds.Credentials.fromUsername('admin', {
encryptionKey: kmsKey,
}),There was a problem hiding this comment.
Good catch. Updated to use Credentials.fromUsername() for consistency.
| * When enabled, RDS generates and manages the master user password in Secrets Manager. | ||
| * Cannot be used together with credentials containing a password. | ||
| * | ||
| * @default false |
There was a problem hiding this comment.
Let's add manageMasterUserPassword to DatabaseClusterFromSnapshotProps as well. Per the AWS RDS docs, ManageMasterUserPassword is supported when restoring from snapshots. Customers migrating existing databases to RDS-managed passwords would benefit.
There was a problem hiding this comment.
Added manageMasterUserPassword to DatabaseClusterFromSnapshotProps with tests.
| addConstructMetadata(this, props); | ||
|
|
||
| const credentials = renderCredentials(this, props.engine, props.credentials); | ||
| const secret = credentials.secret; |
There was a problem hiding this comment.
This validation block is duplicated identically in instance.ts (lines 1367-1384). If a new credential property is added in the future, both locations must be updated.
Consider extracting a shared helper alongside renderCredentials:
function validateManagedPasswordCredentials(scope: Construct, credentials?: Credentials): void {
const unsupportedProps = [
credentials?.excludeCharacters && 'excludeCharacters',
credentials?.password && 'password',
credentials?.replicaRegions && 'replicaRegions',
credentials?.secret && 'secret',
credentials?.secretName && 'secretName',
credentials?.usernameAsString && 'usernameAsString',
].filter(Boolean);
if (unsupportedProps.length > 0) {
throw new ValidationError(
`When manageMasterUserPassword is enabled, only 'username' and 'encryptionKey' are allowed. Found: ${unsupportedProps.join(', ')}.`,
scope,
);
}
}There was a problem hiding this comment.
Extracted validateManagedPasswordCredentials() to private/util.ts and replaced both inline blocks.
| vpc, | ||
| writer: ClusterInstance.serverlessV2('writer'), | ||
| manageMasterUserPassword: true, | ||
| credentials: { |
There was a problem hiding this comment.
This test passes credentials as a plain object { username: 'testuser', encryptionKey: kmsKey }. Since most users will use Credentials.fromUsername(), consider adding a test (or changing this one) to verify that path works correctly with manageMasterUserPassword. The fromUsername method has internal logic that could interact differently.
There was a problem hiding this comment.
Added a test using Credentials.fromUsername() with manageMasterUserPassword.
- Use Credentials.fromUsername() in README examples for consistency - Extract shared validateManagedPasswordCredentials helper to private/util.ts - Add manageMasterUserPassword support to DatabaseClusterFromSnapshotProps - Add tests for Credentials.fromUsername() and DatabaseClusterFromSnapshot
Pull request has been modified.
…dPasswordCredentials
Issue # (if applicable)
Closes #29239.
Reason for this change
Implements the
manageMasterUserPasswordproperty for RDS clusters and instances, enabling RDS native integration with AWS Secrets Manager for automatic master user password management.Description of changes
Added
manageMasterUserPasswordproperty tords.Clusterandrds.Instance.Describe any new or updated permissions being added
N/A
Description of how you validated changes
Add unit tests and integ test.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license