Skip to Content
mlab docs

Cloudflare

Connect a Cloudflare account to mlab.sh with a read-only API token: active zones and their DNS names, synced every day.

The Cloudflare connector reads your zones and DNS records through the Cloudflare API. Cloudflare has no page where you approve a third-party application, so you create a read-only API token and paste it in mlab.sh. mlab.sh then checks the token only reads, and refuses it otherwise.

Before you start

  • You need a Cloudflare user that can see the zones to monitor.
  • In mlab.sh, you need to be owner or admin of the organization, on the Team or Enterprise plan.
  • One token is one connection. Zones in several Cloudflare accounts? A token can cover all the accounts your user belongs to, or connect each one separately.

Create the token

Open the API tokens page

In the Cloudflare dashboard, open My Profile → API Tokens and click Create Token. At the bottom, next to Custom token, click Get started.

Name it and give it two read-only policies

Name the token mlab.sh (you will look for that name to delete it). Under Policies, add:

PolicyResourcesPermissions
Zone policyInclude → All zones (or the zones to monitor)Zone Read, DNS Read
User policyYour userAPI Tokens Read

When you are done, the token lists exactly these two policies and nothing else.

The two policies of a valid mlab.sh token: a User policy with API Tokens Read, and a Zone policy on all zones with DNS Read and Zone Read

API Tokens Read lets mlab.sh read this token's own permissions, so it can prove the token only reads. It shows the names and permissions of your tokens, never their values. Without it, mlab.sh refuses the token.

Choose the zones

All zones monitors everything, including zones added later. To limit it, pick specific zones in the Zone policy: a zone left out is simply not synced.

Create it and copy it

Leave TTL empty for monitoring (a token that expires stops the syncs). Click Continue to summary, then Create Token, and copy the token. Cloudflare shows it only once.

Connect it in mlab.sh

Paste the token

In Inventory → Connections, click Connect an account, choose Cloudflare, give the connection a name if you have several accounts, paste the token, and click Connect Cloudflare.

Checked, then synced

mlab.sh checks the token is active and that every permission it holds is a Read permission. If one of them allows more (Edit, Write...), the token is refused and nothing is kept. Once accepted, the connection is Active and the first sync starts within a minute.

What is synced

CloudflareIn mlab.sh
Active zonesDomain (DNS zone), proven yours: an active zone is delegated to Cloudflare
A, AAAA, CNAME recordsThe zone's Subdomains, with their records and whether they are proxied

Pending zones (not delegated to Cloudflare yet) are not synced: they prove nothing about who holds the domain. The addresses your records point to are not added as your IPs, since a name can point to a shared host.

The sync runs every 24 hours. In the connection page, Sync now starts one within a minute.

Troubleshooting

What mlab.sh showsWhat to do
the token needs the API Tokens Read permissionEdit the token in Cloudflare and add User · API Tokens · Read, then connect again.
the Cloudflare token allows ... Edit (or Write)The token can change something. Create a new token with the three Read permissions only.
the Cloudflare token is expired (or disabled)Create a new token without TTL, disconnect the old connection and connect the new token.
Cloudflare 403 ... Authentication error during a syncThe token was deleted or rolled in Cloudflare. Disconnect and connect a new token.

Revoke

A read-only token cannot delete itself, so Disconnect in mlab.sh deletes the token on our side and stops the syncs, and says the provider did not confirm. Delete the token in Cloudflare too: My Profile → API Tokens, the mlab.sh token, Delete. That is the step that makes it unusable everywhere.

On this page