aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(aws-secretsmanager): rotationSchedule only allows whole days

Open joekendal opened this issue 5 years ago • 6 comments

:question: General Issue

Currently, the RotationScheduleOpts only allows for a Duration that can convert to a number of whole days. It cannot work on an hourly basis or on a minutes basis. This seems to defeat the whole purpose of the feature (to allow customisation). It is also misleading that the type interface is Duration.

For example, this configuration

secret.addRotationSchedule('RotationSchedule', {
    rotationLambda: rotate,
    automaticallyAfter: cdk.Duration.minutes(30)
})

causes the following error:

node_modules/@aws-cdk/core/lib/duration.ts:228
    throw new Error(`'${amount} ${fromUnit}' cannot be converted into a whole number of ${toUnit}.`);
          ^
Error: '30 minutes' cannot be converted into a whole number of days.

This seems like a huge inconvenience in the case of updating access tokens that expire in less than 24 hours or in the case of expiring every 24 hours may lead to a short window where the secret becomes invalid and breaks a production system for users.

Environment

  • CDK CLI Version: 1.116.0 (build d04661d)
  • Module Version: 1.116.0
  • Node.js Version: v14.16.1
  • OS: Do not wish to disclose for personal security reasons
  • Language (Version): TypeScript (4.2.3)

Other information

I realise this is a general issue with the Secrets Manager API but this should be a recommended fix. The documentation is not clear about when that rotation will occur within the 24 hours (I found a Medium article that claims it is random) and whether there could be a short gap where a secret access token is invalid for oauth if it happened at the end of every 24 hours and the access token expires after 24 hours (a few seconds of an app that depends on the token could break for a few users).

joekendal avatar Aug 02 '21 00:08 joekendal

For reference, this repository is the intended use case https://github.com/joekendal/aws-oauth-rotator . It is possible to add a scheduled lambda to manually rotate the secret at a custom interval but this seems like an unnecessary step for users.

joekendal avatar Aug 02 '21 00:08 joekendal

This issue may need to be transferred to the relevant RFC. Or a pattern should be released to make the custom interval with a lambda

joekendal avatar Aug 02 '21 00:08 joekendal

There's nothing the CDK can directly do about this, CloudFormation asks you to input a number of days. You can feel free to open a feature request for a workaround to this, but you'll likely need help from the community to get that made

peterwoodworth avatar Aug 02 '21 04:08 peterwoodworth

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Aug 02 '21 04:08 github-actions[bot]

The docs still show an incorrect example: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_secretsmanager.RotationSchedule.html.

The Example includes automaticallyAfter: cdk.Duration.minutes(30), when it only allows cdk.Duration.days here.

I'm curious if this could be updated?

deeheber avatar Jul 13 '23 22:07 deeheber

The docstring mentions that the values are placeholders.

That said, this could get fixed to be a number of days if there is a docstring example which directly instantiates a RotationSchedule construct, as this example would start to show that instead of this autogenerated one.

peterwoodworth avatar Jul 13 '23 22:07 peterwoodworth