@@ -17,10 +17,10 @@ import {
17
17
aws_certificatemanager as acm ,
18
18
aws_backup as backup ,
19
19
aws_cloudfront as cloudfront ,
20
- // custom_resources,
21
20
aws_ec2 as ec2 ,
22
21
aws_efs as efs ,
23
22
aws_iam as iam ,
23
+ // custom_resources,
24
24
aws_kms as kms ,
25
25
aws_lambda as lambda ,
26
26
aws_cloudfront_origins as origins ,
@@ -577,6 +577,23 @@ export class StacksCloud extends Stack {
577
577
// },
578
578
// })
579
579
// }
580
+ // also add
581
+ // }, {
582
+ // "name": "AWSManagedRulesAnonymousIpList",
583
+ // "priority": 40,
584
+ // "overrideAction": "none",
585
+ // "excludedRules": []
586
+ // }, {
587
+ // "name": "AWSManagedRulesLinuxRuleSet",
588
+ // "priority": 50,
589
+ // "overrideAction": "none",
590
+ // "excludedRules": []
591
+ // }, {
592
+ // "name": "AWSManagedRulesUnixRuleSet",
593
+ // "priority": 60,
594
+ // "overrideAction": "none",
595
+ // "excludedRules": [],
596
+ // }];
580
597
581
598
return rules
582
599
}
@@ -756,32 +773,14 @@ export class StacksCloud extends Stack {
756
773
this . storage . emailBucket = this . createBucket ( 'email' )
757
774
758
775
const sesPrincipal = new iam . ServicePrincipal ( 'ses.amazonaws.com' )
759
- const ruleSetName = `${ this . appName } -${ appEnv } -email`
776
+ const ruleSetName = `${ this . appName } -${ appEnv } -email-receipt-rule-set-${ timestamp } `
777
+ const receiptRuleName = `${ this . appName } -${ appEnv } -email-receipt-rule-${ timestamp } `
778
+
760
779
const ruleSet = new ses . CfnReceiptRuleSet ( this , 'SESReceiptRuleSet' , {
761
780
ruleSetName,
762
781
} )
763
782
764
- const ruleName = 'Inbound'
765
- // const receiptRule = new ses.CfnReceiptRule(this, 'SESReceiptRule', {
766
- new ses . CfnReceiptRule ( this , 'SESReceiptRule' , {
767
- ruleSetName : ruleSet . ref ,
768
- rule : {
769
- name : ruleName ,
770
- enabled : true ,
771
- actions : [
772
- {
773
- s3Action : {
774
- bucketName : this . storage . emailBucket . bucketName ,
775
- kmsKeyArn : this . encryptionKey . keyArn ,
776
- objectKeyPrefix : 'tmp/email_in' ,
777
- } ,
778
- } ,
779
- ] ,
780
- scanEnabled : config . email . server ?. scan || true ,
781
- tlsPolicy : 'Require' ,
782
- } ,
783
- } )
784
-
783
+ // add a policy to the S3 bucket to allow the SES service to put objects into it
785
784
this . storage . emailBucket . addToResourcePolicy (
786
785
new iam . PolicyStatement ( {
787
786
sid : `AllowSESToPutObject` ,
@@ -792,39 +791,38 @@ export class StacksCloud extends Stack {
792
791
's3:PutObjectAcl' ,
793
792
] ,
794
793
resources : [
794
+ this . storage . emailBucket . bucketArn ,
795
795
`${ this . storage . emailBucket . bucketArn } /*` ,
796
796
] ,
797
797
conditions : {
798
798
StringEquals : {
799
799
'aws:SourceAccount' : Stack . of ( this ) . account ,
800
800
} ,
801
801
ArnLike : {
802
- 'aws:SourceArn' : `arn:aws:ses:${ this . region } :${ Stack . of ( this ) . account } :receipt-rule-set/${ ruleSetName } :receipt-rule/${ ruleName } ` ,
802
+ 'aws:SourceArn' : `arn:aws:ses:${ this . region } :${ Stack . of ( this ) . account } :receipt-rule-set/${ ruleSet . ref } :receipt-rule/${ receiptRuleName } ` ,
803
803
} ,
804
804
} ,
805
805
} ) ,
806
806
)
807
807
808
- this . storage . emailBucket . addToResourcePolicy (
809
- new iam . PolicyStatement ( {
810
- sid : `AllowSESToEncryptMessagesBelongingToThisAccount` ,
811
- effect : iam . Effect . ALLOW ,
812
- principals : [ sesPrincipal ] ,
813
- actions : [
814
- 'kms:Decrypt' ,
815
- 'kms:GenerateDataKey*' ,
816
- ] ,
817
- resources : [ '*' ] ,
818
- conditions : {
819
- StringEquals : {
820
- 'aws:SourceAccount' : Stack . of ( this ) . account ,
821
- } ,
822
- ArnLike : {
823
- 'aws:SourceArn' : `arn:aws:ses:${ this . region } :${ Stack . of ( this ) . account } :receipt-rule-set/${ ruleSetName } :receipt-rule/${ ruleName } ` ,
824
- } ,
825
- } ,
826
- } ) ,
827
- )
808
+ new ses . CfnReceiptRule ( this , 'SESReceiptRule' , {
809
+ ruleSetName : ruleSet . ref ,
810
+ rule : {
811
+ name : receiptRuleName ,
812
+ enabled : true ,
813
+ // actions: [
814
+ // {
815
+ // s3Action: {
816
+ // bucketName: this.storage.emailBucket.bucketName,
817
+ // kmsKeyArn: this.encryptionKey.keyArn,
818
+ // objectKeyPrefix: 'tmp/email_in',
819
+ // },
820
+ // },
821
+ // ],
822
+ scanEnabled : config . email . server ?. scan || true ,
823
+ tlsPolicy : 'Require' ,
824
+ } ,
825
+ } )
828
826
829
827
const iamGroup = new iam . Group ( this , 'IAMGroup' , {
830
828
groupName : `${ this . appName } -${ appEnv } -email-management-s3-group` ,
@@ -849,7 +847,7 @@ export class StacksCloud extends Stack {
849
847
's3:PutObjectVersionAcl' ,
850
848
] ,
851
849
resources : [
852
- ` ${ this . storage . emailBucket . bucketArn } ` ,
850
+ this . storage . emailBucket . bucketArn ,
853
851
`${ this . storage . emailBucket . bucketArn } /*` ,
854
852
] ,
855
853
} )
@@ -859,9 +857,6 @@ export class StacksCloud extends Stack {
859
857
statements : [ policyStatement , listBucketsPolicyStatement ] ,
860
858
} )
861
859
862
- const cfnBucketPolicy = this . storage . emailBucket . node . findChild ( 'Policy' ) . node . findChild ( 'Resource' )
863
- ruleSet . node . addDependency ( cfnBucketPolicy )
864
-
865
860
iamGroup . attachInlinePolicy ( policy )
866
861
867
862
// Create a SES domain identity
@@ -1051,22 +1046,6 @@ export class StacksCloud extends Stack {
1051
1046
1052
1047
lambdaEmailConverterRole . addToPolicy ( converterS3PolicyStatement )
1053
1048
1054
- this . storage . emailBucket . addToResourcePolicy ( new iam . PolicyStatement ( {
1055
- sid : `AllowSESToInvokeLambda` ,
1056
- principals : [ sesPrincipal ] ,
1057
- actions : [
1058
- 'lambda:InvokeFunction' ,
1059
- ] ,
1060
- conditions : {
1061
- StringEquals : {
1062
- 'aws:SourceAccount' : Stack . of ( this ) . account ,
1063
- } ,
1064
- ArnLike : {
1065
- 'aws:SourceArn' : `arn:aws:ses:${ this . region } :${ Stack . of ( this ) . account } :receipt-rule-set/${ ruleSetName } :receipt-rule/${ ruleName } ` ,
1066
- } ,
1067
- } ,
1068
- } ) )
1069
-
1070
1049
this . storage . emailBucket . addEventNotification ( s3 . EventType . OBJECT_CREATED_PUT , new s3n . LambdaDestination ( lambdaEmailInbound ) , { prefix : 'tmp/email_in' } )
1071
1050
this . storage . emailBucket . addEventNotification ( s3 . EventType . OBJECT_CREATED_PUT , new s3n . LambdaDestination ( lambdaEmailOutbound ) , { prefix : 'tmp/email_out/json' } )
1072
1051
this . storage . emailBucket . addEventNotification ( s3 . EventType . OBJECT_CREATED_COPY , new s3n . LambdaDestination ( lambdaEmailConverter ) , { prefix : 'sent/' } )
@@ -1202,6 +1181,7 @@ export class StacksCloud extends Stack {
1202
1181
versioned : true ,
1203
1182
removalPolicy : RemovalPolicy . DESTROY ,
1204
1183
autoDeleteObjects : true ,
1184
+ encryption : s3 . BucketEncryption . KMS ,
1205
1185
encryptionKey : this . encryptionKey ,
1206
1186
enforceSSL : true ,
1207
1187
publicReadAccess : false ,
@@ -1231,13 +1211,14 @@ export class StacksCloud extends Stack {
1231
1211
removalPolicy : RemovalPolicy . DESTROY ,
1232
1212
autoDeleteObjects : true ,
1233
1213
encryptionKey : this . encryptionKey ,
1214
+ encryption : s3 . BucketEncryption . KMS ,
1234
1215
lifecycleRules : [
1235
1216
{
1236
1217
id : '24h' ,
1218
+ enabled : true ,
1237
1219
expiration : Duration . days ( 1 ) ,
1238
1220
noncurrentVersionExpiration : Duration . days ( 1 ) ,
1239
1221
prefix : 'today/' ,
1240
- enabled : true ,
1241
1222
} ,
1242
1223
{
1243
1224
id : 'Intelligent transition for Inbox' ,
@@ -1280,6 +1261,8 @@ export class StacksCloud extends Stack {
1280
1261
versioned : true ,
1281
1262
autoDeleteObjects : true ,
1282
1263
removalPolicy : RemovalPolicy . DESTROY ,
1264
+ // encryption: s3.BucketEncryption.KMS, // does encryption for public files make sense?
1265
+ // encryptionKey: this.encryptionKey,
1283
1266
} )
1284
1267
1285
1268
Tags . of ( bucket ) . add ( 'daily-backup' , 'true' )
0 commit comments