-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(rds): unable to alter master user password when using DatabaseClusterFromSnapshot with snapshotCredentials #21730
Comments
@MitchWijt can you provide an example that I can deploy to reproduce? We have an integration test that tests this scenario and I tried to reproduce using this test and was unable to. One thing I noticed is that all DB instances have to be created before the password is updated to the new generated password. |
@corymhall The problem seems to be in the secret rotation. We have Permissions Boundary Aspects on our stack. However CDK tries to create a role for the rotating lambda function without these Aspects in a nested stack. Which is the reason it fails. Its mentioned in this issue But I do not see a solution for it at the moment. As a sidenote. Since by default the Currently the secret returned is unreliable since it can't be used to login to the Cluster that is created |
Should a rotation be needed in order for the password to be updated to the new generated password? If not, then the password is not being updated on my end. Example: new rds.DatabaseCluster(this, `DatabaseCluster`,
{
defaultDatabaseName: "postgres",
engine: rds.DatabaseClusterEngine.auroraPostgres({
version: AuroraPostgresEngineVersion.VER_13_6,
}),
instances: 1,
backup: {
retention: Duration.days(7)
},
removalPolicy: RemovalPolicy.RETAIN,
instanceProps: {
vpc: vpc,
instanceType: CustomInstanceType.SERVERLESS as unknown as ec2.InstanceType,
autoMinorVersionUpgrade: true,
publiclyAccessible: false,
vpcSubnets: {
subnets: vpc.isolatedSubnets
},
},
cloudwatchLogsExports: ["postgresql"],
}
) 2. Create Snapshot 3. Create cluster from Snapshot and deploy new rds.DatabaseClusterFromSnapshot(this, `DatabaseClusterFromSnapshot`, {
...samePropsAsStep1,
snapshotCredentials: rds.SnapshotCredentials.fromGeneratedSecret('postgres', {
excludeCharacters: '`+{}[]()\'"/\\'
}),
snapshotIdentifier: props.snapshotIdentifier
}) 4. Unable to login using generated secret |
@MitchWijt I tried again today and it's not working for me anymore. I'm not sure if something changed, or I just messed something up the last time I tried. After looking into it more, I'm not sure how it ever could have worked. In all of my testing, including with the integration test, it always uses the previous database password (which is inline with the documentation). It seems like this issue impacts a significant number of customers, and I've tagged it as P1, which means it should be on our near-term roadmap. We welcome community contributions! If you are able, we encourage you to contribute (https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) a bug fix or new feature to the CDK. If you decide to contribute, please start an engineering discussion in this issue to ensure there is a commonly understood design before submitting code. This will minimize the number of review cycles and get your code merged faster. |
I redeployed the integration test just now and indeed it doesn't work anymore... very strange. I can assure that when #20504 was merged it worked. I now have to check if the behavior has also changed for DB instances created from snapshots. I think the solution could be to use a custom resource to make a |
Should we not even try to update the password? I think if CloudFormation does not support this functionality that we should not try to hack around it. |
@corymhall I do agree with you. If it's indeed not supported, there is probably a reason for it. However, currently the secret that is returned from the snapshot has an incorrect password, even when not using the Example:
This way users can rely on the |
Yeah we should expose the original secret if we can, and if we can't then |
This cross referenced issue provides a minimally scoped reproducable v2 CDK project. #22199 |
In 2.47.0 still an issue. It will be a new password generated which doesn't fit to snapshot password. As soon as the new password is replaced with original one, which was in the stack during snapshot creation, everything works fine |
It seems like the current implementation of
I don't know of a way to expose the original secret when restoring from a snapshot. My understanding is that the original secret is never recreated when restoring from a snapshot. It's up to the user to remember the password, keep the original secret from being deleted, or change the database password using AWS console/RDS API. Solutions: A.) File this as an issue with Cfn. This will require evidence that Cfn supports restoring a DB cluster and updating the password in a single deploy. B.) Update documentation to inform the user that they must deploy the C.) We create and maintain a custom resource that changes the DB password shortly after the DB cluster is restored. Which as Cory mentioned is not ideal. I'm leaning towards B. Would that be acceptable? |
@ryparker This means whenever other services depend on these events, for example event 005 which is in my eyes option A seems like a more viable solution that would also be and feel more intuitive for users using these constructs. |
I've not looked too much into this yet, but RDS just announced a new integration with secretsmanager https://aws.amazon.com/about-aws/whats-new/2022/12/amazon-rds-integration-aws-secrets-manager/ |
What's completely bizarre is that The Event Type is ModifyDBInstance "eventTime": "2023-01-12T22:48:04Z", There is no such event after a DBClusterFromSnapshot is created. |
I am trying to restore a snapshot from prod db to my dev db, and I need to reset the password of the db with a new generated password and be saved into secretsmanager. I am stuck until this bug is fixed |
Tested this today: The only problem is that when
In summary the new |
I've created a Cfn issue for the desired behavior: aws-cloudformation/cloudformation-coverage-roadmap#1500 |
It seems this bug is fixed for me. I'm using the following code:
Please confirm or infirm above information. |
@pflueras Are you able to use that secret to login to the cluster that was created from snapshot? |
Before: the actual master password of the cluster was given by the RDS snapshot. The password of the newly created secret (SnapshotCredentials.fromGeneratedSecret) was incorrect. I had to fix the password from the secret to get the secret functional. After: the actual master password is given by the newly created secret (SnapshotCredentials.fromGeneratedSecret). The secret is fully functional. I am not sure I answered to your question.. |
@pflueras Did you confirm in Cloudtrail that Cloudformation actually reset the cluster password after it was restored? From my experience, when restoring a DBCluster from a snapshot the original snapshot master password is retained and Cloudformation never attempts to reset the password once the cluster is restored. |
@pflueras I've been investigating this and it seems from some initial testing that the bug is fixed for me too. I'm going to continue testing this today with some different variations, but I'm wondering if anyone else has had a chance to retry this with success too. @MitchWijt would you be able to retry on your end to see if this is now working for you? |
Linking related issue: #21730 |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the bug
About 2 months ago a this PR got merged, which states that we should be able to alter the master user password of the snapshot using the
snapshotCredentials
prop. However when using this prop CDK creates a new secret in Secrets Manager, but the master user password still remains unchanged. It seems like the DatabaseSecret that is created is not being used.Looking at the code of the PR, the
masterUserPassword
gets changed in thecfnDbCluster
while also having thesnapshotIdentifier
prop. However the docs state to NOT use themasterUserPassword
prop together with thesnapshotIdentifier
prop.Expected Behavior
When using the
snapshotCredentials
property withrds.SnapshotCredentials.fromGeneratedSecret()
inside theDatabaseClusterFromSnapshot
construct. I expect the master user password to be changed to the password that is generated in Secrets Manager.Current Behavior
A DatabaseSecret is created inside Secrets Manger, however the master user password of the snapshot remains unchanged.
Reproduction Steps
DatabaseCluster
construct in CDKDatabaseClusterFromSnapshot
construct to CDK using thesnapshotCredentials
withSnapshotCredentials.fromGeneratedSecret()
, and remove theDatabaseCluster
construct from CDKDatabaseClusterFromSnapshot
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.27.0
Framework Version
No response
Node.js Version
16
OS
Linux
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: