Description
To filter requests with AWS WAF on an internet-facing ALB, associate a web ACL with the load balancer.
Potential impact
Without the association, requests can reach the application without being evaluated against those WAF rules.
Remediation
Set the ALB ARN and the ARN of a REGIONAL web ACL in the same Region on aws_wafv2_web_acl_association. Check that legitimate traffic passes and that the intended blocking rules take effect.
Examples
The second excerpt attaches a separately defined web ACL to aws_lb.alb. The ACL’s rules and default action determine what it blocks.
Before
hcl
resource "aws_lb" "alb" {
name = "test-lb-tf"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb_sg.id]
subnets = [for subnet in aws_subnet.public : subnet.id]
}
After
hcl
resource "aws_lb" "alb" {
name = "test-lb-tf"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.lb_sg.id]
subnets = [for subnet in aws_subnet.public : subnet.id]
}
resource "aws_wafv2_web_acl_association" "alb_waf_association" {
resource_arn = aws_lb.alb.arn
web_acl_arn = aws_wafv2_web_acl.example.arn
}