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

bug: SecretsManagerRotationEnabled is non compliant even if rotation is configured after cdk v2.116 #1565

Closed
clueleaf opened this issue Jan 17, 2024 · 0 comments · Fixed by #1566
Labels
bug Something isn't working needs-triage This issue or PR still needs to be triaged.

Comments

@clueleaf
Copy link
Contributor

What is the problem?

When using cdk v2.116.0 or later, even if Secrets Manager secret rotation is configured, SecretsManagerRotationEnabled rule results in non-compliant.

Reproduction Steps

  1. Create a secret, configure the rotation.
    new secretsmanager.Secret(this, "Secret").addRotationSchedule("my-secret-rotation-schedule", {
      hostedRotation: secretsmanager.HostedRotation.mysqlSingleUser(),
      automaticallyAfter: Duration.days(30),
    });
  1. Synth the stack using cdk v2.115.0. No cdk-nag error shows up. The cfn template contains the following:
  "MyConstructSecretmysecretrotationscheduleDDD9F0F6": {
   "Type": "AWS::SecretsManager::RotationSchedule",
   "Properties": {
    "HostedRotationLambda": {
     "ExcludeCharacters": " %+~`#$&*()|[]{}:;<>?!'/@\"\\",
     "RotationType": "MySQLSingleUser"
    },
    "RotationRules": {
     "AutomaticallyAfterDays": 30
    },
    "SecretId": {
     "Ref": "MyConstructSecretA546D653"
    }
   },
  },
  1. Use cdk v2.116.0 and synth again. The following cdk-nag error shows up this time.
[Error at /MyStack/MyConstruct/Secret/Resource] AwsSolutions-SMG4: The secret does not have automatic rotation scheduled. AWS Secrets Manager can be configured to automatically rotate the secret for a secured service or database.
  1. When I remove cdk-nag checks, the cfn template is like this. RotationRules.AutomaticallyAfterDays is replaced by RotationRules.ScheduleExpression due to fix(secretsmanager): cannot set hourly rotation aws/aws-cdk#28303
  "MyConstructSecretmysecretrotationscheduleDDD9F0F6": {
   "Type": "AWS::SecretsManager::RotationSchedule",
   "Properties": {
    "HostedRotationLambda": {
     "ExcludeCharacters": " %+~`#$&*()|[]{}:;<>?!'/@\"\\",
     "RotationType": "MySQLSingleUser"
    },
    "RotationRules": {
     "ScheduleExpression": "rate(30 days)"
    },
    "SecretId": {
     "Ref": "MyConstructSecretA546D653"
    }
   },
  },

What did you expect to happen?

SecretsManagerRotationEnabled rule results in compliant when using cdk v2.116.0 or later.

What actually happened?

SecretsManagerRotationEnabled is non compliant when using cdk v2.116.0 or later.

cdk-nag version

2.28.11

Language

Typescript

Other information

I will try to fix this later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant