WAF Managed Rules
This page provides examples of deploying and configuring WAF Managed Rules in your zone or account using Terraform. It covers the following configurations:
- Deploy managed rulesets
- Configure skip rules
- Configure payload logging
- Configure overrides
- Configure the OWASP paranoia level, score threshold, and action
For more information on WAF Managed Rules, refer to WAF Managed Rules in the Cloudflare WAF documentation. For more information on deploying and configuring rulesets using the Rulesets API, refer to Work with managed rulesets in the Ruleset Engine documentation.
The Terraform configurations provided in this page need the zone ID (or account ID) of the zone/account where you will deploy the managed rulesets.
- To retrieve the list of accounts you have access to, including their IDs, use the List accounts operation.
- To retrieve the list of zones you have access to, including their IDs, use the List zones operation.
The deployment of managed rulesets via Terraform requires that you use the ruleset IDs. To find the IDs of managed rulesets, use the List account rulesets operation. The response will include the description and IDs of existing managed rulesets.
Terraform assumes that it has complete control over account and zone rulesets. If you already have rulesets configured in your account or zone, do one of the following:
- Import existing rulesets to Terraform using the
cf-terraforming
tool. Recent versions of the tool can generate resource definitions for existing rulesets and import their configuration to Terraform state. - Start from scratch by deleting existing rulesets (account and zone rulesets with
"kind": "root"
and"kind": "zone"
, respectively) and then defining your rulesets configuration in Terraform.
The following example deploys two managed rulesets to the zone with ID <ZONE_ID>
using Terraform, using a cloudflare_ruleset
resource with two rules that execute the managed rulesets.
Account-level example configuration
The following example deploys two managed rulesets to the account with ID <ACCOUNT_ID>
using Terraform, using a cloudflare_ruleset
resource with two rules that execute the managed rulesets for two hostnames belonging to Enterprise zones.
The following example adds two skip rules (or exceptions) for the Cloudflare Managed Ruleset:
- The first rule will skip the execution of the entire Cloudflare Managed Ruleset (with ID
...376e9aee
) for specific URLs, according to the rule expression. - The second rule will skip the execution of two rules belonging to the Cloudflare Managed Ruleset for specific URLs, according to the rule expression.
Add the two skip rules to the cloudflare_ruleset
resource before the rule that deploys the Cloudflare Managed Ruleset:
The following example adds three overrides for the Cloudflare Managed Ruleset:
- A rule override for rule with ID
5de7edfa648c4d6891dc3e7f84534ffa
setting the action tolog
. - A rule override for rule with ID
75a0060762034a6cb663fd51a02344cb
disabling the rule. - A tag override for the
wordpress
tag, setting the action of all the rules with this tag tojs_challenge
.
The following configuration includes the three overrides in the rule that executes the Cloudflare Managed Ruleset:
This example enables payload logging for matched rules of the Cloudflare Managed Ruleset, setting the public key used to encrypt the logged payload.
Building upon the rule that deploys the Cloudflare Managed Ruleset, the following rule configuration adds the matched_data
object with the public key used to encrypt the payload:
The OWASP managed ruleset supports the following configurations:
-
Enable all the rules up to a specific paranoia level by creating tag overrides that disable all the rules associated with higher paranoia levels.
-
Set the action to perform when the calculated threat score is greater than the score threshold by creating a rule override for the last rule in the Cloudflare OWASP Core Ruleset (rule with ID
...843b323c
), and including theaction
property. -
Set the score threshold by creating a rule override for the last rule in the Cloudflare OWASP Core Ruleset (rule with ID
...843b323c
), and including thescore_threshold
property.
For more information on the available configuration values, refer to the Cloudflare OWASP Core Ruleset page in the WAF documentation.
The following example rule of a cloudflare_ruleset
Terraform resource performs the following configuration:
- Deploys the OWASP managed ruleset.
- Sets the OWASP paranoia level to PL2.
- Sets the score threshold to
60
(Low). - Sets the ruleset action to
log
.