Skip to content

Commit 704e619

Browse files
fix(query): resolve false positive on ALB WAF integration with WAFv2 #7405
1 parent e1f23ca commit 704e619

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

assets/queries/cloudFormation/aws/alb_is_not_integrated_with_waf/query.rego

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,28 @@ internal_alb(resource) {
2626
scheme == "internal"
2727
}
2828

29+
waf_association_types := {"AWS::WAFRegional::WebACLAssociation", "AWS::WAFv2::WebACLAssociation"}
30+
2931
associated_waf(target_alb) {
3032
resource := input.document[_].Resources[_]
31-
resource.Type == "AWS::WAFRegional::WebACLAssociation"
33+
waf_association_types[resource.Type]
3234
resource.Properties.ResourceArn.Ref == target_alb
3335
}
3436

3537
associated_waf(target_alb) {
3638
resource := input.document[_].Resources[_]
37-
resource.Type == "AWS::WAFRegional::WebACLAssociation"
39+
waf_association_types[resource.Type]
3840
resource.Properties.ResourceArn == target_alb
3941
}
42+
43+
associated_waf(target_alb) {
44+
resource := input.document[_].Resources[_]
45+
waf_association_types[resource.Type]
46+
resource.Properties.ResourceArn["Fn::GetAtt"][0] == target_alb
47+
}
48+
49+
associated_waf(target_alb) {
50+
resource := input.document[_].Resources[_]
51+
waf_association_types[resource.Type]
52+
startswith(resource.Properties.ResourceArn, sprintf("%s.", [target_alb]))
53+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Resources:
3+
MyLoadBalancerV2:
4+
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
5+
Properties:
6+
Name: myloadbalancerv2
7+
Scheme: internet-facing
8+
MyWebACLAssociation:
9+
Type: "AWS::WAFv2::WebACLAssociation"
10+
Properties:
11+
ResourceArn: !GetAtt MyLoadBalancerV2.LoadBalancerArn
12+
WebACLArn: !Ref MyWebACL
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09T00:00:00Z",
3+
"Resources": {
4+
"MyLoadBalancerV2": {
5+
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
6+
"Properties": {
7+
"Name": "myloadbalancerv2",
8+
"Scheme": "internet-facing"
9+
}
10+
},
11+
"MyWebACLAssociation": {
12+
"Type": "AWS::WAFv2::WebACLAssociation",
13+
"Properties": {
14+
"ResourceArn": {
15+
"Ref": "MyLoadBalancerV2"
16+
},
17+
"WebACLArn": {
18+
"Ref": "MyWebACL"
19+
}
20+
}
21+
}
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
Resources:
3+
MyLoadBalancerV2b:
4+
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
5+
Properties:
6+
Name: myloadbalancerv2b
7+
Scheme: internet-facing
8+
MyWebACLAssociation:
9+
Type: "AWS::WAFv2::WebACLAssociation"
10+
Properties:
11+
ResourceArn: !Ref MyLoadBalancerV2b
12+
WebACLArn: !Ref MyWebACL
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09T00:00:00Z",
3+
"Resources": {
4+
"MyLoadBalancerV2c": {
5+
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
6+
"Properties": {
7+
"Name": "myloadbalancerv2c",
8+
"Scheme": "internet-facing"
9+
}
10+
},
11+
"MyWebACLAssociation": {
12+
"Type": "AWS::WAFv2::WebACLAssociation",
13+
"Properties": {
14+
"ResourceArn": {
15+
"Fn::GetAtt": ["MyLoadBalancerV2c", "LoadBalancerArn"]
16+
},
17+
"WebACLArn": {
18+
"Ref": "MyWebACL"
19+
}
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)