Deploy a managed ruleset
You can deploy a managed ruleset at the zone level or at the account level.
To deploy a managed ruleset to a phase, use the Rulesets API.
Use the following workflow to deploy a managed ruleset to a phase at the zone level.
- Get your zone ID.
- Invoke the List account rulesets operation to obtain the available managed rulesets. Managed rulesets exist at the account level, but you can deploy them to a zone. Find the ruleset ID of the managed ruleset you want to deploy.
- Identify the phase where you want to deploy the managed ruleset. Ensure that the managed ruleset belongs to the same phase where you want to deploy it. To learn more about the available phases supported by each Cloudflare product, refer to the specific documentation for that product, or the Phases list.
- Add a rule to the zone-level phase entry point ruleset that executes the managed ruleset. Refer to the following example for details on this step.
The following example deploys a WAF managed ruleset to the http_request_firewall_managed
phase of a given zone ({zone_id}
) by creating a rule that executes the managed ruleset.
-
Invoke the Get a zone entry point ruleset operation to obtain the definition of the entry point ruleset for the
http_request_firewall_managed
phase. You will need the zone ID for this task. -
If the entry point ruleset already exists (that is, if you received a
200 OK
status code and the ruleset definition), take note of the ruleset ID in the response. Then, invoke the Create a zone ruleset rule operation to add anexecute
rule to the existing ruleset deploying the Cloudflare Managed Ruleset (with IDefb7b8c949ac4650a09736fc376e9aee
). By default, the rule will be added at the end of the list of rules already in the ruleset. -
If the entry point ruleset does not exist (that is, if you received a
404 Not Found
status code in step 1), create it using the Create a zone ruleset operation. Include a single rule in therules
array that executes the Cloudflare Managed Ruleset (with IDefb7b8c949ac4650a09736fc376e9aee
) for all incoming requests in the zone.
In this example, the managed ruleset executes the behavior configured by Cloudflare. To customize the behavior of managed rulesets, refer to Override a managed ruleset.
Use the following workflow to deploy a managed ruleset to a phase at the account level.
- Get your account ID.
- Invoke the List account rulesets operation to obtain the available managed rulesets. Find the ruleset ID of the managed ruleset you want to deploy.
- Identify the phase where you want to deploy the managed ruleset. Ensure that the managed ruleset belongs to the same phase where you want to deploy it. To learn more about the available phases supported by each Cloudflare product, refer to the specific documentation for that product, or the Phases list.
- Add a rule to the account-level phase entry point ruleset that executes the managed ruleset. Use parentheses to enclose any custom conditions in the rule expression and end your expression with
and cf.zone.plan eq "ENT"
so that it only applies to zones on an Enterprise plan. Refer to the following example for details on this step.
The following example deploys a WAF managed ruleset to the http_request_firewall_managed
phase of a given account ({account_id}
) by creating a rule that executes the managed ruleset. The rules in the managed ruleset are executed when the zone name matches one of example.com
or anotherexample.com
.
-
Invoke the Get an account entry point ruleset operation to obtain the definition of the entry point ruleset for the
http_request_firewall_managed
phase. You will need the account ID for this task. -
If the entry point ruleset already exists (that is, if you received a
200 OK
status code and the ruleset definition), take note of the ruleset ID in the response. Then, invoke the Create an account ruleset rule operation to add anexecute
rule to the existing ruleset deploying the Cloudflare Managed Ruleset (with IDefb7b8c949ac4650a09736fc376e9aee
). By default, the rule will be added at the end of the list of rules already in the ruleset. -
If the entry point ruleset does not exist (that is, if you received a
404 Not Found
status code in step 1), create it using the Create an account ruleset operation. Include a single rule in therules
array that executes the Cloudflare Managed Ruleset (with IDefb7b8c949ac4650a09736fc376e9aee
) for all incoming requests where the zone name matches one ofexample.com
oranotherexample.com
.
In this example, the managed ruleset executes the behavior configured by Cloudflare. To customize the behavior of managed rulesets, refer to Override a managed ruleset.