Welcome Guest to Defaut site!

Cloudflare API Token Guide

Table of Contents

Overview

This guide explains how to create a Cloudflare API token with the correct permissions for use with the Comserv2 application.

Issue

The current API token has IP address restrictions and cannot be used from the server where Comserv2 is running. This results in 403 Forbidden errors with the message "Cannot use the access token from location: [IP address]".

Solution

Create a new Cloudflare API token without IP restrictions and with the correct permissions.

Steps to Create a New API Token

  1. Log in to your Cloudflare account at https://dash.cloudflare.com/
  2. Click on your profile icon in the top right corner and select "My Profile"
  3. In the left sidebar, click on "API Tokens"
  4. Click the "Create Token" button
  5. You can either:
    • Select the "Edit zone DNS" template, or
    • Create a custom token with the following permissions:

Custom Token Permissions

If creating a custom token, use these settings:

Token name: Comserv2 DNS Management

Permissions:

  • Zone > DNS > Edit
  • Zone > Zone > Read
  • Zone > SSL and Certificates > Read (optional)
  • Zone > Cache Purge > Purge (optional)

Zone Resources:

  • Include > Specific zone > computersystemconsulting.ca
  • Include > Specific zone > beemaster.ca
  • (Add any other domains you need to manage)

Client IP Address Filtering:

  • Leave this section blank to allow access from any IP address
  1. Click "Continue to summary" and review the permissions
  2. Click "Create Token"
  3. Copy the generated token (you will only see it once)

Updating the Configuration

After creating the new token, update the cloudflare_config.json file with the new token:

{
  "cloudflare": {
    "api_token": "your-new-token-here",
    "email": "[email protected]",
    "application_id": "comserv2"
  },
  ...
}
        

Testing the New Token

You can test the new token using the provided test script:

perl /home/shanta/PycharmProjects/comserv2/Comserv/script/test_cloudflare_domain.pl
        

This script will verify that the token is valid and has the correct permissions to access your domains.

Troubleshooting

If you continue to experience issues with the new token:

  1. Verify that the token has the correct permissions
  2. Check that there are no IP restrictions on the token
  3. Ensure the token is active and has not expired
  4. Check the Cloudflare API status at https://www.cloudflarestatus.com/

For more information on Cloudflare API tokens, see the Cloudflare API documentation.