Skip to content
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

(secretsmanager): cannot make 'RotationRules' unset for RotationSchedule #18749

Closed
RobReus opened this issue Jan 31, 2022 · 4 comments · Fixed by #18906
Closed

(secretsmanager): cannot make 'RotationRules' unset for RotationSchedule #18749

RobReus opened this issue Jan 31, 2022 · 4 comments · Fixed by #18906
Labels
@aws-cdk/aws-secretsmanager Related to AWS Secrets Manager bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@RobReus
Copy link

RobReus commented Jan 31, 2022

What is the problem?

Without tapping into the CfnRotationSchedule construct directly, it is not possible to leave the RotationRules (automaticallyAfter in the RotationSchedule construct) property of AWS::SecretsManager::RotationSchedule empty. When using the CfnRotationSchedule and not setting the rotationRules property, it is left unset as is expected.

The CloudFormation docs (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html#cfn-secretsmanager-rotationschedule-rotationrules) has this property set as optional, and when left empty, allows you to configure a rotation lambda without any schedule.

My use-case for this is for secrets that do not need to be automatically rotated, but only on demand when needed.

Reproduction Steps

const rotationSchedule = new secretsmanager.RotationSchedule(this, 'MyRotationSchedule', {
  secret: secret,
  // automaticallyAfter: cdk.Duration.minutes(30),
  rotationLambda: function_,
});

What did you expect to happen?

The resulting CloudFormation template to not have the property RotationRules set for the AWS::SecretsManager::RotationSchedule resource.

What actually happened?

The resulting CloudFormation template has the property RotationRules set to a default of 30 days for the AWS::SecretsManager::RotationSchedule resource.

CDK CLI Version

2.10.0

Framework Version

2.10.0

Node.js Version

16.13.2

OS

Ubuntu 20.04 LTS (WSL2)

Language

Typescript

Language Version

4.5.5

Other information

No response

@RobReus RobReus added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 31, 2022
@github-actions github-actions bot added the @aws-cdk/aws-secretsmanager Related to AWS Secrets Manager label Jan 31, 2022
@ryparker ryparker added the p1 label Jan 31, 2022
@ryparker
Copy link
Contributor

ryparker commented Jan 31, 2022

Hey @RobReus 👋🏻 Thanks for reporting this.

It does look like we force the default to be 30 days. We should allow this to be undefined to match CloudFormation's implementation.

Marked this as p1 which means it is prioritized as important to our devs. As always we appreciate any contributions if anyone is interested in tackling this as there are many issues that our devs are currently working through (see our contribution guidelines).

Meanwhile if you need a quick workaround you should be able to override the generated template properties using escape hatches.

@njlynch njlynch removed their assignment Feb 3, 2022
@njlynch njlynch added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 3, 2022
@AdamVD
Copy link
Contributor

AdamVD commented Feb 6, 2022

Hi @RobReus and @ryparker 👋

I'd be happy to contribute a fix here, but we need to evaluate what the best non-breaking fix would be. If we stopped applying the default 30 days then automatic rotation would be turned off for any users relying on the default. Clearly this is breaking behavior and not acceptable.

I've thought of a couple options to fix this without a breaking change:

  1. We treat a automaticallyAfter input duration of zero (e.g. Duration.days(0)) to indicate that automatic rotation should be disabled. When a zero duration is received then we would set the underlying Cfn option to undefined.
  2. We add a manualRotation option that defaults false. If it is set true we will have to check if automaticallyAfter is set and throw an error if so, as these would be incompatible options. When manualRotation is true we would set the underlying Cfn option to undefined.

I think the second option is clearer and more quickly recognizable to anyone trying to turn off automatic rotation. I'm also open to names other than manualRotation.

Let me know what you think!

@RobReus
Copy link
Author

RobReus commented Feb 7, 2022

@AdamVD thank you for your willingness to contribute to fix this issue.

Personally I like the second option better as well. I feel like the way you have described it will be clear and fully backwards compatible. It would be the perfect solution for me.

@mergify mergify bot closed this as completed in #18906 May 17, 2022
mergify bot pushed a commit that referenced this issue May 17, 2022
fixes #18749

Adds a `manualRotation` prop to `RotationSchedule` in order to leave `automaticallyAfterDays` unset on the underlying Cfn resource.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️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.

wphilipw pushed a commit to wphilipw/aws-cdk that referenced this issue May 23, 2022
fixes aws#18749

Adds a `manualRotation` prop to `RotationSchedule` in order to leave `automaticallyAfterDays` unset on the underlying Cfn resource.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-secretsmanager Related to AWS Secrets Manager bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants