Skip to content

Commit 4ab5bb2

Browse files
authored
fix(secretsmanager): hosted rotation with fromSecretNameV2() does not create correct iam policy (#28379)
In the case for a hosted rotation with a master secret by `fromSecretNameV2()`, IAM policy for lambda is not correct. The secret by the method has a partial ARN, so a generated IAM policy should use an ARN with `'-??????'`, but it will not use the ARN. Closes #28308. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7264121 commit 4ab5bb2

File tree

9 files changed

+364
-53
lines changed

9 files changed

+364
-53
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-secretsmanager/test/integ.hosted-rotation.js.snapshot/cdk-integ-secret-hosted-rotation.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-secretsmanager/test/integ.hosted-rotation.js.snapshot/cdk-integ-secret-hosted-rotation.template.json

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"SecretSchedule18F2CB66": {
1515
"Type": "AWS::SecretsManager::RotationSchedule",
1616
"Properties": {
17-
"SecretId": {
18-
"Ref": "SecretA720EF05"
19-
},
2017
"HostedRotationLambda": {
2118
"ExcludeCharacters": " %+~`#$&*()|[]{}:;<>?!'/@\"\\",
2219
"RotationType": "MySQLSingleUser"
2320
},
2421
"RotationRules": {
2522
"ScheduleExpression": "rate(30 days)"
23+
},
24+
"SecretId": {
25+
"Ref": "SecretA720EF05"
2626
}
2727
}
2828
},
@@ -75,16 +75,16 @@
7575
"CustomSecretScheduleDD99F351": {
7676
"Type": "AWS::SecretsManager::RotationSchedule",
7777
"Properties": {
78-
"SecretId": {
79-
"Ref": "CustomSecret5DC95D87"
80-
},
8178
"HostedRotationLambda": {
8279
"ExcludeCharacters": "&@/",
8380
"RotationType": "MySQLSingleUser"
8481
},
8582
"RotateImmediatelyOnUpdate": false,
8683
"RotationRules": {
8784
"ScheduleExpression": "rate(30 days)"
85+
},
86+
"SecretId": {
87+
"Ref": "CustomSecret5DC95D87"
8888
}
8989
}
9090
},
@@ -123,6 +123,85 @@
123123
"Ref": "CustomSecret5DC95D87"
124124
}
125125
}
126+
},
127+
"MySecret8FE80B51": {
128+
"Type": "AWS::SecretsManager::Secret",
129+
"Properties": {
130+
"GenerateSecretString": {}
131+
},
132+
"UpdateReplacePolicy": "Delete",
133+
"DeletionPolicy": "Delete"
134+
},
135+
"MySecretRotationSchedule673B961C": {
136+
"Type": "AWS::SecretsManager::RotationSchedule",
137+
"Properties": {
138+
"HostedRotationLambda": {
139+
"ExcludeCharacters": " %+~`#$&*()|[]{}:;<>?!'/@\"\\",
140+
"MasterSecretArn": {
141+
"Fn::Join": [
142+
"",
143+
[
144+
"arn:",
145+
{
146+
"Ref": "AWS::Partition"
147+
},
148+
":secretsmanager:",
149+
{
150+
"Ref": "AWS::Region"
151+
},
152+
":",
153+
{
154+
"Ref": "AWS::AccountId"
155+
},
156+
":secret:MasterSecret-??????"
157+
]
158+
]
159+
},
160+
"RotationType": "PostgreSQLMultiUser"
161+
},
162+
"RotationRules": {
163+
"ScheduleExpression": "rate(30 days)"
164+
},
165+
"SecretId": {
166+
"Ref": "MySecret8FE80B51"
167+
}
168+
}
169+
},
170+
"MySecretPolicyDAD0E682": {
171+
"Type": "AWS::SecretsManager::ResourcePolicy",
172+
"Properties": {
173+
"ResourcePolicy": {
174+
"Statement": [
175+
{
176+
"Action": "secretsmanager:DeleteSecret",
177+
"Effect": "Deny",
178+
"Principal": {
179+
"AWS": {
180+
"Fn::Join": [
181+
"",
182+
[
183+
"arn:",
184+
{
185+
"Ref": "AWS::Partition"
186+
},
187+
":iam::",
188+
{
189+
"Ref": "AWS::AccountId"
190+
},
191+
":root"
192+
]
193+
]
194+
}
195+
},
196+
"Resource": "*"
197+
}
198+
],
199+
"Version": "2012-10-17"
200+
},
201+
"SecretId": {
202+
"Ref": "MySecret8FE80B51"
203+
}
204+
}
126205
}
127206
},
128207
"Parameters": {

packages/@aws-cdk-testing/framework-integ/test/aws-secretsmanager/test/integ.hosted-rotation.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-secretsmanager/test/integ.hosted-rotation.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-secretsmanager/test/integ.hosted-rotation.js.snapshot/manifest.json

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)