Service Token Authentication, Rotation, and Lifecycle
How Cloudflare Access service tokens authenticate machines, strict mode, secret rotation, disable, and inactive cleanup.
This page summarises Cloudflare documentation on Cloudflare Access service tokens: static Client ID and Client Secret pairs for automated systems (CI/CD, monitoring, coding agents, backend APIs) to reach applications protected by Cloudflare Access without an identity-provider login. It also covers recent organisation settings for strict service token authentication, secret rotation grace periods, temporary disable, inactive token cleanup, and the scannable cfast_ secret format.
Service tokens: what they are and when to use them
Section titled “Service tokens: what they are and when to use them”Service tokens are non-interactive credentials for machine-to-machine access. Cloudflare Access issues a Client ID and Client Secret; callers send them on each HTTP request. Automated workflows with no user present should use service tokens rather than browser login flows.
You can provide automated systems with service tokens to authenticate against your Cloudflare One policies. Cloudflare Access will generate service tokens that consist of a Client ID and a Client Secret. Automated systems or applications can then use these values to reach an application protected by Access.
— Cloudflare, Service tokens
Service Auth policies (not Allow policies) authorize those requests. You can add constraints such as IP ranges so the token only works from known infrastructure.
Automated services such as CI/CD pipelines, monitoring systems, and backend APIs need to access protected applications without an interactive login. Service Auth policies allow machine-to-machine communication by authenticating requests that present valid service token headers.
— Cloudflare, Authenticate a service using a service token
| Approach | Best for | Credentials |
|---|---|---|
| Service token headers | Unattended automation, agents, APIs | CF-Access-Client-Id, CF-Access-Client-Secret (or a single configured header) |
cloudflared access login / cf-access-token |
CLI or agents where a user can sign in once per session | Session token tied to user identity and app session duration |
cloudflared access curl |
Quick CLI calls with automatic token handling | Handled by cloudflared; first session may open a browser |
The Connect through Cloudflare Access using a CLI walkthrough is aimed at end users interacting with an API from the command line, not at long-running services. For agents that use their own HTTP client, Authenticate coding agents documents cloudflared access curl, reusable session tokens, and service tokens.
HTTP headers: how service token authentication works
Section titled “HTTP headers: how service token authentication works”Service token authentication adds two headers to every request:
To authenticate to an Access application using your service token, add the following to the headers of any HTTP request:
CF-Access-Client-Id: <CLIENT_ID>
CF-Access-Client-Secret: <CLIENT_SECRET>
— Cloudflare, Service tokens
Example:
curl -H "CF-Access-Client-Id: $CF_ACCESS_CLIENT_ID" \ -H "CF-Access-Client-Secret: $CF_ACCESS_CLIENT_SECRET" \ https://app.example.com/apiService Auth policy: include the token on the application
Section titled “Service Auth policy: include the token on the application”Create the token first, then attach a Service Auth rule that Includes your Service Token. For coding agents, the same pattern appears in Authenticate coding agents:
| Action | Rule type | Selector | Value |
|---|---|---|---|
| Service Auth | Include | Service Token | Your token name |
Store Client ID and Client Secret where the automation can read them (secret manager, not source control).
Single custom header (SaaS or one-header limits)
Section titled “Single custom header (SaaS or one-header limits)”Some upstream services allow only one custom header (for example Authorization). You can set read_service_tokens_from_header on a self-hosted application via the Service tokens API and send a JSON object in that header with cf-access-client-id and cf-access-client-secret.
Strict service token authentication: API behavior without login redirects
Section titled “Strict service token authentication: API behavior without login redirects”Strict service token authentication is a Zero Trust organisation setting that normalises how Cloudflare Access treats requests that already carry service token headers.
The strict service token authentication setting applies consistent behavior to requests made with service tokens. When the setting is on for a Zero Trust organization, Access handles requests with service token headers as follows:
If authentication or authorization fails, Access always returns 401 or 403 instead of redirecting the client to the login page with 302. Only Service Auth policies can authorize the request. Access ignores Allow policies and any CF_Authorization cookie sent with the request. Access does not return a CF_Authorization cookie to the client after successful authentication. Subsequent requests should continue to use service token headers. Failed requests for recognized service tokens appear in Access authentication logs.
— Cloudflare, New strict service token authentication setting for Access
The Service tokens page adds logging detail: Access logs expired or disabled tokens, wrong secrets, and tokens not authorised for the app; it does not log malformed headers or unknown Client IDs.
Defaults and control:
- Organisations created on or after 2026-10-05 have strict mode on by default and cannot turn it off.
- Older organisations can enable or disable it in Zero Trust → Access controls → Access settings → Manage service tokens, or set
strict_service_token_authvia the Access changelog API example (PATCH…/access/organizations).
Cloudflare recommends existing organisations enable strict mode so API clients get 401/403 instead of 302 to a login page—a common cause of “silent” automation failures.
Related but separate: Session management describes Return 401 response for non-browser traffic for failed Cloudflare One Client auth (warp_auth_non_browser_401), which is not the same as per-application Service Auth redirect behaviour (service_auth_401_redirect).
Client Secret format: cfast_ prefix and checksum
Section titled “Client Secret format: cfast_ prefix and checksum”New secrets created on or after 2026-08-26 use a scannable format:
Cloudflare Access service token Client Secrets created on or after August 26, 2026, use the format cfast_[40 alphanumeric characters][8-character checksum]. The prefix and checksum make these credentials easier for secret scanning tools to identify with fewer false positives.
Existing service token secrets continue to work and do not require rotation. Both formats use the same Client ID and the same CF-Access-Client-Id and CF-Access-Client-Secret authentication headers.
— Cloudflare, Access service token secrets use a scannable format
Rotation is not required solely because the format changed.
Rotate service token secrets: grace periods and API timing
Section titled “Rotate service token secrets: grace periods and API timing”Rotate when you suspect exposure or on a schedule. The Client ID stays the same; Access issues a new Client Secret.
Cloudflare Access administrators can now choose a grace period when rotating a service token secret. Both secrets remain valid during the grace period, giving administrators time to update services without interrupting authentication.
The dashboard offers grace periods from one hour to 30 days. Administrators can also revoke the previous secret immediately. The API accepts an RFC 3339 expiration time for custom rotation schedules.
— Cloudflare, Grace periods for service token rotation
Dashboard path: Zero Trust → Access controls → Service credentials → Service Tokens → Rotate secret. API: POST … /access/service_tokens/$SERVICE_TOKEN_ID/rotate with optional previous_client_secret_expires_at (Service tokens). Omit that field to revoke the old secret immediately.
Turn a service token off: pause without deleting
Section titled “Turn a service token off: pause without deleting”Disable blocks authentication but keeps configuration for re-enable later.
Cloudflare Access administrators can now temporarily turn off service tokens without deleting them. A disabled token cannot authenticate, but its configuration remains available so administrators can turn it on again later.
Turning off a token also stops any previous secret in an active rotation grace period. Use this control to contain suspected credential exposure or pause an automated service.
— Cloudflare, Temporarily turn off Access service tokens
Use Disable token in the dashboard or enabled: false on Update a service token. This is faster than delete when you may resume the same integration.
Inactive service tokens: automatic disable or delete
Section titled “Inactive service tokens: automatic disable or delete”Organisation-wide cleanup reduces abandoned credentials.
Cloudflare Access administrators can now automatically disable or delete inactive service tokens. Administrators can set an inactivity period from 30 to 365 days and choose what Access does when a token reaches that limit.
To be eligible for cleanup, a token must be older than the configured period, must not have successfully authenticated during that period, and must not be directly referenced by an Access policy rule. Cleanup runs gradually in the background, so eligible tokens may not be disabled or deleted immediately.
— Cloudflare, Automatically manage inactive Access service tokens
Configure under Access settings → Manage service tokens → Automatically clean up inactive service tokens, or service_token_inactivity on the organisation PATCH (Service tokens — Manage inactive service tokens). Disabled tokens can be turned on again; deleted tokens cannot be recovered.
Renew, extend, and revoke service tokens
Section titled “Renew, extend, and revoke service tokens”Lifetime: Tokens expire based on duration chosen at creation. Refresh (dashboard or API) extends by one year, or Edit / PUT with a new duration (for example 17520h) for a custom extension (Service tokens — Renew).
Revoke before expiry: Delete the token. After deletion, dependent services cannot authenticate.
When editing an Access application, selecting Revoke existing tokens revokes existing sessions but does not prevent the user from starting a new session. As long as the Client ID and Client Secret are still valid, they can be exchanged for a new token on the next request. To revoke access, you must delete the service token.
— Cloudflare, Service tokens — Revoke
Common mistakes when using Access service tokens
Section titled “Common mistakes when using Access service tokens”- Allow instead of Service Auth — User Allow policies do not authenticate service tokens; under strict mode they are explicitly ignored when token headers are present.
- Expecting a session cookie — After successful service token auth with strict mode, there is no
CF_Authorizationcookie; scripts must keep sending headers. - 302 instead of 401 — Without strict mode or without token headers, failed auth may redirect browsers to login; parsers then break. Enable strict service token authentication for predictable API errors.
- Token still in policy but “inactive” cleanup — Tokens referenced in a policy rule are not eligible for automatic cleanup (Manage inactive service tokens).
- Disabling during rotation — Disabling a token ends validity of a previous secret still in a grace window (Turn a service token on or off).
- Confusing token types — Cloudflare Tunnel tokens, API tokens, and Access service tokens are different credentials with different rotation paths.
- Device enrollment — MDM
auth_client_id/auth_client_secretrequire a service token with Service Auth device enrollment permissions; Allow permissions do not work (Parameters).
How to check this on your site
Section titled “How to check this on your site”-
In the Cloudflare Zero Trust dashboard, open Access controls → Service credentials → Service Tokens and confirm the token exists, is enabled, and is not past its expiration after renew if needed.
-
On the protected application, verify a Service Auth policy Includes that token (common policies).
-
Under Access settings, review Strict service token authentication and inactive-token cleanup against your automation expectations (Access changelog).
-
From the client host, run
curlwithCF-Access-Client-IdandCF-Access-Client-Secretas in Service tokens — Request. Failed auth with strict mode should return 401 or 403, not 302 (strict setting). -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about so it can be corrected.