Skip to content

Commit 2da544f

Browse files
authored
fix(ses-actions): permissions too wide for S3 action (#29833)
### Issue # (if applicable) Closes #29811, continuation of @msambol 's #29823 ### Reason for this change Reduce overly broad permissions allocated to SES for the S3 receipt rule action ### Description of changes * Restrain by both rule set and rule name, as recommended in the [docs](https://docs.aws.amazon.com/ses/latest/dg/receiving-email-permissions.html#receiving-email-permissions-s3) * Accomplished by generating the permission lazily, when the rule is rendering the actions for CloudFormation ### Description of how you validated changes Updated the unit and integration tests. The integration now uses a free test WorkMail domain. It's a bit of manual setup upfront, but doesn't require the contributor to use one of their own domains ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9eb21bd commit 2da544f

File tree

14 files changed

+325
-401
lines changed

14 files changed

+325
-401
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-ses-actions/test/integ.actions.js.snapshot/asset.96d0b6be9a64ae309bf89a86f5515453f0fa1d07b4f6b37198051cc98e251f34/index.d.ts

-3
This file was deleted.

packages/@aws-cdk-testing/framework-integ/test/aws-ses-actions/test/integ.actions.js.snapshot/asset.96d0b6be9a64ae309bf89a86f5515453f0fa1d07b4f6b37198051cc98e251f34/index.js

-22
This file was deleted.

packages/@aws-cdk-testing/framework-integ/test/aws-ses-actions/test/integ.actions.js.snapshot/asset.96d0b6be9a64ae309bf89a86f5515453f0fa1d07b4f6b37198051cc98e251f34/index.ts

-22
This file was deleted.

packages/@aws-cdk-testing/framework-integ/test/aws-ses-actions/test/integ.actions.js.snapshot/aws-cdk-ses-receipt.assets.json

+3-16
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-ses-actions/test/integ.actions.js.snapshot/aws-cdk-ses-receipt.template.json

+62-86
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,31 @@
8686
"Action": "s3:PutObject",
8787
"Condition": {
8888
"StringEquals": {
89-
"aws:Referer": {
89+
"aws:SourceAccount": {
9090
"Ref": "AWS::AccountId"
91+
},
92+
"aws:SourceArn": {
93+
"Fn::Join": [
94+
"",
95+
[
96+
"arn:",
97+
{
98+
"Ref": "AWS::Partition"
99+
},
100+
":ses:",
101+
{
102+
"Ref": "AWS::Region"
103+
},
104+
":",
105+
{
106+
"Ref": "AWS::AccountId"
107+
},
108+
":receipt-rule-set/INBOUND_MAIL:receipt-rule/",
109+
{
110+
"Ref": "RuleSetFirstRule0A27C8CC"
111+
}
112+
]
113+
]
91114
}
92115
}
93116
},
@@ -172,40 +195,9 @@
172195
"UpdateReplacePolicy": "Retain",
173196
"DeletionPolicy": "Retain"
174197
},
175-
"RuleSetE30C6C48": {
176-
"Type": "AWS::SES::ReceiptRuleSet"
177-
},
178-
"RuleSetDropSpamRule5809F51B": {
179-
"Type": "AWS::SES::ReceiptRule",
180-
"Properties": {
181-
"Rule": {
182-
"Actions": [
183-
{
184-
"LambdaAction": {
185-
"FunctionArn": {
186-
"Fn::GetAtt": [
187-
"SingletonLambda224e77f9a32e4b4dac32983477abba164533EA15",
188-
"Arn"
189-
]
190-
},
191-
"InvocationType": "RequestResponse"
192-
}
193-
}
194-
],
195-
"Enabled": true,
196-
"ScanEnabled": true
197-
},
198-
"RuleSetName": {
199-
"Ref": "RuleSetE30C6C48"
200-
}
201-
}
202-
},
203198
"RuleSetFirstRule0A27C8CC": {
204199
"Type": "AWS::SES::ReceiptRule",
205200
"Properties": {
206-
"After": {
207-
"Ref": "RuleSetDropSpamRule5809F51B"
208-
},
209201
"Rule": {
210202
"Actions": [
211203
{
@@ -256,7 +248,7 @@
256248
{
257249
"BounceAction": {
258250
"Message": "Message content rejected",
259-
"Sender": "cdk-ses-receipt-test@yopmail.com",
251+
"Sender": "test@cdk-test-123.awsapps.com",
260252
"SmtpReplyCode": "500",
261253
"StatusCode": "5.6.1",
262254
"TopicArn": {
@@ -268,17 +260,14 @@
268260
"Enabled": true,
269261
"Name": "FirstRule",
270262
"Recipients": [
271-
"cdk-ses-receipt-test@yopmail.com"
263+
"test@cdk-test-123.awsapps.com"
272264
],
273265
"ScanEnabled": true,
274266
"TlsPolicy": "Require"
275267
},
276-
"RuleSetName": {
277-
"Ref": "RuleSetE30C6C48"
278-
}
268+
"RuleSetName": "INBOUND_MAIL"
279269
},
280270
"DependsOn": [
281-
"BucketPolicyE9A3008A",
282271
"FunctionAllowSes1829904A"
283272
]
284273
},
@@ -301,79 +290,66 @@
301290
],
302291
"Enabled": true
303292
},
304-
"RuleSetName": {
305-
"Ref": "RuleSetE30C6C48"
306-
}
293+
"RuleSetName": "INBOUND_MAIL"
307294
}
308295
},
309-
"SingletonLambda224e77f9a32e4b4dac32983477abba16ServiceRole3037F5B4": {
310-
"Type": "AWS::IAM::Role",
296+
"NotificationQueue36610CC1": {
297+
"Type": "AWS::SQS::Queue",
298+
"UpdateReplacePolicy": "Delete",
299+
"DeletionPolicy": "Delete"
300+
},
301+
"NotificationQueuePolicyCC060EA6": {
302+
"Type": "AWS::SQS::QueuePolicy",
311303
"Properties": {
312-
"AssumeRolePolicyDocument": {
304+
"PolicyDocument": {
313305
"Statement": [
314306
{
315-
"Action": "sts:AssumeRole",
307+
"Action": "sqs:SendMessage",
308+
"Condition": {
309+
"ArnEquals": {
310+
"aws:SourceArn": {
311+
"Ref": "TopicBFC7AF6E"
312+
}
313+
}
314+
},
316315
"Effect": "Allow",
317316
"Principal": {
318-
"Service": "lambda.amazonaws.com"
317+
"Service": "sns.amazonaws.com"
318+
},
319+
"Resource": {
320+
"Fn::GetAtt": [
321+
"NotificationQueue36610CC1",
322+
"Arn"
323+
]
319324
}
320325
}
321326
],
322327
"Version": "2012-10-17"
323328
},
324-
"ManagedPolicyArns": [
329+
"Queues": [
325330
{
326-
"Fn::Join": [
327-
"",
328-
[
329-
"arn:",
330-
{
331-
"Ref": "AWS::Partition"
332-
},
333-
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
334-
]
335-
]
331+
"Ref": "NotificationQueue36610CC1"
336332
}
337333
]
338334
}
339335
},
340-
"SingletonLambda224e77f9a32e4b4dac32983477abba164533EA15": {
341-
"Type": "AWS::Lambda::Function",
336+
"NotificationQueueawscdksesreceiptTopicE9CA2388E8E96C33": {
337+
"Type": "AWS::SNS::Subscription",
342338
"Properties": {
343-
"Code": {
344-
"S3Bucket": {
345-
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
346-
},
347-
"S3Key": "96d0b6be9a64ae309bf89a86f5515453f0fa1d07b4f6b37198051cc98e251f34.zip"
348-
},
349-
"Handler": "index.handler",
350-
"Role": {
339+
"Endpoint": {
351340
"Fn::GetAtt": [
352-
"SingletonLambda224e77f9a32e4b4dac32983477abba16ServiceRole3037F5B4",
341+
"NotificationQueue36610CC1",
353342
"Arn"
354343
]
355344
},
356-
"Runtime": "nodejs18.x"
345+
"Protocol": "sqs",
346+
"TopicArn": {
347+
"Ref": "TopicBFC7AF6E"
348+
}
357349
},
358350
"DependsOn": [
359-
"SingletonLambda224e77f9a32e4b4dac32983477abba16ServiceRole3037F5B4"
351+
"NotificationQueuePolicyCC060EA6"
360352
]
361-
},
362-
"SingletonLambda224e77f9a32e4b4dac32983477abba16AllowSesB42DF904": {
363-
"Type": "AWS::Lambda::Permission",
364-
"Properties": {
365-
"Action": "lambda:InvokeFunction",
366-
"FunctionName": {
367-
"Fn::GetAtt": [
368-
"SingletonLambda224e77f9a32e4b4dac32983477abba164533EA15",
369-
"Arn"
370-
]
371-
},
372-
"Principal": "ses.amazonaws.com",
373-
"SourceAccount": {
374-
"Ref": "AWS::AccountId"
375-
}
376-
}
377353
}
378354
},
379355
"Parameters": {

packages/@aws-cdk-testing/framework-integ/test/aws-ses-actions/test/integ.actions.js.snapshot/cdk.out

+1-1
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-ses-actions/test/integ.actions.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)