Add-ons
Posted By Nick —

Configuring Cloudflare zones


The Cloudflare add-on for WP Cerber can keep its IP Access Rules in the Cloudflare zone of your website. We recommend this setup. Enter the Zone ID of the website in the add-on settings, and every rule the add-on creates applies to that zone only.

While the Zone ID is empty, the add-on creates user-level rules instead. A user-level rule applies to every zone owned by the Cloudflare user the add-on’s credentials belong to, so a lockout on one website blocks the address on all of that user’s websites, and an allowed address is allowed on all of them.

Limiting the rules to one zone isolates your websites from each other. It does not raise the number of rules Cloudflare allows. If you run several websites under one Cloudflare user and rely on a lockout on one of them protecting the others, leave the Zone ID empty.

New and existing installations

On a new installation, enter the Zone ID together with the credentials, before you enable any synchronization option. The add-on has no rules yet, so there is nothing to move, and the API Token needs the permission for the zone only.

On an existing installation, the add-on already has user-level rules. Entering the Zone ID moves them: the add-on deletes the user-level rules and creates them again in the zone. Until the move has completed, the website has no Cloudflare rules from the add-on, while WP Cerber keeps enforcing its lockouts and IP Access Lists on the WordPress server. Treat the move as a step of its own:

  1. Update the add-on and confirm that synchronization works as before.
  2. Give the API Token the permissions for both scopes, as described in Prepare the API Token.
  3. Enter the Zone ID at a time when you can follow the Diagnostic Log, and wait until it records the end of the move.

Nothing obliges you to move. An installation that keeps the Zone ID empty works as it did before the update.

If the add-on settings page has no Cloudflare Zone section, your version of the add-on does not support zones. Update the add-on before following the steps below.

Find the Zone ID

  1. Log in to the Cloudflare dashboard and select the account and the domain of your website.
  2. On the Overview page of the domain, find the API section.
  3. Copy the Zone ID shown there.

Prepare the API Token

The permission the API Token needs depends on where the rules live:

Rules API Token permission
User level, Zone ID empty Account, Account Firewall Access Rules, Edit, with the account included under Account Resources
One zone Zone, Firewall Services, Edit, with the zone of the website included under Zone Resources

On an installation that already has rules, setting, changing, or clearing the Zone ID moves them from one scope to the other. The add-on deletes the rules in the old scope and creates them again in the new one, so the token needs both permissions until the move has completed. Change the permissions in this order:

  1. In the Cloudflare dashboard, edit the token and add the permission for the new scope. Keep the permission the token already has.
  2. Enter or clear the Zone ID in the add-on settings, as described below.
  3. Wait until the move has completed. The Diagnostic Log records it, as described in the next section.
  4. Edit the token again and remove the permission for the old scope, if you no longer need it.

If you remove the permission for the old scope before the move has completed, the move stops and the add-on creates no new rules until you restore it. See The move does not complete.

A token created on the Account API Tokens page of your Cloudflare account can be used in place of a token from your profile, with the same permissions.

The Global API Key has no permissions to adjust. It covers both scopes, provided its Cloudflare user has access to the zone.

Enter the Zone ID

Open WP Cerber → Add-ons → Cloudflare, paste the Zone ID into the Zone ID field of the Cloudflare Zone section, and save the settings. To return to user-level rules, clear the field and save the settings again.

When you save the settings, the add-on checks that its credentials can manage IP Access Rules in the configured scope by creating and deleting a temporary rule there. A successful check is confirmed with a message such as “The Cloudflare API Token is valid and can manage IP Access Rules in the Cloudflare zone …”. A failed check shows a notice that names the scope and the reason Cloudflare gave.

The check covers the configured scope only. While a move is pending, a successful check does not confirm that the token can still delete the rules in the old scope. The move checks that separately when it starts.

A value that is not a Zone ID is rejected with a notice and never sent to Cloudflare. The add-on does not fall back to user-level rules in that case, and it creates no rules until you correct the value.

What happens when you change the Zone ID

Cloudflare does not provide an API operation for moving an existing IP Access Rule between scopes, and a rule can be deleted only through the scope that created it. Changing the Zone ID therefore replaces the whole rule set:

  1. The add-on verifies that its credentials can manage rules in the new scope. It does so even when there are no rules to delete, so that it never switches to a scope it cannot write to.
  2. If rules exist in the old scope, it verifies that its credentials can still manage them.
  3. It deletes every rule it has created in the old scope.
  4. It records the new scope and creates the rules again there, based on the lockouts and IP Access List entries WP Cerber holds at that moment and on the synchronization options you have enabled.

If either verification fails, the add-on deletes nothing and leaves the existing rules in place. It reports the failure in the WordPress admin area when the move runs while you work in the dashboard, and in the Diagnostic Log if logging is enabled.

The move starts with the next event the add-on handles, such as a lockout or an IP Access List change, rather than at the moment you save the settings. It runs in batches. A run lasts up to 15 seconds, and the next one starts with a later event, no sooner than 30 seconds after the previous run started. The move therefore takes longer on a website with many rules or few events.

Until the move has completed, the add-on creates no new Cloudflare rules, and between the deletion and the re-creation your website has no Cloudflare rules from the add-on at all. WP Cerber keeps enforcing its lockouts and IP Access Lists on the WordPress server throughout.

The re-creation covers every supported IP Access List entry while IP Access List syncing is enabled, including entries that were added before you enabled the option.

To follow the move, turn on Enable diagnostic logging and review WP Cerber → Tools → Diagnostic Log. These entries mark its progress:

  • “Rebuilding the Cloudflare rule set: replacing the rules at user level with rules in the Cloudflare zone …” starts a run of the move.
  • “Rebuild suspended, …” ends a run before the move has completed and names the cause, either the time limit of the run or an error logged just above it.
  • “The Cloudflare rule set now lives in the Cloudflare zone …” means the old rules are gone and the new scope is recorded.
  • “Rebuilding the Cloudflare rule set has been completed, its rules live in the Cloudflare zone …” means the rules have been created again and the move is over.

Why the Zone ID field may be disabled

Versions 1.3 and older of the add-on stored their rules in a format that later versions clean up automatically. Until that cleanup has completed, the Zone ID field is disabled and its description explains why. The cleanup runs after the next lockout or IP Access List change, provided working Cloudflare credentials are saved, and the field becomes available once it has completed.

If the field stays disabled, the cleanup is not running or cannot delete the old rules. Save the add-on settings to rerun the credential check and correct the credentials if it fails. Then trigger an event yourself by adding an IP Access List entry and removing it, and review the Diagnostic Log for rejected Cloudflare operations.

Multisite networks

On a WordPress multisite network, WP Cerber keeps one set of lockouts and IP Access Lists for the whole network, and the add-on settings apply to the whole network as well. One Zone ID therefore covers every site, and all sites of the network must be served by that zone:

  • A subdirectory network, such as example.com/shop/, fits one zone.
  • A subdomain network under one domain, such as shop.example.com, fits one zone.
  • A network whose sites use domains of their own, known as mapped domains, spans several zones. Leave the Zone ID empty on such a network. Otherwise, the sites outside the configured zone get no Cloudflare rules, and nothing warns you about it.

The add-on does not check which sites the configured zone serves.

Deleting the rules on deactivation

When Delete Cloudflare rules on deactivation is enabled, deactivating the add-on deletes its rules from the scope they currently live in, whether that is a zone or user level.

When you activate the add-on again with a Zone ID configured, the next event creates the whole rule set again in that zone. With user-level rules, reactivation recreates nothing, and rules appear again only for new lockouts and IP Access List changes.

Troubleshooting

Authentication error (code 10000)

Cloudflare answers with this error when it refuses a request, and it does not say why. When the add-on receives it, it adds a sentence that names the scope of the refused request, for example “The Cloudflare API Token may lack the permission to manage the IP Access Rules in the Cloudflare zone …”. Cloudflare returns the same error for several other causes, which is why the sentence says “may”. Check that:

  • the token has the permission for the scope the notice names, as listed in Prepare the API Token
  • for a zone, the zone of the website is included under Zone Resources of the token
  • the Zone ID belongs to your website’s domain, in an account the token has access to
  • the token is active and has not expired
  • the Client IP Address Filtering of the token, if you set it, includes the public IP address of your server

With the Global API Key, the error most likely means that its Cloudflare user has no access to the scope the notice names.

The move does not complete

No new Cloudflare rules appear, the Diagnostic Log repeats “Rebuild suspended, the rules at user level are not replaced yet”, and a notice says “Unable to verify that the Cloudflare credentials can manage IP Access Rules at user level, where the existing Cloudflare rules live”.

The token can no longer manage the rules in the old scope, usually because the permission for that scope was removed before the move completed. Add the permission back to the token. The next event completes the move, and you can remove the permission afterwards.

The add-on never discards its records of rules it cannot delete. The rules would stay in Cloudflare with nothing tracking them. Allow rules can bypass several Cloudflare security controls, including WAF and rate limiting rules.

If you cannot restore the permission, abandon the old rules deliberately:

  1. Enable Delete Cloudflare rules on deactivation and save the settings.
  2. Deactivate the add-on on the WordPress Plugins page, then activate it again. The deletions fail, but the add-on discards its records of the old rules, and the move completes with the next event.
  3. Delete the old rules in the Cloudflare dashboard. Their notes start with “Blocked by WP Cerber” or “Whitelisted by WP Cerber”.

The move takes a long time

The Diagnostic Log repeats “Rebuild suspended, …” followed by “the time limit of 15 s per run has been reached”, and the entries that mark the end of the move do not appear yet.

On a website with many rules, this is how a move normally proceeds. A run starts no new Cloudflare request once it has worked for 15 seconds, and the next event continues from where it stopped. A request that is already in flight is allowed to finish, so a run can last somewhat longer. The add-on keeps its records of the rules throughout, and no rule is left untracked.

To tell whether the move advances, look at the entries between two “Rebuild suspended” entries. “Deleted rule …” and “Added … rule …” entries mean that the run made progress, and further events will complete the move.

If a run logs only “Access to the IP Access Rules … has been verified” before it is suspended, the move is not advancing. Until the rules of the old scope are deleted, every run first verifies its access to both scopes, which takes four Cloudflare requests. When the Cloudflare API responds very slowly, these requests can use up the whole run, and every later run repeats them. More events do not help in that case. Wait until the Cloudflare API responds normally again and then trigger an event.

The WordPress admin area does not show the progress of a move. The Diagnostic Log is the only place to follow it.

On a website with few events, the move waits for the next one. To continue it yourself, add an IP Access List entry and remove it, leaving at least 30 seconds between attempts. Choose an address that will not affect your own access to WordPress.

A rule for 10.254.254.254 stays in Cloudflare

The add-on verifies its access by creating a temporary Allow rule for 10.254.254.254 and deleting it right away. The address is private, so the rule affects no real visitor. The verification runs when you save the settings, when a move starts, and when Cloudflare reports a rule as missing.

If deleting the temporary rule fails, it stays in Cloudflare, and every later verification in that scope fails, because Cloudflare rejects a second rule for the same address. Delete the rule in the Cloudflare dashboard and save the add-on settings again.

Before downgrading the add-on

Versions of the add-on without zone support manage user-level rules only. After a downgrade with the rules in a zone, the older version tries to delete them through the user-level endpoint. Cloudflare has no such rule there, so the rule stays in the zone, and the older version can neither remove it nor create a new rule for its address.

Before downgrading, clear the Zone ID, save the settings, and wait until the move back to user level has completed. The Diagnostic Log records it, and the IP Access Rules of the zone no longer list rules created by WP Cerber.

Versions older than 3.0 also authenticate with the Global API Key only. If the add-on uses an API Token, enter the email address of your Cloudflare account and its Global API Key before downgrading, clear the token field, and save the settings to confirm that the credential check passes with the key. This applies whether or not a Zone ID is entered. Use the key of the same Cloudflare user the token belongs to.

Cloudflare references

Have any questions?

If you have a question regarding WordPress security or WP Cerber, ask it in the comments below or find answers on the community forum.

Spotted a bug or glitch?

We’d love to fix it! Share your bug discoveries with us here: Bug Report.


I'm a software engineer and team lead at Cerber Tech. I started coding in 1993 on IBM System/370 and today software engineering at Cerber Tech is how I make my living.

View Comments
There are currently no comments.