@@ -416,77 +416,58 @@ export class StacksCloud extends Stack {
416
416
}
417
417
418
418
if ( config . security . firewall ?. httpHeaders ?. length ) {
419
- priorities . push ( 1 )
420
- rules . push ( {
421
- name : 'HttpHeaderRule' ,
422
- priority : priorities . length ,
423
- statement : {
424
- byteMatchStatement : {
425
- fieldToMatch : {
426
- singleHeader : {
427
- name : config . security . firewall . httpHeaders ,
419
+ config . security . firewall . httpHeaders . forEach ( ( header , index ) => {
420
+ priorities . push ( 1 )
421
+ rules . push ( {
422
+ name : `HttpHeaderRule${ index } ` ,
423
+ priority : priorities . length ,
424
+ statement : {
425
+ byteMatchStatement : {
426
+ fieldToMatch : {
427
+ singleHeader : {
428
+ name : header ,
429
+ } ,
428
430
} ,
431
+ positionalConstraint : 'EXACTLY' ,
432
+ searchString : 'true' ,
433
+ textTransformations : [
434
+ {
435
+ priority : index ,
436
+ type : 'NONE' ,
437
+ } ,
438
+ ] ,
429
439
} ,
430
- positionalConstraint : 'EXACTLY' ,
431
- searchString : 'true' ,
432
- textTransformations : [
433
- {
434
- priority : 0 ,
435
- type : 'NONE' ,
436
- } ,
437
- ] ,
438
440
} ,
439
- } ,
440
- action : {
441
- block : { } ,
442
- } ,
443
- visibilityConfig : {
444
- sampledRequestsEnabled : true ,
445
- cloudWatchMetricsEnabled : true ,
446
- metricName : 'HttpHeaderRule' ,
447
- } ,
448
- } )
449
- }
450
-
451
- if ( config . security . firewall ?. queryString ?. length ) {
452
- priorities . push ( 1 )
453
- rules . push ( {
454
- name : 'QueryStringRule' ,
455
- priority : priorities . length ,
456
- statement : {
457
- byteMatchStatement : {
458
- fieldToMatch : {
459
- queryString : { } ,
460
- } ,
461
- positionalConstraint : 'EXACTLY' ,
462
- searchString : config . security . firewall . queryString . join ( ', ' ) ,
463
- textTransformations : [
464
- {
465
- priority : 0 ,
466
- type : 'NONE' ,
467
- } ,
468
- ] ,
441
+ action : {
442
+ block : { } ,
469
443
} ,
470
- } ,
471
- action : {
472
- block : { } ,
473
- } ,
474
- visibilityConfig : {
475
- sampledRequestsEnabled : true ,
476
- cloudWatchMetricsEnabled : true ,
477
- metricName : 'QueryStringRule' ,
478
- } ,
444
+ visibilityConfig : {
445
+ sampledRequestsEnabled : true ,
446
+ cloudWatchMetricsEnabled : true ,
447
+ metricName : `HttpHeaderRule${ index } ` ,
448
+ } ,
449
+ } )
479
450
} )
480
451
}
481
452
482
- // if (config.security.firewall?.ipSets ?.length) {
453
+ // if (config.security.firewall?.queryString ?.length) {
483
454
// priorities.push(1)
484
455
// rules.push({
485
- // name: 'IpSetRule ',
456
+ // name: 'QueryStringRule ',
486
457
// priority: priorities.length,
487
458
// statement: {
488
- // ipSetReferenceStatement: {
489
- // arn: config.security.firewall.ipSets,
459
+ // byteMatchStatement: {
460
+ // fieldToMatch: {
461
+ // queryString: {},
462
+ // },
463
+ // positionalConstraint: 'EXACTLY',
464
+ // searchString: config.security.firewall.queryString.join(', '),
465
+ // textTransformations: [
466
+ // {
467
+ // priority: 0,
468
+ // type: 'NONE',
469
+ // },
470
+ // ],
490
471
// },
491
472
// },
492
473
// action: {
@@ -495,86 +476,76 @@ export class StacksCloud extends Stack {
495
476
// visibilityConfig: {
496
477
// sampledRequestsEnabled: true,
497
478
// cloudWatchMetricsEnabled: true,
498
- // metricName: 'IpSetRule ',
479
+ // metricName: 'QueryStringRule ',
499
480
// },
500
481
// })
501
482
// }
502
483
503
- if ( config . security . firewall ?. rateLimitPerMinute ) {
504
- priorities . push ( 1 )
505
- rules . push ( {
506
- name : 'RateLimitRule' ,
507
- priority : priorities . length ,
508
- statement : {
509
- rateBasedStatement : {
510
- limit : config . security . firewall . rateLimitPerMinute ,
511
- aggregateKeyType : 'IP' ,
512
- scopeDownStatement : {
513
- notStatement : {
514
- statement : {
515
- rateBasedStatement : {
516
- limit : config . security . firewall . rateLimitPerMinute ,
517
- aggregateKeyType : 'IP' ,
518
- } ,
519
- } ,
520
- } ,
521
- } ,
522
- } ,
523
- } ,
524
- action : {
525
- block : { } ,
526
- } ,
527
- visibilityConfig : {
528
- sampledRequestsEnabled : true ,
529
- cloudWatchMetricsEnabled : true ,
530
- metricName : 'RateLimitRule' ,
531
- } ,
532
- } )
533
- }
484
+ // if (config.security.firewall?.rateLimitPerMinute) {
485
+ // priorities.push(1)
486
+ // rules.push({
487
+ // name: 'RateLimitRule',
488
+ // priority: priorities.length,
489
+ // statement: {
490
+ // rateBasedStatement: {
491
+ // limit: config.security.firewall.rateLimitPerMinute,
492
+ // aggregateKeyType: 'IP',
493
+ // },
494
+ // },
495
+ // action: {
496
+ // block: {},
497
+ // },
498
+ // visibilityConfig: {
499
+ // sampledRequestsEnabled: true,
500
+ // cloudWatchMetricsEnabled: true,
501
+ // metricName: 'RateLimitRule',
502
+ // },
503
+ // })
504
+ // }
534
505
535
- if ( config . security . firewall ?. useIpReputationLists ) {
536
- priorities . push ( 1 )
537
- rules . push ( {
538
- name : 'IpReputationRule' ,
539
- priority : priorities . length ,
540
- statement : {
541
- managedRuleGroupStatement : {
542
- vendorName : 'AWS' ,
543
- name : 'AWSManagedRulesAmazonIpReputationList' ,
544
- } ,
545
- } ,
546
- action : {
547
- block : { } ,
548
- } ,
549
- visibilityConfig : {
550
- sampledRequestsEnabled : true ,
551
- cloudWatchMetricsEnabled : true ,
552
- metricName : 'IpReputationRule' ,
553
- } ,
554
- } )
555
- }
506
+ // if (config.security.firewall?.useIpReputationLists) {
507
+ // priorities.push(1)
508
+ // rules.push({
509
+ // name: 'IpReputationRule',
510
+ // priority: priorities.length,
511
+ // statement: {
512
+ // managedRuleGroupStatement: {
513
+ // vendorName: 'AWS',
514
+ // name: 'AWSManagedRulesAmazonIpReputationList',
515
+ // },
516
+ // },
517
+ // action: {
518
+ // block: {},
519
+ // },
520
+ // visibilityConfig: {
521
+ // sampledRequestsEnabled: true,
522
+ // cloudWatchMetricsEnabled: true,
523
+ // metricName: 'IpReputationRule',
524
+ // },
525
+ // })
526
+ // }
556
527
557
- if ( config . security . firewall ?. useKnownBadInputsRuleSet ) {
558
- priorities . push ( 1 )
559
- rules . push ( {
560
- name : 'KnownBadInputsRule' ,
561
- priority : priorities . length ,
562
- statement : {
563
- managedRuleGroupStatement : {
564
- vendorName : 'AWS' ,
565
- name : 'AWSManagedRulesKnownBadInputsRuleSet' ,
566
- } ,
567
- } ,
568
- action : {
569
- block : { } ,
570
- } ,
571
- visibilityConfig : {
572
- sampledRequestsEnabled : true ,
573
- cloudWatchMetricsEnabled : true ,
574
- metricName : 'KnownBadInputsRule' ,
575
- } ,
576
- } )
577
- }
528
+ // if (config.security.firewall?.useKnownBadInputsRuleSet) {
529
+ // priorities.push(1)
530
+ // rules.push({
531
+ // name: 'KnownBadInputsRule',
532
+ // priority: priorities.length,
533
+ // statement: {
534
+ // managedRuleGroupStatement: {
535
+ // vendorName: 'AWS',
536
+ // name: 'AWSManagedRulesKnownBadInputsRuleSet',
537
+ // },
538
+ // },
539
+ // action: {
540
+ // block: {},
541
+ // },
542
+ // visibilityConfig: {
543
+ // sampledRequestsEnabled: true,
544
+ // cloudWatchMetricsEnabled: true,
545
+ // metricName: 'KnownBadInputsRule',
546
+ // },
547
+ // })
548
+ // }
578
549
579
550
return rules
580
551
}
@@ -749,21 +720,23 @@ export class StacksCloud extends Stack {
749
720
750
721
const sesPrincipal = new iam . ServicePrincipal ( 'ses.amazonaws.com' )
751
722
752
- this . storage . emailBucket . addToResourcePolicy ( new iam . PolicyStatement ( {
723
+ const sesPolicy = new iam . PolicyStatement ( {
753
724
sid : 'AllowSESPuts' ,
754
725
effect : iam . Effect . ALLOW ,
755
726
principals : [ sesPrincipal ] ,
756
727
actions : [ 's3:PutObject' ] ,
757
728
resources : [
758
- // this.storage.emailBucket.arnForObjects('tmp/email_in/*') ,
759
- this . storage . emailBucket . arnForObjects ( '*' ) ,
729
+ ` ${ this . storage . emailBucket . bucketArn } ` ,
730
+ ` ${ this . storage . emailBucket . bucketArn } /*` ,
760
731
] ,
761
732
conditions : {
762
733
StringEquals : {
763
734
'aws:Referer' : this . account ,
764
735
} ,
765
736
} ,
766
- } ) )
737
+ } )
738
+
739
+ this . storage . emailBucket . addToResourcePolicy ( sesPolicy )
767
740
768
741
const iamGroup = new iam . Group ( this , 'IAMGroup' , {
769
742
groupName : `${ this . appName } -${ appEnv } -email-management-s3-group` ,
@@ -788,8 +761,8 @@ export class StacksCloud extends Stack {
788
761
's3:PutObjectVersionAcl' ,
789
762
] ,
790
763
resources : [
791
- `arn:aws:s3::: ${ this . storage . emailBucket . bucketName } ` ,
792
- `arn:aws:s3::: ${ this . storage . emailBucket . bucketName } /*` ,
764
+ `${ this . storage . emailBucket . bucketArn } ` ,
765
+ `${ this . storage . emailBucket . bucketArn } /*` ,
793
766
] ,
794
767
} )
795
768
0 commit comments