This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Cloudflare WAF

    SamurAI [Local] CollectorSamurAI [Cloud] Collector
    Picture1.svg

    This guide describes the steps required to configure Cloudflare Web Application Firewall (WAF) to stream its security logs to public cloud storage (Microsoft Azure Blob Storage or Amazon S3) for ingestion to the SamurAI platform via a Cloud Collector.

    Cloudflare WAF logs are collected from two zone-level datasets, delivered by:

    • Creating a Logpush job in the Cloudflare dashboard for each dataset, in each zone you wish to monitor
    • Cloudflare writing the log files to a customer owned cloud storage container / bucket
    • The SamurAI Cloud Collector monitoring that storage for new files and pulling the data into the SamurAI platform

    Prerequisites

    Ensure that a Samurai Cloud Collector has been deployed via the SamurAI Portal for your chosen cloud provider (Microsoft Azure or Amazon Web Services).

    Take note of the following as it will be required when configuring the Logpush destination:

    • Microsoft Azure — the Storage account name
    • Amazon Web Services — the S3 bucket name and the Region

    If you are planning to reuse an already deployed Cloud Collector, this information can be found via:

    1. Navigate to the SamurAI Portal
    2. Click Telemetry and select Collectors from the main menu
    3. Click on the name of the desired Collector
    4. Note down the storage information presented

    Supported datasets

    DatasetSourcetypeProduct
    Firewall events (firewall_events)cloudflare_waf_firewall_eventsWAF Firewall Events
    HTTP requests (http_requests)cloudflare_waf_http_requestsWAF HTTP Requests

    Storage naming requirement

    Add Logpush custom fields

    Request and response header values are not included in the http_requests dataset by default. The RequestHeaders and ResponseHeaders fields are only populated for headers configured as Logpush custom fields, so these must be configured before creating the Logpush jobs. Custom fields are configured per zone and apply to the http_requests dataset only.

    Some headers can only be configured via the Cloudflare API, so this section configures all required fields in bulk through the Rulesets API. Refer to the vendor documentation for further details: Custom fields.

    Repeat this section for each zone you wish to monitor.

    Before starting, you will need:

    • The Zone ID of the target zone ($ZONE_ID)
    • An API token ($API_TOKEN) with the Zone Logs: Edit (Logs Write) permission for the target zone

    Check for an existing ruleset

    Check whether a ruleset for the http_log_custom_fields phase already exists in the zone.

    curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets" \
      -H "Authorization: Bearer $API_TOKEN" \
      | jq '.result[] | select(.phase=="http_log_custom_fields" and .kind=="zone")'
    

    If a ruleset exists, a response similar to the following is returned. Note the id and continue to Update the ruleset.

    {
      "description": "",
      "id": "17e8c0cd9b9c4e278e78ce390e089202",
      "kind": "zone",
      "last_updated": "2026-07-10T03:23:46.697578Z",
      "name": "Zone-level phase entry point",
      "phase": "http_log_custom_fields",
      "version": "3"
    }
    

    Create the ruleset

    If no ruleset exists, create one. If your curl version does not support the --json option, use --data together with --header "Content-Type: application/json" instead.

    curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets" \
      --request POST \
      --header "Authorization: Bearer $API_TOKEN" \
      --json '{
        "name": "Zone-level phase entry point",
        "kind": "zone",
        "description": "This ruleset configures custom log fields.",
        "phase": "http_log_custom_fields"
      }'
    

    On success, note the id returned in the response as it is required in the next step.

    Update the ruleset

    Replace $id with the ruleset ID noted above and run the following command.

    curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$id" \
      --request PUT \
      --header "Authorization: Bearer $API_TOKEN" \
      --json '{"rules":[{"action":"log_custom_field","expression":"true","description":"Set Logpush custom fields","action_parameters":{"request_fields":[{"name":"accept"},{"name":"accept-charset"},{"name":"accept-language"},{"name":"authorization"},{"name":"cache-control"},{"name":"content-type"},{"name":"cookie"},{"name":"forwarded"},{"name":"origin"},{"name":"range"},{"name":"sec-fetch-mode"},{"name":"sec-fetch-site"},{"name":"te"},{"name":"transfer-encoding"},{"name":"upgrade"},{"name":"x-api-key"},{"name":"x-auth-token"},{"name":"x-forwarded-host"},{"name":"x-http-method-override"},{"name":"x-original-uri"},{"name":"x-original-url"},{"name":"x-real-ip"},{"name":"x-requested-with"},{"name":"x-rewrite-url"}],"transformed_request_fields":[{"name":"accept-encoding"},{"name":"true-client-ip"},{"name":"x-forwarded-for"},{"name":"x-forwarded-proto"}],"raw_response_fields":[{"name":"accept-ranges","preserve_duplicates":true},{"name":"access-control-allow-credentials","preserve_duplicates":true},{"name":"access-control-allow-headers","preserve_duplicates":true},{"name":"access-control-allow-methods","preserve_duplicates":true},{"name":"access-control-allow-origin","preserve_duplicates":true},{"name":"age","preserve_duplicates":true},{"name":"cache-control","preserve_duplicates":true},{"name":"content-disposition","preserve_duplicates":true},{"name":"content-encoding","preserve_duplicates":true},{"name":"content-range","preserve_duplicates":true},{"name":"content-security-policy","preserve_duplicates":true},{"name":"date","preserve_duplicates":true},{"name":"etag","preserve_duplicates":true},{"name":"expires","preserve_duplicates":true},{"name":"last-modified","preserve_duplicates":true},{"name":"location","preserve_duplicates":true},{"name":"retry-after","preserve_duplicates":true},{"name":"server","preserve_duplicates":true},{"name":"set-cookie","preserve_duplicates":true},{"name":"strict-transport-security","preserve_duplicates":true},{"name":"vary","preserve_duplicates":true},{"name":"www-authenticate","preserve_duplicates":true},{"name":"x-content-type-options","preserve_duplicates":true},{"name":"x-frame-options","preserve_duplicates":true},{"name":"x-powered-by","preserve_duplicates":true}]}}]}'
    

    On success, a response similar to the following is returned (abbreviated):

    {
      "result": {
        "id": "17e8c0cd9b9c4e278e78ce390e089202",
        "kind": "zone",
        "name": "Zone-level phase entry point",
        "phase": "http_log_custom_fields",
        "rules": [
          {
            "action": "log_custom_field",
            "description": "Set Logpush custom fields",
            "enabled": true,
            "expression": "true"
          }
        ]
      },
      "success": true,
      "errors": [],
      "messages": []
    }
    

    To confirm, open the zone in the Cloudflare dashboard, navigate to the Logpush page, select Configuration and verify the custom log fields have been added.

    Configure Logpush in Cloudflare

    Follow the vendor documentation to create one Logpush job per dataset, writing to the storage prepared above.

    Logpush jobs for the WAF datasets are created at the zone level. Select the zone you wish to collect logs from, then navigate to Investigate > Logpush. The menu location may differ depending on the Cloudflare dashboard version.

    Ensure the custom fields have been configured, then select the section below that matches your deployed Cloud Collector, complete the destination steps, then apply the Logpush job settings.

    Amazon S3 (AWS Cloud Collector)

    1. Confirm the bucket name and region. Use the S3 bucket name and Region noted in the Prerequisites. This is the bucket monitored by the Cloud Collector.

    2. Start creating the Logpush job. In the Cloudflare dashboard, open the Logpush page, select Create a Logpush job and choose Amazon S3 as the destination.

    3. Enter the bucket and copy the bucket policy. Enter the S3 bucket name in the Bucket field. Once entered, Cloudflare automatically generates the bucket policy JSON that allows Cloudflare to upload logs to the bucket. Copy it, but do not select Continue yet.

    4. Add the Cloudflare statement to the existing bucket policy. In the AWS Management Console open the bucket, then Permissions > Bucket policy. Add the Statement element generated by Cloudflare as a new element in the existing Statement array.

      For example, the bucket policy initially contains only the read permission for the Cloud Collector:

      {
        "Version": "2012-10-17",
        "Statement": [
          {
            "Sid": "AllowSamuraiXdrReader",
            "Effect": "Allow",
            "Principal": {
              "AWS": "arn:aws:iam::600502389717:user/samurai-xdr-s3-reader-user"
            },
            "Action": [
              "s3:GetObject",
              "s3:ListBucket"
            ],
            "Resource": [
              "arn:aws:s3:::<bucket-name>",
              "arn:aws:s3:::<bucket-name>/*"
            ]
          }
        ]
      }
      

      After adding the Cloudflare statement, the policy will look similar to the following. Save the policy.

      {
        "Version": "2012-10-17",
        "Statement": [
          {
            "Sid": "Stmt1506627150918",
            "Effect": "Allow",
            "Principal": {
              "AWS": "arn:aws:iam::391854517948:user/cloudflare-logpush"
            },
            "Action": "s3:PutObject",
            "Resource": "arn:aws:s3:::<bucket-name>/*"
          },
          {
            "Sid": "AllowSamuraiXdrReader",
            "Effect": "Allow",
            "Principal": {
              "AWS": "arn:aws:iam::600502389717:user/samurai-xdr-s3-reader-user"
            },
            "Action": [
              "s3:GetObject",
              "s3:ListBucket"
            ],
            "Resource": [
              "arn:aws:s3:::<bucket-name>",
              "arn:aws:s3:::<bucket-name>/*"
            ]
          }
        ]
      }
      
    5. Enter the Path and Bucket region. Return to the Cloudflare Logpush page and complete the following:

      • Path: enter a value that ends with the required suffix for the dataset, as listed in Storage naming requirement — for example contoso-cloudflare-waf-firewall-events. The Path is what the SamurAI platform uses to identify the dataset, so each dataset needs its own Path.
      • Enable Organize logs into daily subfolders.
      • Bucket region: select the region of the bucket confirmed in step 1.
      • Select Continue.
    6. Complete ownership verification. Cloudflare places an ownership verification file at the specified bucket and Path. Open the file in the S3 bucket, copy the ownership token, enter it in Cloudflare and select Continue.

    Microsoft Azure (Azure Cloud Collector)

    1. Create a container for the dataset. In the Azure portal open the Storage account noted in the Prerequisites and create a Blob Storage container whose name ends with the required suffix for the dataset, as listed in Storage naming requirement — for example contoso-cloudflare-waf-firewall-events. Each dataset needs its own container.

    2. Generate a SAS URL. In the Storage account select Security + networking > Shared access signature and configure:

      • Allowed services: Blob
      • Allowed resource types: Object
      • Allowed permissions: Write
      • Allowed protocols: HTTPS only
      • Expiry time: Cloudflare requires an expiration period of at least five years (see the note below)

      Select Generate SAS and connection string and copy the Blob service SAS URL.

    3. Create the Logpush job. In the Cloudflare dashboard, open the Logpush page, select Create a Logpush job and choose Microsoft Azure as the destination. Complete the following:

      • SAS URL: enter the Blob service SAS URL generated in step 2.
      • Path: enter the container name created in step 1 (ending with the required suffix). The Path is what the SamurAI platform uses to identify the dataset.
      • Enable Organize logs into daily subfolders.
      • Select Continue.

    Logpush job settings

    After the destination steps, on the dataset selection and job configuration screens:

    • Select the dataset that matches the Path you entered.

    • Set the Job name to the same string as the Path.

    • Under If logs match…:

      • firewall_events — select All logs. Do not configure a filter.
      • http_requests — select Filtered logs and add the filter below, so that only requests associated with a Cloudflare security rule are sent.
      FieldOperatorValue
      SecurityRuleIDdoes not equal(leave blank)
    • Under Send the following fields…, select Select all. Confirm that RequestHeaders and ResponseHeaders are included.

    • Set Timestamp format to RFC3339.

    • Do not enable Sampling unless it is required for volume control.

    • Select Submit to create the job.

    Repeat for each dataset

    To collect both firewall_events and http_requests, create a second Logpush job for the other dataset. The bucket policy (Amazon S3) and SAS URL (Microsoft Azure) can be reused, however the Path / container, ownership verification (Amazon S3), dataset selection and job settings must be completed for each dataset.

    Finally, return to the Logpush page and confirm that both jobs are listed and enabled.

    Cloudflare Logpush delivery

    Be aware of the following Logpush behaviour:

    • If delivery to the destination fails, Cloudflare retries five times at one-minute intervals. Logs that are not delivered within the retry period are dropped and cannot be resent or backfilled later.
    • If the destination is unreachable for 24 hours, the Logpush job may be disabled by Cloudflare.
    • We recommend enabling the Failing Logpush Job Disabled notification in Cloudflare Notifications. The notification is configured at the account level and applies to all jobs in the account. Refer to Logpush alerts and analytics.
    • Depending on your Cloudflare plan, multiple destinations may be configurable per dataset. If required, a backup destination can be configured within the limits of your plan.

    Log the detection payload

    Cloudflare WAF Managed Rules can log the payload of requests that match a rule in a Managed Ruleset. The payload includes the string that triggered the detection along with the text immediately before and after it, which provides valuable context when investigating an alert.

    This feature is available on the Cloudflare Enterprise plan and can only be enabled by a Super Administrator. Payloads are logged only for requests matched after the feature is enabled. Follow the vendor documentation to enable it:

    Our Integration guide was accurate at the time of writing but vendors change things frequently! If you find errors or anything is outdated, let us know by raising a request in the SamurAI MDR Portal and we shall get it updated.