Review the CloudFront WAF association

Apply WAF rules suited to the application’s risks.

Description

To apply AWS WAF rules at CloudFront, set the distribution’s web_acl_id to the ARN of a WAFv2 web ACL for CloudFront.

Potential impact

Without the association, requests you intended to filter can reach the origin application.

Remediation

Create the web ACL in us-east-1 with CLOUDFRONT scope and configure the rules your service needs. Check their effect on legitimate traffic before enabling blocking.

Examples

The second excerpt associates var.cloudfront_web_acl_arn with the distribution. Supply the remaining distribution settings, including the origin, cache behavior and certificate.

Before

hcl
resource "aws_cloudfront_distribution" "example" {
  enabled         = true
  is_ipv6_enabled = true
  comment         = var.site_domain

  aliases = [var.site_domain]
}

After

hcl
resource "aws_cloudfront_distribution" "example" {
  enabled         = true
  is_ipv6_enabled = true
  comment         = var.site_domain
  web_acl_id      = var.cloudfront_web_acl_arn

  aliases = [var.site_domain]
}

References