Skip to main content

Connecting Cloudflare to Bicycle

Learn how to create a read-only Cloudflare API token and connect your Cloudflare account to Bicycle.

Once connected, Bicycle can use Cloudflare as a source of evidence when it investigates a change in your metrics. It can look at traffic and error analytics, DNS records, Workers observability, audit logs, and recent configuration changes.

Requirements​

To follow the steps in this guide, you'll need:

  • Permission to create connectors in Bicycle
  • A Cloudflare account that owns the zones and Workers you want Bicycle to investigate
  • Permission in Cloudflare to create API tokens
Official Cloudflare documentation
Use a read-only token

Bicycle only needs read access to investigate causes. Cloudflare's execute tool can call any API endpoint that the token allows, including endpoints that change or delete resources. Grant read-only permissions so that nothing in your Cloudflare configuration can be changed through the connector.

In Cloudflare​

Open API Tokens

Log in to the Cloudflare dashboard.

  • For a token that belongs to you, go to My Profile > API Tokens.
  • For a token that is not tied to one user, go to Manage Account > Account API Tokens.

Click Create Token.

Choose the permissions

Start from the Read all resources template. It grants read access to everything in the account and nothing that edits.

If you prefer a narrower token, start from Start from scratch and add Read permissions for the data you want investigated, for example:

  • Account Analytics
  • Account Settings
  • Workers Scripts
  • Workers Observability
  • Audit Logs
  • Zone
  • DNS
  • Analytics and Logs for your zones

Choose the account and zones

Set Account Resources to your account. Set Zone Resources to the zones you want Bicycle to look at, or to all zones.

Set an expiry that matches your token rotation policy.

Create and copy the token

Click Continue to summary, then Create Token. Copy the token straight away. Cloudflare shows it only once.

In Bicycle​

Open Connectors and select Cloudflare

In Bicycle, go to Connectors. Find Cloudflare and click + Connect.

Name the connection

Enter a connection name that identifies the account, such as Cloudflare Production.

Paste the API token

Paste the token you copied from Cloudflare.

API TokenRequired

A Cloudflare user or account API token with read-only permissions

Test the connection

Click Test connection. Bicycle checks that Cloudflare accepts the token. When the test succeeds, you will see Connection verified successfully.

The test confirms that the token is valid. It does not check that the token has access to every product you want to investigate.

Save the connection

Click Save connection. When the connection is created, you will see Connection successfully added! with the connection name and ID. Click Close to return to the Connectors page.

What Bicycle can do with Cloudflare​

After you save the connection, these tools become available when Bicycle investigates a cause.

ToolWhat it does
cloudflare-whoamiReturns the Cloudflare user or account the connection is signed in as
cloudflare-docsSearches the Cloudflare documentation
cloudflare-searchSearches the Cloudflare API specification to find the right endpoint and its response format
cloudflare-executeRuns a call against the Cloudflare API and returns the result. It can only do what the token's permissions allow.

Troubleshooting​

If Test connection fails, or results come back empty, check the following.

Error or symptomLikely causeFix
Authentication failedThe token is invalid, expired or was revokedCreate a new token in Cloudflare and paste the new value
Token does not have sufficient permissionsThe token lacks a permission for the data being readAdd the missing Read permission to the token, or create a new one
Test passes but a result is a permission errorThe token is valid but does not cover that product, account or zoneEdit the token's permissions and Account Resources or Zone Resources in Cloudflare
Empty resultsThe account or zone has no recent traffic, or the token's resources do not include itCheck that the zone is included in the token's Zone Resources

References​