11import { Construct } from "constructs"
2- import * as wafv2 from "aws-cdk-lib/aws-wafv2"
2+ import { CfnIPSet , CfnLoggingConfiguration , CfnWebACL } from "aws-cdk-lib/aws-wafv2"
33
44/**
55 * WAF ACL and supporting resources
@@ -11,35 +11,28 @@ export interface WebACLProps {
1111 readonly githubAllowListIpv4 : Array < string >
1212 readonly githubAllowListIpv6 : Array < string >
1313 readonly wafAllowGaRunnerConnectivity : boolean
14+ readonly allowedHeaders ?: Map < string , string >
1415 readonly scope : string
16+ readonly wafLogGroupName : string
1517}
1618
1719export class WebACL extends Construct {
18- public readonly githubAllowListIpv4 : wafv2 . CfnIPSet
19- public readonly githubAllowListIpv6 : wafv2 . CfnIPSet
20+ public readonly githubAllowListIpv4 : CfnIPSet
21+ public readonly githubAllowListIpv6 : CfnIPSet
2022 public readonly wafAllowGaRunnerConnectivity : boolean
21- public readonly webAcl : wafv2 . CfnWebACL
23+ public readonly webAcl : CfnWebACL
2224 public readonly attrArn : string
2325 public readonly allowedHeaders ?: Map < string , string >
2426
2527 public constructor (
2628 scope : Construct ,
2729 id : string ,
28- props : {
29- serviceName : string
30- rateLimitTransactions : number
31- rateLimitWindowSeconds : number
32- githubAllowListIpv4 : Array < string >
33- githubAllowListIpv6 : Array < string >
34- wafAllowGaRunnerConnectivity : boolean
35- allowedHeaders ?: Map < string , string >
36- scope : string
37- }
30+ props : WebACLProps
3831 ) {
3932 super ( scope , id )
4033
4134 if ( props . wafAllowGaRunnerConnectivity && props . githubAllowListIpv4 . length > 0 ) {
42- this . githubAllowListIpv4 = new wafv2 . CfnIPSet ( this , "githubAllowListIpv4" , {
35+ this . githubAllowListIpv4 = new CfnIPSet ( this , "githubAllowListIpv4" , {
4336 addresses : props . githubAllowListIpv4 ,
4437 ipAddressVersion : "IPV4" ,
4538 scope : props . scope ,
@@ -49,7 +42,7 @@ export class WebACL extends Construct {
4942 }
5043
5144 if ( props . wafAllowGaRunnerConnectivity && props . githubAllowListIpv6 . length > 0 ) {
52- this . githubAllowListIpv6 = new wafv2 . CfnIPSet ( this , "githubAllowListIpv6" , {
45+ this . githubAllowListIpv6 = new CfnIPSet ( this , "githubAllowListIpv6" , {
5346 addresses : props . githubAllowListIpv6 ,
5447 ipAddressVersion : "IPV6" ,
5548 scope : props . scope ,
@@ -58,7 +51,7 @@ export class WebACL extends Construct {
5851 } )
5952 }
6053
61- const rules : Array < wafv2 . CfnWebACL . RuleProperty > = [ ]
54+ const rules : Array < CfnWebACL . RuleProperty > = [ ]
6255 let nextPriority = 0
6356
6457 if ( props . wafAllowGaRunnerConnectivity && props . githubAllowListIpv4 . length > 0 ) {
@@ -214,7 +207,7 @@ export class WebACL extends Construct {
214207 }
215208 } )
216209
217- const webAcl = new wafv2 . CfnWebACL ( this , "CloudfrontWebAcl" , {
210+ const webAcl = new CfnWebACL ( this , "CloudfrontWebAcl" , {
218211 name : `${ props . serviceName } -WebAcl` ,
219212 defaultAction : { allow : { } } ,
220213 scope : props . scope ,
@@ -232,6 +225,11 @@ export class WebACL extends Construct {
232225 ]
233226 } )
234227
228+ new CfnLoggingConfiguration ( scope , "webAclLoggingConfiguration" , {
229+ logDestinationConfigs : [ props . wafLogGroupName ] ,
230+ resourceArn : webAcl . attrArn // Arn of Acl
231+ } )
232+
235233 this . webAcl = webAcl
236234 this . attrArn = webAcl . attrArn
237235 }
0 commit comments