Join our Newsletter — 33% off our NHI Course
Home› Guides› Cloudflare Zero Trust Configuration Guide: Access Policies, Tunnels…
Guide Zero Trust

Cloudflare Zero Trust Configuration Guide: Access Policies, Tunnels and Service Tokens Done Right

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 13 November 2026 18 min read
On this page

Cloudflare Access, Cloudflare Tunnel and Access service tokens together decide which people, devices and machines reach your internal applications, so a loose policy, a long-lived service token or a copied tunnel token can open a private service to anyone who holds it. This guide goes below the account level and covers the Zero Trust data plane: how Access policies are evaluated, how to write Allow, Block, Bypass and Service Auth policies that hold up, how to run cloudflared tunnels with a closed inbound firewall and validated JWTs, and how to issue, tag, rotate and retire service tokens and mTLS certificates for machine clients. It is for engineers who build or review a Cloudflare One deployment. Account roles, dashboard SSO and Cloudflare API token hardening are covered in the Cloudflare Security Configuration Guide and are not repeated here.

This is an independent guide from NHI Mgmt Group, based on Cloudflare's public documentation as of November 2026. It is not sponsored or reviewed by Cloudflare. Product features change, so confirm settings against Cloudflare's current documentation.

Key takeaways

  • Know the evaluation order before writing policy. Service Auth and Bypass policies are evaluated first, then Allow and Block, top to bottom, and the first matching Allow or Block wins; anything that matches nothing is denied.
  • Use Service Auth, not Bypass, for machines. Bypass turns off Access enforcement and logging for matching traffic, while Service Auth checks a service token or client certificate and keeps the request in the Access logs.
  • Treat the tunnel token as a production credential. Anyone holding a remotely-managed tunnel's token can run a connector for it, so store it in a secrets manager, rotate it with replicas, and know the compromise procedure.
  • Give every service token an owner, tags, a short duration and an expiry alert. Turn on strict service token authentication and automatic cleanup of inactive tokens, and remember that deleting the token is the only full revocation.
  • Validate the Access JWT at the origin. Set Protect with Access on tunnel routes, or check Cf-Access-Jwt-Assertion against your team's public keys, so a request that did not pass through Access is refused.

How the Access policy engine decides

Each Access application has one or more policies, each with one action and a set of rules.

Policy actionWhat it doesLoggedUse it for
AllowLets users who match the rules reach the application after identity provider loginYesPeople, with identity, device and network conditions
BlockDenies users who match the rulesYesExplicit denials, for example a country or a contractor group
Service AuthEnforces non-identity-provider authentication: service tokens and mutual TLSYesScripts, CI jobs, SaaS webhooks, servers and devices without a user
BypassDisables Access enforcement for matching traffic; no security controls applyNoNarrow public paths such as a health check, never internal applications

Rule logic

  • Include (OR): the user must match at least one Include criterion. Every policy needs one Include rule, which defines the starting pool.
  • Require (AND): the user must match every Require rule. Multiple values in one Require rule are joined by AND; use a rule group when you need OR inside a Require.
  • Exclude (NOT): matching any Exclude criterion removes the user from the policy.

Cloudflare documents 22 selectors, from identity provider group, OIDC Claim and Authentication Method to Device posture, Country, IP ranges, Service Token Tag, Common Name and Valid Certificate.

Evaluation order

  1. Service Auth and Bypass policies are evaluated first, in order from top to bottom.
  2. Allow and Block policies are evaluated next, also top to bottom.
  3. Evaluation stops at the first Allow or Block that matches, so a later policy cannot override it.
  4. A request that matches no Allow policy is denied, because Access is deny by default.

So a Bypass policy beats every Allow and Block for the traffic it matches, and an Allow placed above a Block can admit users the Block was meant to stop: order Block policies first when they carve out exceptions. Non-identity attributes such as device posture and IP are re-evaluated on each HTTP request during the session, so posture failures take effect without waiting for the session to end.

Writing Access policies that hold up

Policy patterns for people

Application tierIncludeRequireExcludeSession
General internal toolsIdentity provider group for the staff populationAuthentication Method with MFA; Device posture (managed device)Disabled or leaver groupApplication session 24 hours or less
Administrative consolesA named admin group onlyMFA, managed device posture, Warp or Gateway connectionCountries you do not operate inPolicy session of a few hours
Contractor accessContractor group or email domainMFA; purpose justification for sensitive appsProduction data applicationsShort policy session, reviewed monthly
  • Use groups, not lists of emails: identity provider groups follow joiners and leavers; hand-maintained Emails selectors leave former staff with access.
  • Put MFA in Require: even if the identity provider enforces MFA, requiring it in the policy makes it visible and testable. See the Conditional Access Guide for the same idea at the identity provider.
  • Do not lean on IP ranges alone: an IP range in Include admits every host on that network; use it as a Require condition on top of identity.

Session lengths

Access has three session layers. Cloudflare's session management documentation lists the defaults and ranges:

SettingRangeDefaultWhere
Global session duration15 minutes to one month24 hoursAccess controls, Access settings
Application session durationImmediate timeout to one month24 hoursAccess controls, Applications, Edit
Policy session durationImmediate timeout to one monthSame as the applicationAccess controls, Policies, Edit

The most specific setting wins: Cloudflare One Client session, then policy, then application, then global. Shorten the policy session on admin tools rather than shortening every application. When an application token expires Access reissues it silently while the global token is valid and the user still passes policy, so the global duration is the real re-login interval. For single-page applications, send X-Requested-With: XMLHttpRequest so an expired session returns 401 instead of failing silently.

To cut access during an incident: "Revoke existing tokens" on the application ends current sessions, but a user whose identity provider account is still active can start a new one. Revoking the user under Team and Resources, Users ends access to every Access application; disable the account in the identity provider first if the removal is meant to stick.

Service tokens for machine clients

A service token is a Client ID and Client Secret pair sent on every request in the CF-Access-Client-Id and CF-Access-Client-Secret headers, and the application must have a Service Auth policy that matches the token, otherwise Access redirects the client to an identity provider login. See the Secrets Management Guide for storage patterns.

Issuing

  • Create: Zero Trust, Access controls, Service credentials, Service Tokens, Create Service Token, or POST /accounts/{account_id}/access/service_tokens, or the Terraform resource cloudflare_zero_trust_access_service_token, which needs the Access: Service Tokens Write permission.
  • Capture once: the Client Secret is shown once. Write it straight into a secrets manager; if it is lost, generate a new token.
  • Recognise the format: new secrets issued from 26 August 2026 carry a cfast_ prefix with a checksum, which secret scanners can match. Older 64-character hexadecimal secrets keep working.
  • Choose a duration: the Service Token Duration is set at creation. Cloudflare's examples use 8760h (one year) and 17520h (two years); choose the shortest period the integration's owner can rotate within.

Scoping with tags

Write Service Auth policies against a specific token or a Service Token Tag, not Any Access Service Token, which admits every valid token in the organisation. Tags are exact, case-sensitive key and value pairs, up to five per token, and the selector works in Include, Require and Exclude. A sound pattern is Include on env=prod with Require on app=billing-sync, so a token must carry both. Updating tags replaces the whole set, and a tag never makes an expired or disabled token valid.

Strict service token authentication

With strict mode on, failed requests get a 401 or 403 rather than a login redirect, only Service Auth policies can authorise, any CF_Authorization cookie is ignored and none is issued, so clients present headers on every call. Organisations created on or after 5 October 2026 have it on permanently; older ones can enable it in Access settings or with strict_service_token_auth after testing clients.

Rotation, leaks and cleanup

EventActionDetail from Cloudflare docs
Planned rotationRotate the secretClient ID stays the same; new Client Secret; old secret valid for a grace period from one hour to 30 days, or Revoke immediately
Approaching expiryExpiring Access Service Token alertNotifies a week before expiry, for all or selected tokens; extend with Refresh (one year) or Edit
Leak reported by a scanning partnerRotate, update clients, then re-enableReported tokens are disabled; re-enabling before rotation returns 409; Super Administrators and the creator are emailed
Token no longer usedAutomatic cleanup of inactive tokensInactivity period 30 to 365 days, action disable or delete; tokens referenced directly by a policy are not eligible
Integration retired or token suspected stolenDelete the tokenRevoke existing tokens on the application only ends sessions; deleting the token is the only way to revoke its access

Disabling a token stops it authenticating, including a previous secret still in its grace period; use it while you confirm a suspected leak, then delete.

Service token or mutual TLS

  • Choose service tokens for SaaS platforms, webhooks and scripts that can only add headers, and on the Free plan, where Cloudflare documents service tokens as the option for machine clients.
  • Choose mTLS where the client can hold a private key, ideally in a TPM or secure element, and you already run a private CA. Upload the CA chain under Service credentials, Mutual TLS, associate the hostnames, and write a Service Auth policy using Common Name for a specific client or Valid Certificate for any certificate from that CA. Access mTLS is available on Enterprise and pay-as-you-go Zero Trust plans.
  • Plan revocation for mTLS: Cloudflare's documentation describes enforcing a CRL at your server or in a Worker using the cf.tls_client_auth.cert_revoked field; build that before you depend on certificate removal. See the mTLS Guide and the mTLS vs Signed Tokens for Service Authentication.
  • Forward certificates safely: if the origin needs the client certificate, use the RFC 9440 Client-Cert and Client-Cert-Chain headers, set them only when cert_verified is true and cert_revoked is not, and always strip client-supplied copies first.

Running Cloudflare Tunnel safely

A tunnel is a named object with a UUID. The connector, cloudflared, opens four long-lived outbound connections to at least two Cloudflare data centres, and traffic then flows both ways over them. Extra cloudflared instances on other hosts are replicas of the same tunnel. Remotely-managed tunnels keep configuration in Cloudflare and run from a token; locally-managed tunnels keep it in a local directory. Quick tunnels on random trycloudflare.com subdomains should not appear in production; the Cloudflare Tunnel and trycloudflare abuse guide covers how to spot tunnels that are not yours.

Firewall for the connector host

DirectionDestinationPort and protocolRequired
InboundAnyBlock allYes: the origin needs no inbound listener
Outboundregion1.v2.argotunnel.com, region2.v2.argotunnel.com7844 TCP (http2) and UDP (quic)Yes
Outbound, SNI-filtering firewallscftunnel.com, h2.cftunnel.com, quic.cftunnel.com, _v2-origintunneld._tcp.argotunnel.com7844Where SNI is enforced
Outboundapi.cloudflare.com, update.argotunnel.com443 TCPOptional: update checks
Outbound<team-name>.cloudflareaccess.com443 TCPNeeded if cloudflared validates Access JWTs
DNSTXT for cfd-features.argotunnel.com53Allow if egress DNS is filtered by name

Prefer FQDN allowlists, otherwise allow every published address per hostname. Because the origin has no inbound listener, Authenticated Origin Pulls does not apply to tunnelled hostnames; the connector credentials authenticate the origin side instead.

Protect every route with Access

  • Turn on Protect with Access: the access origin parameter, with required: true, your teamName and the application's audTag, makes cloudflared validate the Access JWT in Cf-Access-Jwt-Assertion before proxying. A public hostname route without an Access application in front publishes the service to the internet.
  • Keep origin TLS verification on: noTLSVerify defaults to false; leave it there and set caPool and originServerName when the origin uses a private CA, rather than switching verification off.
  • Turn on URL normalisation: available from cloudflared 2026.10.0 and off by default; enable it where Access-protected ingress rules match on paths.
  • Validate in the application too: where the app can, check the JWT signature against https://<team-name>.cloudflareaccess.com/cdn-cgi/access/certs, match the kid against public_certs, and check the aud claim. Access rotates signing keys every six weeks by default and keeps old keys valid for seven days, so fetch keys rather than pinning them.

Tunnel tokens and permissions

Cloudflare states plainly that anyone with a remotely-managed tunnel's token can run the tunnel. The token can be read from the dashboard install command, from GET /accounts/{account_id}/cfd_tunnel/{tunnel_id}/token, or through Terraform, by anyone with one of the Cloudflare One Connectors Write, Cloudflare One Connector: cloudflared Write or Cloudflare Tunnel Write permissions. Treat those permissions as privileged and scope them to individual tunnels where possible.

  1. Planned rotation: with at least two replicas, select Refresh token (or PATCH the tunnel with a new tunnel_secret of at least 32 random bytes). Existing connectors keep running; the old token can no longer open new connections. Reinstall half the replicas with the new token, confirm the service is healthy, wait about 10 minutes for traffic to shift, then do the other half.
  2. Suspected compromise: refresh the token, delete all tunnel connections with DELETE /accounts/{account_id}/cfd_tunnel/{tunnel_id}/connections to drop any unauthorised connector, then reinstall every replica with the new token.
  3. Locally-managed tunnels: protect the tunnel credentials in the cloudflared directory the same way, and keep them out of images and repositories.

Where identity fits

Service tokens, client certificates and tunnel tokens are non-human credentials, and a tunnel token authenticates a whole network path. Give each service token, certificate and tunnel an owner, a purpose and an expiry in your NHI inventory, review them with the same cadence as cloud service accounts, and alert when one is created outside your pipeline. See the API Key Management Guide for lifecycle practice that carries over directly.

Rolling it out

  1. Inventory (week 1): export every Access application with its policies and actions, every service token with expiry, last use and tags, every mTLS CA, and every tunnel with its replicas, routes and management mode. Assign an owner to each.
  2. Remove Bypass (weeks 2 to 3): list Bypass policies, keep only narrow public paths, and replace the rest with Allow for people or Service Auth for machines. Test in a staging application first and keep the old policy disabled, not deleted, for quick rollback.
  3. Tighten service tokens (weeks 3 to 5): move policies from Any Access Service Token to specific tokens or tags, set durations and expiry alerts, turn on inactive token cleanup with the disable action first, then strict authentication once clients are confirmed.
  4. Close the origin (weeks 4 to 6): enable Protect with Access on every tunnel route, block inbound traffic on connector hosts, add replicas where only one connector exists, and move tunnel tokens into a secrets manager.
  5. Test and rehearse: confirm a request without a JWT is refused at the origin, and rotate one service token and one tunnel token in a maintenance window.

Decision guidance

  • Public hostname or private network: use a public hostname with Access for browser users on unmanaged devices; use private network routing with the Cloudflare One Client for non-HTTP protocols or services that should have no public name.
  • Remotely or locally managed: remotely-managed keeps configuration central and visible; locally-managed suits configuration held in code that the dashboard should not change.
  • Small organisations: one identity provider group per application, MFA in Require, no Bypass, and service tokens with expiry alerts.
  • Large organisations: add device posture, rule groups, tag-based Service Auth, per-tunnel permissions, Logpush, and policies in Terraform reviewed in pull requests.

Detection and measurement

Cloudflare's log documentation lists Admin logs kept 18 months on every plan and Access authentication logs from 24 hours on Free to 180 days on Enterprise. Export the access_requests dataset through Logpush so authentication history outlives the in-product window. Remember that Bypass traffic is never logged.

EventSourceWhy it mattersATT&CK
Policy changed to Bypass, or Include broadened to EveryoneAdmin logsRemoves enforcement for an internal applicationT1199 Trusted Relationship
Service token created, rotated or re-enabled outside the pipelineAdmin logsNew machine credential with access to internal appsT1078 Valid Accounts
Service token used from a new source IP or countryaccess_requestsPossible stolen Client SecretT1078 Valid Accounts
New tunnel, new connector, or token retrieved by APIAdmin logs, tunnel connector listUnknown path into or out of a private networkT1572 Protocol Tunneling

Metrics

  • Bypass coverage: number of Bypass policies on non-public paths (target zero).
  • Token hygiene: percentage of service tokens with an owner, tags and a duration of one year or less.
  • Expiry response: Expiring Access Service Token alerts not actioned within the week.
  • Origin protection: percentage of tunnel routes with Protect with Access enabled.
  • Connector resilience: percentage of production tunnels with two or more replicas.

Common failure patterns

  • Bypass as a shortcut: a team adds Bypass to fix a broken integration, and the application is left unenforced and unlogged. Use Service Auth with a scoped token instead.
  • Any Access Service Token everywhere: one leaked token reaches every application that uses this selector. Scope by token or tag.
  • Revoking sessions and calling it done: Revoke existing tokens leaves the service token valid. Delete or disable the token itself.
  • A tunnel route with no Access application: the service is published to the internet behind Cloudflare with no authentication. Require an Access application and Protect with Access on every route.
  • Tunnel tokens in scripts and images: the install command is pasted into a provisioning script or container image, and anyone who reads it can run a connector. Pull the token from a secrets manager at start-up.

Framework mapping

Control areaNIST SP 800-53 Rev. 5NIST CSF 2.0CIS Controls v8.1ISO/IEC 27001:2022 Annex A
Access policies and evaluationAC-3 Access Enforcement, AC-17 Remote AccessPR.AA-05Control 6 Access Control ManagementA.5.15 Access control
Service tokens and mTLS for machinesIA-9 Service Identification and Authentication, IA-5 Authenticator ManagementPR.AA-01, PR.AA-03Control 5 Account ManagementA.5.17 Authentication information
Tunnel with closed inbound firewallSC-7 Boundary ProtectionPR.IR-01Control 12 Network Infrastructure ManagementA.8.20 Networks security
Origin TLS and JWT validationSC-8 Transmission Confidentiality and IntegrityPR.AA-03Control 3 Data ProtectionA.8.5 Secure authentication
Log export and reviewAU-6 Audit Record Review, Analysis, and ReportingDE.CM-01Control 8 Audit Log ManagementA.8.15 Logging

Practitioner checklist

  • Remove Bypass from every internal application; keep it only for narrow public paths.
  • Order Block policies above Allow policies where they carve out exceptions, and require MFA and device posture for admin tools.
  • Scope Service Auth policies to specific tokens or tags, never Any Access Service Token for production apps.
  • Set service token durations to one year or less, add the Expiring Access Service Token alert, and enable inactive token cleanup.
  • Turn on strict service token authentication after testing clients.
  • Enable Protect with Access on every tunnel route and keep origin TLS verification on.
  • Block all inbound traffic on connector hosts and allow outbound 7844 TCP and UDP only to the published hostnames.
  • Run at least two replicas per production tunnel and rehearse token rotation and the compromise procedure.
  • Export Access and admin logs to the SIEM and alert on Bypass, token and tunnel changes.
  • Record an owner, purpose and expiry for every service token, mTLS CA and tunnel in the NHI inventory.

Standards and references

Related NHI Mgmt Group resources: Cloudflare Security Configuration Guide · Cloudflare API tokens security guide · Cloudflare Tunnel and trycloudflare abuse · ZTNA vs VPN · Secrets Management Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 13 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.