aws-samples / aws-secrets-manager-rotation-lambdas

Contains Lambda functions to be used for automatic rotation of secrets stored in AWS Secrets Manager
MIT No Attribution
324 stars 279 forks source link

Name of IAM role not returned from AWS::SecretsManager::RotationSchedule #115

Open FrederiqueRetsema opened 1 year ago

FrederiqueRetsema commented 1 year ago

It is currently very hard to create a resource policy for the master database user secret in a multi user secret rotation template. The name of the IAM role doesn’t contain the name of the Lambda function or the name of the secret that is rotated. The most least-privileged permission that is currently possible without writing a custom resource to get the name of the role is therefore:

AllowUseOfDatabaseMainAdminSecretAtRotationOfWebsiteUserSecret: Type: AWS::SecretsManager::ResourcePolicy Properties: BlockPublicPolicy: False SecretId: !Ref DatabaseMainAdminSecret ResourcePolicy: Version: "2012-10-17" Statement:

It would be nicer to get the name of the IAM role back from AWS::SecretsManager::RotationSchedule, f.e. via GetAtt: [...] Condition: "ArnLike": "aws:PrincipalArn":

You can use my CloudFormation template Database-MySQLMultiUser.yml in the repository https://github.com/FrederiqueRetsema/Blogs-2023 .

simonmarty commented 1 year ago

Thank you for the request, Frederique. We've noted this as an enhancement request.