This document will provide detailed instructions and a step-by-step process to setup and configure a WAF for AWS using Cloudfront.

Phase 1: Prerequisites

  1. Existing CloudFront Distribution: Ensure you have a functioning Amazon CloudFront distribution serving your application or static site.
  2. Access: Ensure you have the necessary IAM permissions to modify WAF, CloudFront, and Logging resources.

Phase 2: Creating the Web ACL

  1. Open the AWS WAF Console: Navigate to WAF & Shield in the AWS Management Console.
  2. Create a Web ACL:
  3. Associate AWS resources:

Phase 3: Adding Rules and Rule Groups

  1. Under Add rules and rule groups, click Add rules.
  2. AWS Managed Rules: It is highly recommended to start here.
  3. Custom Rules (Optional): You can create custom rules for specific needs, such as:
  4. Set Default Action: At the bottom, choose the default action for requests that do not match any of your rules. For most web applications, this is set to Allow.
  5. Set Rule Priority: AWS evaluates rules from top to bottom. Drag your rules to order them (e.g., Custom IP Allow/Deny lists should usually go at the very top, before Managed Rules).

Phase 4: Configure Logging and Metrics (Enterprise Crucial)

  1. Metrics: Enable Amazon CloudWatch metrics so you can monitor blocked and allowed requests.
  2. Logging destination: Enable logging. You will need to select an Amazon S3 bucket, a CloudWatch Logs log group, or Amazon Kinesis Data Firehose.

Phase 5: Testing and Deployment

  1. Start in "Count" Mode: When adding your rules, set the action of each rule to Count instead of Block. This acts as a "dry run."
  2. Monitor Traffic: Let the WAF run in Count mode for a few days. Review the logs to identify any "false positives" (legitimate traffic that would have been blocked).
  3. Switch to "Block": Once you have tuned your rules and verified that legitimate users are not being impacted, edit the Web ACL and change the rule actions from Count to Block.