How-To

Cloudflare Access Service Tokens for Authorized Automation

A Cloudflare Access service token can authenticate an automated client to an application when its owner has configured a matching Service Auth policy. It is a credential for a specific access arrangement, not a way around an unrelated site's protections.

Start with the application owner

The administrator creates a service token and configures the Access application to accept it. Cloudflare describes the token as a client ID and client secret in its service-token documentation. The token only works where the relevant policy permits it; ask the administrator which application and environment the automation may use.

Use the documented Service Auth policy action for the intended application. A valid credential alone doesn't prove the application grants it access. Test with a non-production service and a narrowly scoped identity before adding it to a scheduled task.

Send and protect both values

Cloudflare documents the default CF-Access-Client-Id and CF-Access-Client-Secret request headers. Its documentation also describes an optional single-header configuration. Follow the administrator's actual policy and the current documentation instead of assuming that a cookie issued in one configuration will work in another.

Put the secret in an approved secret store. Don't paste it into a source repository, ticket, screenshot or debug log. Use different credentials for development and production when possible, restrict who can read them, and plan how to rotate and revoke them. A log containing request headers needs explicit redaction.

Check the failure, not just the status

A 401 or 403 can reflect a bad or expired token, a policy mismatch or a separate application restriction. A redirect to a login page can also indicate that the intended service policy wasn't applied. Cloudflare's behavior depends on its strict service-token authentication setting, so inspect the response and the administrator's Access logs before changing a policy. Avoid logging the credential while debugging.

Access authentication is distinct from application authorization and from other controls protecting an endpoint. If your service account can authenticate but the app denies an operation, resolve the app's permissions with its owner. Cloudflare's Access policy guide explains the policy actions.

Example: default request headers

CF-Access-Client-Id: <CLIENT_ID>
CF-Access-Client-Secret: <CLIENT_SECRET>

The application owner supplies both values; these placeholders are not credentials. In organizations with strict service-token authentication enabled, failed authorization returns 401 or 403, successful authentication does not issue an Access cookie, and subsequent requests continue to send the token headers. Treat the application response separately from Access authorization.

If you need help planning an authorized automation workflow, ask for a scoped assessment. Share the documented limits and a redacted example, without credentials or private data.