-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Creating a secret with SecretRotationApplication.POSTGRES_ROTATION_SINGLE_USER doesn't seem to work #6358
Comments
You need to work with the attached secret (which contains DB informations): const attachedSecret = secret.attach(database);
const databaseSecretRotation = new SecretRotation(
this,
`consumer-api-rotation`,
{
secret: attachedSecret, # use attached secret
application: SecretRotationApplication.POSTGRES_ROTATION_SINGLE_USER,
vpc,
vpcSubnets: vpc.selectSubnets({ subnetType: SubnetType.PRIVATE }),
target: database,
automaticallyAfter: Duration.days(30),
}
); You can also work from the database with |
@jogold, thank you for the very prompt response. Unfortunately even after deleting the whole stack and recreating it using the attached version of the secret, I'm still getting 'Database engine must be set to 'postgres' in order to use this rotation lambda' when I run the rotation. |
What is the content of the json in the secret? |
Edit: I'm going to double check that the secret ARN matches with the logs, because in the Lambda logs I'm seeing it successfully pull down the secret, and I don't understand how it'd give this error with that secret. |
Ok, I'm really not sure what's going on. It looks like the lambda on first run creates the secret successfully, and then fails on subsequent runs. This is an Aurora Postgres Serverless cluster if that makes a difference. Here are the logs from creation:
|
My working hypothesis is:
So, if that's correct the solution is to create the user with the password that the lambda is expecting. I was creating it with a random password I generated because I (incorrectly) assumed the rotation would work with the database master secret to set the user's password, not the user's password itself. |
The single user rotation scheme is supposed to be used with the master credentials. The error you get comes from this line: Not sure this is a CDK issue. |
Yup, that fixed it, just needed to create the user with the current secret value as the password so the rotation could log in as that user. If rotations aren't meant to be used with other user accounts the docs here should be updated as they seem to say otherwise:
Happy to flag the confusing error message wherever those lambdas are maintained. Could you let me know where I should create that issue? |
Normally with other users accounts you use the multi user scheme, more info here https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets-one-user-one-password.html and here https://docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets-two-users.html
This might be the right repo https://github.com/aws-samples/aws-secrets-manager-rotation-lambdas |
That makes sense, but that's not working either. I updated to:
and I'm getting:
after I destroy the stack, create it, then create the user with the credentials in the secret. |
You have to "manually" add the Something like: const userSecret = new Secret(this, 'UserSecret', {
generateSecretString: {
secretStringTemplate: JSON.stringify({
username: 'your-user-name',
masterarn: database.secret.secretArn
}),
generateStringKey: 'password'
}
});
const attachedSecret = userSecret.attach(database); Then your
|
Exactly what I needed, thank you @jogold, really appreciate your help. |
Add an optional `masterSecret` prop in `DatabaseSecret` and clarify documentation for the multi user rotation schema. Related to aws#6358
Add an optional `masterSecret` prop in `DatabaseSecret` and clarify documentation for the multi user rotation schema. Related to #6358 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
I create a Secret with rotation for my application database credentials like this:
But when I go into Secrets Manager and click "Rotate Immediately" I get this in the logs:
And when I try to use the secret, I get a password error because the rotation hasn't happened.
Reproduction Steps
See Above
Error Log
Environment
Other
How do I correctly create a single user rotation for that secret?
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: