- Newest
- Most votes
- Most comments
You're correct that assigning a pre-created AWS Secrets Manager secret to an RDS DB cluster using CloudFormation (CFN) is not straightforward, and there are some limitations to consider.
The MasterUserSecret property in the AWS::RDS::DBCluster resource is primarily designed as a return value, not an input. When you set ManageMasterUserPassword to true, RDS automatically creates and manages a secret for the master user password. This secret is then returned in the MasterUserSecret property, which you can reference in other parts of your stack if needed.
You cannot directly assign a pre-created secret to the MasterUserSecret property. This is why your attempt to set the SecretArn didn't work as expected.
The approach you mentioned using the resolve function with Secrets Manager is a valid workaround:
MasterUsername: !Sub '{{resolve:secretsmanager:${DbSecret}:SecretString:username}}' MasterUserPassword: !Sub '{{resolve:secretsmanager:${DbSecret}:SecretString:password}}'
However, you're right to be concerned about rotation. When the secret is rotated, these values won't automatically update in your RDS cluster.
To address this, you have a few options:
-
Use the RDS-managed secret by setting
ManageMasterUserPassword: trueand let RDS handle the creation and rotation of the secret. -
If you need to use a pre-created secret, you can use the
resolvefunction as shown above, but you'll need to implement a custom solution to update the RDS cluster when the secret rotates. This could involve using a Lambda function triggered by secret rotation events. -
Consider using IAM database authentication instead of password authentication if your use case allows it. This can be more secure and easier to manage.
The MasterUserSecret property, while it may seem limited, serves the purpose of returning the ARN and other details of the RDS-managed secret when you use ManageMasterUserPassword: true. This can be useful for retrieving the secret details in other parts of your infrastructure or application.
In summary, while you can't directly assign a pre-created secret to an RDS cluster at the CFN level, you can use the resolve function as a workaround. However, for simplicity and automatic rotation, using the RDS-managed secret (ManageMasterUserPassword: true) is often the recommended approach.
Sources
Password management with Amazon RDS and AWS Secrets Manager - Amazon Relational Database Service
Amazon Relational Database Service (Amazon RDS) controls - AWS Control Tower
Get a secret or secret value from Secrets Manager - AWS CloudFormation
AWS::RDS::DBCluster MasterUserSecret - AWS CloudFormation
Relevant content
- asked 4 years ago
- asked a year ago
- AWS OFFICIALUpdated 3 years ago
