Skip to main content

AWS WAF

AWS WAF writes a log record for every request a web ACL inspects. Fluency collects those records from S3: WAF delivers log files to a bucket, the bucket sends an "object created" notification to an SQS queue, and the AWS WAF (S3 notification) application reads the queue and downloads each new file. One CloudFormation stack creates the bucket, the queue and the read access, and turns logging on.

Fluency reads with an assumed role, or with an IAM access key as the alternative, as described in Connecting to AWS. The one decision is where the web ACL logs today: a web ACL has a single logging destination, so if its CloudWatch Logs group has to stay, the logs are forwarded from there instead (path B).

The setup has two halves:

  1. In AWS: in the web ACL's region, create a stack from IngextAWSWAFS3Logging.yaml with the web ACL's ARN and your role's name. Copy the stack's QueueURL, Region and RoleARN outputs.
  2. In Fluency: register the role on Configuration → AWS Roles if it is new, then install the AWS WAF (S3 notification) application template with those values.

What arrives​

StreamWhat it holdsLands in
Web ACL logsOne record per request the web ACL inspects: the time, client IP and country, host, method, URI, query string and headers, the action (ALLOW, BLOCK, COUNT, CAPTCHA or CHALLENGE) and the rule that decided itThe AWSWAF index

The values of the Authorization, Cookie and Set-Cookie headers are replaced with [redacted] before the record is stored; on path A, the stack also has WAF redact Authorization and Cookie at the source. One record is written per request, so a busy web ACL can produce millions a day (Before you begin). Delivery starts when logging is turned on; earlier requests can be loaded only if they were logged somewhere (Loading past logs).

The record layout and the _http search fields are in Reference.

Choose a path​

A. Direct to S3 (recommended)B. From CloudWatch Logs
Use whenThe web ACL has no logging yet, or its CloudWatch Logs destination can be replaced.The web ACL logs to a CloudWatch Logs group (aws-waf-logs-<name>), and that has to stay.
Set up in AWSOne stack: the bucket, the queue, the read access and the logging.A subscription filter on the log group, a Firehose stream, a bucket, a queue and the read access: up to three stacks.
AWS costLog delivery to S3.CloudWatch Logs ingestion and storage, plus Firehose.
TemplateAWS WAF (S3 notification)AWS WAF (CloudWatch Logs)

Both paths store the same records in the same AWSWAF index. Pick one per web ACL: using both stores each request twice.

Before you begin​

  • The web ACL's ARN and region. In the AWS console, open WAF & Shield → Web ACLs, choose the region, open the web ACL, and copy its ARN. A web ACL attached to CloudFront is global, and its logging is set up in US East (N. Virginia) (us-east-1).
  • A region Fluency reads from. The queue is created in the web ACL's region, and the install form's AWS Region drop-down has to offer it; AWS CloudTrail's form shows the same list. For a region that isn't there, contact Fluency support.
  • What depends on the current logging destination. Turning on S3 logging replaces a CloudWatch Logs or Firehose destination. Check for dashboards, alarms and metric filters on the current log group first, or take path B.
  • AWS permissions to create S3 buckets, SQS queues, IAM roles or users and WAF logging configurations (wafv2:PutLoggingConfiguration), and to create CloudFormation stacks with the IAM acknowledgement.
  • The expected request rate, for a large web ACL. Tell Fluency support before you switch it on. AWS charges for log delivery to S3 and for the bucket's storage; the stack keeps files for 30 days by default, because Fluency keeps its own copy.

Part 1 (path A): AWS​

Step 1: Choose the role​

  • The account already has a registered role (for CloudTrail or another source): reuse it. In step 2, set IAMRole to its Role Name and ExternalID to its External ID, and leave PodRoleARN empty; the stack only adds read access to the WAF bucket.
  • No role yet: start the Setup Role wizard, as described in Connecting to AWS. On Role Details, enter a Role Name such as ingextWAFLogsRole, generate an External ID, and click Next. Copy PodRoleARN from the CloudFormation step's Parameters table, and leave the dialog open for step 4: the WAF stack creates the role, in place of the IngextSaasPodRole.yaml stack the dialog shows.

The wizard is on Configuration → AWS Roles → Setup Role.

Role Setup dialog on the 02 CloudFormation step: the URL, Region and Description fields, and the Parameters table listing IAMRole, ExternalID and PodRoleARN with their values

Where a role is not an option, skip this step and set AccessMode to accesskey in step 2: the stack then creates an IAM user and an access key instead.

Step 2: Create the stack​

In the AWS console, switch to the web ACL's region, open CloudFormation → Stacks → Create stack → With new resources (standard), choose Amazon S3 URL, and enter:

https://fluency-cloudformation.s3.us-east-2.amazonaws.com/IngextAWSWAFS3Logging.yaml

The console's four pages are as in Create the stack in the AWS console. On Specify stack details, set:

ParameterValue
WebACLArnThe web ACL's ARN. This replaces the web ACL's current logging destination. Leave it empty to create only the bucket and the queue, and turn logging on yourself (step 3).
BucketSuffixThe bucket is named aws-waf-logs-<suffix>, such as aws-waf-logs-mycompany-prod-us-east-1. Lower case, digits, dots and dashes; the name must be unique across all of AWS.
RetentionDaysDays to keep log files in the bucket. Defaults to 30.
RedactAuthHeaderstrue (the default) has WAF redact the Authorization and Cookie headers before it writes the logs.
SQSQueueNameDefaults to ingext-waf-logs. Use a name of its own for each stack in the account and region.
AccessModerole (the default, recommended) or accesskey.
PodRoleARNRole mode: the PodRoleARN from step 1 to create a new role, or empty to extend the existing role named in IAMRole.
IAMRoleRole mode: the Role Name from step 1, new or existing. Defaults to ingextWAFLogsRole.
ExternalIDRole mode: the role's External ID, or empty.
IAMUserAccess-key mode: the name of the IAM user to create. Defaults to ingext-waf-logs.

On Configure stack options, tick I acknowledge that AWS CloudFormation might create IAM resources with custom names, then submit the stack.

Capabilities box at the bottom of Configure stack options, with the IAM acknowledgement ticked

When the stack reaches CREATE_COMPLETE, its Outputs tab holds the values for Part 2: QueueURL and Region, and either RoleARN (role mode) or AccessKey and SecretKey (access-key mode). The secret stays readable there to anyone allowed to view the stack, so restrict who can. What the stack creates is listed in The stack; to build the same by hand, see Manual setup.

Step 3: Add more web ACLs​

Optional. One bucket and queue take logs from any number of web ACLs in the same region. For each one, open it in the WAF console, choose Logging and metrics → Enable, choose S3 bucket as the destination, and select the aws-waf-logs-<suffix> bucket. Under Redacted fields, add Single header authorization and cookie. Nothing changes in Fluency.

A web ACL in another region needs a stack of its own in that region, and an application of its own (Adding a region).

Optional: check the AWS side before you leave AWS

WAF writes a log file about every 5 minutes, and only for a web ACL that receives traffic, so request the protected site once. Within about 5 minutes:

  • a new file appears in the bucket under AWSLogs/<account-id>/WAFLogs/<region>/<web-acl>/YYYY/MM/DD/HH/mm/, and
  • the queue's Monitoring tab in the SQS console shows a message sent.
What you seeWhat it means
No file in the bucketLogging isn't on for the web ACL, or it had no traffic. Check its Logging and metrics tab.
A file, but no message on the queueThe bucket's notification is missing, or has another prefix.
A message on the queueThe AWS side is complete. Messages wait on the queue, for up to 14 days, until Fluency reads them.

Path A continues with Part 2.

Part 1 (path B): from CloudWatch Logs​

WAF keeps logging to its CloudWatch Logs group. A subscription filter copies new log events to an Amazon Data Firehose stream, Firehose writes them to a bucket in buffered files, and the bucket notifies a queue. The CloudWatch templates are the ones described in Amazon CloudWatch. Work in the log group's region throughout.

Step B1: Find the log group​

Open the web ACL in the WAF console, choose Logging and metrics, and note the log group's name. WAF requires it to start with aws-waf-logs-.

Step B2: Create the bucket and the Firehose roles​

Skip this step if the stack already exists in this account and region for another log group; reuse its bucket. Otherwise create a stack from:

https://fluency-cloudformation.s3.us-east-2.amazonaws.com/FluencyCloudWatchFirehose.yaml
  • S3Bucket: a new bucket name, unique across all of AWS, such as mycompany-cloudwatch-firehose.
  • CloudWatchRole and FirehoseRole: keep the defaults. IAM role names are account-wide, so in a second region give both names of their own.

Step B3: Subscribe the WAF log group​

Create a stack from:

https://fluency-cloudformation.s3.us-east-2.amazonaws.com/FluencyCloudWatchSubscriptionFilter.yaml
ParameterValue
NameA short name such as waf-prod. The Firehose stream becomes fluency-cloudwatch-waf-prod, and its files land under cloudwatch/waf-prod/.
LogGroupThe log group from B1.
S3BucketThe bucket from B2.
FilterPatternLeave empty, so that every request is sent.
FilterName, CloudWatchRole, FirehoseRoleKeep the defaults, which have to match B2.

A log group takes at most two subscription filters; if it already has two, remove one first. For another WAF log group, run this stack again with another Name.

Step B4: Add the queue and the read access​

Create a stack from IngextS3SqsNotification.yaml, as described in Connecting to AWS, step 3, with these values:

ParameterValue
S3BucketThe bucket from B2.
S3BucketPrefixcloudwatch/<Name>/, with the Name from B3, such as cloudwatch/waf-prod/.
SQSQueueNameA name for the queue, such as ingext-waf-cloudwatch.
PodRoleARN, IAMRole, ExternalIDAs in step 1 and step 2 of path A: PodRoleARN empty for a registered role, or the wizard's value to create one.

Copy the QueueURL output, and RoleARN if the stack created the role. In Part 2, install AWS WAF (CloudWatch Logs), not AWS WAF (S3 notification), and not the general CloudWatch LogGroup template, whose parser is for VPC flow logs and drops WAF records.

Alternative for a low-traffic web ACL: Lambda instead of Firehose

https://fluency-cloudformation.s3.us-east-2.amazonaws.com/FluencyCloudWatchLambdaS3.yaml replaces B2 and B3. It creates a bucket of its own, and its Lambda function writes each CloudWatch Logs batch to a separate file under logGroups/<log group name>/. Use logGroups/ as S3BucketPrefix in B4.

Because it writes a file per batch, a busy web ACL produces many more files than it does through Firehose, and Fluency can fall behind. Use it only for a web ACL with little traffic.

Part 2: Fluency​

Step 4: Register the role​

Skip this step if you reused a registered role, or used an access key.

Back in the Setup Role dialog from step 1, click Next until Complete Setup (through the Hosting Account step on sites that have one; see Complete Setup). Give the role a Display Name such as WAF logs, enter the stack's RoleARN output in Role ARN, and save. If you closed the dialog, register the role with Add Role instead, with the same External ID.

Click Add. The notice Successfully added role. appears, and the role joins the AWS Roles table.

Step 5: Install the application​

In the navigation rail, open Applications and click Install Application, then choose AWS WAF (S3 notification) from the AWS Services category of the Application Catalog. For path B, choose AWS WAF (CloudWatch Logs), which has the same fields.

Don't choose the plain AWS WAF template: it reads a bucket listing and is for loading past logs.

ParameterNotes
AWS RegionDrop-down, opens on US N.Virginia. The Region output: the region of the queue and the bucket.
SQS notification queue urlThe QueueURL output: the full https://sqs. URL, not the ARN.
Pre-defined AWS RoleThe recommended credential: the display name of the role from step 4, or of the registered role you reused, on AWS Roles (v1: Settings → AWS Roles).
Pre-defined AWS UserLeave empty. A form takes one credential, not several: the role or the access key.
IAM access keyAlternative: the AccessKey output. Use instead of a role, not as well as.
IAM access secretAlternative: the SecretKey output.
datalakeIn the collapsed Advanced configuration section (v1: Advanced Configurations row); expand it to see it. Pre-filled managed.
datalake index nameIn the same collapsed section. Pre-filled AWSWAF. Two applications writing to the same index name in the same lake will collide, and the second one aborts, so a second AWS WAF application needs a name of its own.

Click Dry run first to have the platform check the form's values and credentials before anything is installed, then click Install Application. The Applications page opens with the notice Default is launching., and the new application is listed with a green Running badge once the pipeline is up.

Confirm it is running​

  1. The role. Its Status on Configuration → AWS Roles reads Valid (v1: its Status dot on Settings → Advanced → AWS Roles is green).
  2. The application. It is listed on Applications with a green Running badge (v1: its card on Platform → Applications).
  3. The queue. In the SQS console, Messages available stays near zero. A growing number means Fluency isn't reading the queue (see Troubleshooting).
  4. The records. A search of the AWSWAF index, or the index name you chose, over the last hour returns records with httpRequest.clientIp, action and _http.path. WAF writes files about every 5 minutes, only while the web ACL has traffic; path B adds up to about 5 more minutes of Firehose buffering.

See also Confirm data is arriving. Once the application is Running and requests are in the AWSWAF index, setup is complete.

Maintenance​

An installed application's parameters are read-only: changing its role, key or queue means uninstalling it and installing it again. Messages that arrive while no application reads the queue wait there (for 14 days on the queue the WAF stack creates, 4 days on a queue from IngextS3SqsNotification.yaml) and are collected once the new application starts.

Adding a region​

Repeat step 2 in the new region, with another BucketSuffix and with PodRoleARN empty, so that the stack extends the role rather than trying to create it again. Then install another AWS WAF (S3 notification) application with that stack's Region and QueueURL. Give its datalake index name a name of its own, such as AWSWAF_EU, since AWSWAF is taken by the first application.

Loading past logs​

S3 delivery starts when logging is turned on. Earlier requests can be loaded only if they were logged somewhere:

  • CloudWatch Logs. Run Export data to Amazon S3 on the log group for the date range, then give Fluency support the bucket and prefix. Export files are in another format and aren't announced on a queue, so they are loaded with the AWS WAF application, which reads the bucket for a set range of keys and is uninstalled once the import is finished.
  • Firehose to S3. Give Fluency support the bucket and prefix.

Removing the integration​

  1. Uninstall the application: click Uninstall at the top right of its details page (v1: the red Uninstall button at the foot of its details panel on Platform → Applications).
  2. Delete the stacks. Deleting the path A stack turns WAF logging off for the web ACL it named. CloudFormation can't delete a bucket that still holds files, so empty the bucket first, or keep it when the deletion stops on it.
  3. Delete the role registration on AWS Roles if nothing else uses it.

Troubleshooting​

SymptomLikely causeFix
The stack fails on WAFLoggingThe web ACL is in another region, or the ARN is wrong.Create the stack in the web ACL's region (us-east-1 for CloudFront), or run it with WebACLArn empty and turn logging on in the console (step 3).
The stack fails on LogBucket with "already exists"The bucket name is taken.Choose another BucketSuffix.
The stack fails, asking for IAM capabilitiesThe IAM acknowledgement wasn't ticked.Tick it on Configure stack options (step 2).
No files in the bucketLogging isn't on for the web ACL, or it has no traffic.Check the web ACL's Logging and metrics tab.
Files in the bucket, the queue stays emptyThe bucket notification is missing or has another prefix, or another consumer deletes the messages.Give the queue one consumer only, and check the notification under the bucket's Properties → Event notifications.
Messages pile up on the queueThe application can't read the queue.Check AWS Region, the queue URL, and that the role is Valid and chosen; for an access key, that it is active. Reinstall to correct a value.
Fluency reports AccessDenied on objectsThe bucket uses SSE-KMS, or the read policy doesn't cover the prefix.Use SSE-S3, or grant the role kms:Decrypt on the key; check the prefix of the read policy.
The role's Status stays Invalid (v1: its dot stays red)The trust policy or External ID doesn't match.See Connecting to AWS, step 2.
The application shows Error (v1: Aborted)Its index name is already used by another application.Uninstall it and install it again with another datalake index name.
The CloudWatch log group stopped receiving logsExpected on path A: a web ACL has one logging destination.Take path B if the log group has to stay.
Path B: no files under cloudwatch/<Name>/The subscription filter is missing, or the log group already had two.Check the log group's Subscription filters tab (step B3).
Every request is stored twiceBoth paths are set up for the same web ACL.Remove one of them.

Reference​

What the stack creates, the layout of a stored record, and the manual equivalent of the stack, for whoever builds the AWS side by hand or writes searches and detection rules.

The stack

IngextAWSWAFS3Logging.yaml creates:

  • The S3 bucket aws-waf-logs-<suffix>: private, encrypted with SSE-S3, HTTPS only, with a lifecycle rule that deletes files after RetentionDays.
  • A bucket policy that lets AWS log delivery write under AWSLogs/<account-id>/.
  • The SQS queue, which keeps messages for 14 days, and an "object created" notification for every new file under AWSLogs/.
  • The WAF logging configuration from the web ACL to the bucket, with authorization and cookie redacted when RedactAuthHeaders is true. Not created when WebACLArn is empty.
  • A read-only IAM policy: sqs:ReceiveMessage, sqs:DeleteMessage, sqs:GetQueueUrl and sqs:GetQueueAttributes on the queue, s3:ListBucket on the bucket and s3:GetObject under AWSLogs/. It is attached to the role (role mode) or the user (access-key mode).
  • The role, trusting your tenant's pod role with sts:AssumeRole (conditioned on the External ID, if one is given) and sts:TagSession, when PodRoleARN is set; the IAM user and its access key in access-key mode.

Its outputs are BucketName, QueueURL, Region, and RoleARN (role mode) or AccessKey and SecretKey (access-key mode).

Record layout and the _http search fields

Each record is stored under @awswaf with WAF's own field names (timestamp, action, terminatingRuleId, httpRequest.clientIp, httpRequest.country, httpRequest.headers, httpRequest.uri, httpRequest.args, labels, ruleGroupList and the rest), and is queryable in KQL by those names. @timestamp is WAF's timestamp, and @parser is fpl-AWSWAFAdjustments.

Two changes are made on the way in. The values of the authorization, cookie and set-cookie headers are replaced with [redacted], because WAF logs them in clear and they are live session credentials. And _http carries flat copies of the fields searches and rules key on:

FieldHolds
_http.clientIp, _http.countryThe client's IP address and country, from httpRequest.
_http.method, _http.hostThe HTTP method, and the host in lower case.
_http.uri, _http.pathThe URI as sent, and the same in lower case.
_http.queryThe query string (httpRequest.args), partly URL-decoded, so a search matches where[ whether or not the client encoded the brackets.
_http.userAgent, _http.contentType, _http.xForwardedForThe matching request headers.
_http.action, _http.terminatingRuleIdWAF's decision and the rule that made it.
_http.labelsThe names of the labels managed rule groups and custom rules added, as one list.
_http.hasAuthorizationWhether the request carried an Authorization header.

Records that arrive through path B also carry the log group and stream they came from, as _cw.logGroup and _cw.logStream.

Manual setup, without CloudFormation
  1. Create an S3 bucket named aws-waf-logs-<suffix> in the web ACL's region, with SSE-S3 encryption (not SSE-KMS) and public access blocked.
  2. Turn on logging for the web ACL with the bucket as its destination (step 3). The console adds the log-delivery bucket policy.
  3. Create an SQS queue whose access policy lets s3.amazonaws.com call sqs:SendMessage, restricted to the bucket's ARN and your account. Then add an event notification to the bucket for All object create events, prefix AWSLogs/, sending to the queue. AWS CloudTrail (its Manual tab) shows both screens.
  4. Grant Fluency sqs:ReceiveMessage, sqs:DeleteMessage, sqs:GetQueueUrl and sqs:GetQueueAttributes on the queue, and s3:ListBucket and s3:GetObject on the bucket, through the role or an IAM user (Connecting to AWS).
  5. Continue with Part 2.

AWS documentation

Fluency

Other integrations