What a WAF inspects
A WAF attached to a load balancer inspects every request to the load balancer’s http and https
listeners: its method, path, query, headers, cookies and the first 16 KB of a request body. tcp and
tls listeners pass untouched.
A WAF is in a project and a region, and attaches to load balancers and CDN distributions in the same project and region. One WAF can be attached to several of them; a load balancer or distribution has at most one WAF.
Evaluation order
Each request goes through:
- The custom rules, top to bottom. The first matching rule that ends the request
wins:
allowlets it through and skips the managed rule sets, andblockanswers403. Alogrule records the match and carries on, and a rate limit ends the request only for a client over its limit. - The managed rule sets, in the order the WAF lists them. A set that
blocks answers
403. - Requests that nothing ended are allowed.
Block and log-only
A WAF’s mode is block or log. In log (Log only in the console), every block of the WAF,
from any rule or managed rule set, is recorded instead, and the request goes on to its target. Each
managed rule set has its own mode too, so you can try a new set in log-only mode while the rest of
the WAF blocks.
Start a new WAF, or a new set, in log-only mode, read its logs, then switch it to
block.
Attach and detach
A load balancer’s wafId attaches a WAF: set it to a waf_ ID with
UpdateLoadBalancer, or to null to detach.
ezgh lb load-balancers update lbr_4k2m9x0a7qpe --waf waf_8m2k4q6t9x1c
ezgh lb load-balancers update lbr_4k2m9x0a7qpe --waf none- Attaching needs
waf.wafs.attachon the WAF andlb.loadBalancers.updateon the load balancer. - A WAF in another project or region is refused with
409 waf_mismatch. - The load balancer’s
wafshows the WAFversionit runs and itsstatus:applyingwhile a change reaches the load balancer, thenapplied, ornot_appliedif that version can’t be applied; the load balancer’slastChangesays so, and it keeps serving with the version before.
Changing a WAF
UpdateWaf replaces the whole WAF: send it with the ETag of the version
you read in If-Match. Each change raises the WAF’s version, and reaches the load balancers it’s
attached to in seconds.
| Error | Means |
|---|---|
400 invalid_request |
A field is wrong; issues lists each problem at its path, such as rules.2.conditions.0.value. |
412 precondition_failed |
The WAF changed since you read it. Read it again and retry. |
422 waf_too_large |
The WAF is too large. Use fewer or smaller country, ASN and IP set conditions. |
409 waf_in_use |
A delete of a WAF that’s attached. The message names the load balancers; detach it from them first. |