This guide explains exactly what Cloudflare secrets you need and how to get them for deploying your MD-Book project.
What it does:
- Authenticates your deployment scripts with Cloudflare's API
- Allows GitHub Actions to deploy to Cloudflare Pages
- Enables worker deployments and configuration updates
Required Permissions:
Cloudflare Pages:Edit- Deploy and manage Pages projectsZone:Read- Read DNS and domain informationAccount:Read- Access account-level resources
How to Get It:
-
Go to Cloudflare API Tokens page: Visit: https://dash.cloudflare.com/profile/api-tokens
-
Create Custom Token:
- Click "Create Token"
- Select "Custom token" (not pre-made templates)
-
Set Permissions:
Account - Cloudflare Pages:Edit - [Your Account] Zone - Zone:Read - All zones (or specific zones) Account - Account:Read - [Your Account] -
Add Restrictions (Optional but Recommended):
- Account resources: Select your specific account
- Zone resources: Select specific zones if you don't want all zones
- Client IP: Add your deployment server IPs for extra security
- TTL: Set expiration date (90 days recommended)
-
Create and Copy Token:
- Click "Continue to summary" → "Create Token"
⚠️ IMPORTANT: Copy the token immediately - you won't see it again!- Token format:
1234567890abcdef1234567890abcdef12345678
What it does:
- Identifies which Cloudflare account to deploy resources to
- Required for creating Pages projects and Workers
- Links deployments to the correct billing account
How to Get It:
-
Go to Cloudflare Dashboard: Visit: https://dash.cloudflare.com/
-
Find Account ID:
- On any page, look at the right sidebar
- Under "Account" section, you'll see "Account ID"
- Format:
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
-
Copy the Value:
- Click the copy icon next to the Account ID
- It's a 32-character hex string
- Go to your GitHub repository
- Navigate to Settings → Secrets and variables → Actions
- Add Repository Secrets:
- Click "New repository secret"
- Name:
CLOUDFLARE_API_TOKEN - Value: [Paste your API token]
- Click "Add secret"
- Repeat for
CLOUDFLARE_ACCOUNT_ID
export CLOUDFLARE_API_TOKEN="your-api-token-here"
export CLOUDFLARE_ACCOUNT_ID="your-account-id-here"# Copy the template
cp .env.example .env
# Edit .env file
echo "CLOUDFLARE_API_TOKEN=your-api-token-here" >> .env
echo "CLOUDFLARE_ACCOUNT_ID=your-account-id-here" >> .env.env file to git - it's already in .gitignore
Test that your secrets work:
# Test API token
curl -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/user/tokens/verify"
# Test account access
curl -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID"Both should return successful responses with account information.
- Rotate regularly: Create new tokens every 90 days
- Minimal permissions: Only grant required permissions
- Monitor usage: Check token activity in Cloudflare dashboard
- Revoke unused: Delete old tokens when no longer needed
- Repository secrets: Only repository admins can view/edit secrets
- Environment restrictions: Use different tokens for staging vs production
- IP restrictions: Limit tokens to specific IPs when possible
- Audit logs: Monitor API token usage in Cloudflare dashboard
"Authentication failed"
- Check that
CLOUDFLARE_API_TOKENis correct - Verify token hasn't expired
- Ensure token has required permissions
"Account not found"
- Check that
CLOUDFLARE_ACCOUNT_IDis correct (32-character hex string) - Verify you have access to the account
- Make sure account ID matches the token's account
"Permission denied"
- Token needs
Cloudflare Pages:Editpermission - Add
Account:ReadandZone:Readpermissions - Check if token is restricted to specific zones
# Verify token
wrangler whoami
# List accounts
curl -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts"
# Test Pages access
curl -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects"When you deploy, these secrets are used to:
- Authenticate with Cloudflare API
- Create/update Pages project in your account
- Upload static files (HTML, CSS, JS, images)
- Configure caching rules and security headers
- Deploy Worker functions (if enabled)
- Set up custom domains (if configured)
- Generate deployment URLs for preview/production
The entire process is automated and secure - secrets never appear in logs or output.