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-Assertionagainst 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 action | What it does | Logged | Use it for |
|---|---|---|---|
| Allow | Lets users who match the rules reach the application after identity provider login | Yes | People, with identity, device and network conditions |
| Block | Denies users who match the rules | Yes | Explicit denials, for example a country or a contractor group |
| Service Auth | Enforces non-identity-provider authentication: service tokens and mutual TLS | Yes | Scripts, CI jobs, SaaS webhooks, servers and devices without a user |
| Bypass | Disables Access enforcement for matching traffic; no security controls apply | No | Narrow 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
- Service Auth and Bypass policies are evaluated first, in order from top to bottom.
- Allow and Block policies are evaluated next, also top to bottom.
- Evaluation stops at the first Allow or Block that matches, so a later policy cannot override it.
- 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 tier | Include | Require | Exclude | Session |
|---|---|---|---|---|
| General internal tools | Identity provider group for the staff population | Authentication Method with MFA; Device posture (managed device) | Disabled or leaver group | Application session 24 hours or less |
| Administrative consoles | A named admin group only | MFA, managed device posture, Warp or Gateway connection | Countries you do not operate in | Policy session of a few hours |
| Contractor access | Contractor group or email domain | MFA; purpose justification for sensitive apps | Production data applications | Short 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:
| Setting | Range | Default | Where |
|---|---|---|---|
| Global session duration | 15 minutes to one month | 24 hours | Access controls, Access settings |
| Application session duration | Immediate timeout to one month | 24 hours | Access controls, Applications, Edit |
| Policy session duration | Immediate timeout to one month | Same as the application | Access 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 resourcecloudflare_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
| Event | Action | Detail from Cloudflare docs |
|---|---|---|
| Planned rotation | Rotate the secret | Client ID stays the same; new Client Secret; old secret valid for a grace period from one hour to 30 days, or Revoke immediately |
| Approaching expiry | Expiring Access Service Token alert | Notifies a week before expiry, for all or selected tokens; extend with Refresh (one year) or Edit |
| Leak reported by a scanning partner | Rotate, update clients, then re-enable | Reported tokens are disabled; re-enabling before rotation returns 409; Super Administrators and the creator are emailed |
| Token no longer used | Automatic cleanup of inactive tokens | Inactivity period 30 to 365 days, action disable or delete; tokens referenced directly by a policy are not eligible |
| Integration retired or token suspected stolen | Delete the token | Revoke 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_revokedfield; 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-CertandClient-Cert-Chainheaders, set them only whencert_verifiedis true andcert_revokedis 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
| Direction | Destination | Port and protocol | Required |
|---|---|---|---|
| Inbound | Any | Block all | Yes: the origin needs no inbound listener |
| Outbound | region1.v2.argotunnel.com, region2.v2.argotunnel.com | 7844 TCP (http2) and UDP (quic) | Yes |
| Outbound, SNI-filtering firewalls | cftunnel.com, h2.cftunnel.com, quic.cftunnel.com, _v2-origintunneld._tcp.argotunnel.com | 7844 | Where SNI is enforced |
| Outbound | api.cloudflare.com, update.argotunnel.com | 443 TCP | Optional: update checks |
| Outbound | <team-name>.cloudflareaccess.com | 443 TCP | Needed if cloudflared validates Access JWTs |
| DNS | TXT for cfd-features.argotunnel.com | 53 | Allow 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
accessorigin parameter, withrequired: true, yourteamNameand the application'saudTag, makes cloudflared validate the Access JWT inCf-Access-Jwt-Assertionbefore proxying. A public hostname route without an Access application in front publishes the service to the internet. - Keep origin TLS verification on:
noTLSVerifydefaults to false; leave it there and setcaPoolandoriginServerNamewhen 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 thekidagainstpublic_certs, and check theaudclaim. 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.
- Planned rotation: with at least two replicas, select Refresh token (or
PATCHthe tunnel with a newtunnel_secretof 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. - Suspected compromise: refresh the token, delete all tunnel connections with
DELETE /accounts/{account_id}/cfd_tunnel/{tunnel_id}/connectionsto drop any unauthorised connector, then reinstall every replica with the new token. - 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
- 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.
- 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.
- 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.
- 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.
- 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.
| Event | Source | Why it matters | ATT&CK |
|---|---|---|---|
| Policy changed to Bypass, or Include broadened to Everyone | Admin logs | Removes enforcement for an internal application | T1199 Trusted Relationship |
| Service token created, rotated or re-enabled outside the pipeline | Admin logs | New machine credential with access to internal apps | T1078 Valid Accounts |
| Service token used from a new source IP or country | access_requests | Possible stolen Client Secret | T1078 Valid Accounts |
| New tunnel, new connector, or token retrieved by API | Admin logs, tunnel connector list | Unknown path into or out of a private network | T1572 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 area | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | CIS Controls v8.1 | ISO/IEC 27001:2022 Annex A |
|---|---|---|---|---|
| Access policies and evaluation | AC-3 Access Enforcement, AC-17 Remote Access | PR.AA-05 | Control 6 Access Control Management | A.5.15 Access control |
| Service tokens and mTLS for machines | IA-9 Service Identification and Authentication, IA-5 Authenticator Management | PR.AA-01, PR.AA-03 | Control 5 Account Management | A.5.17 Authentication information |
| Tunnel with closed inbound firewall | SC-7 Boundary Protection | PR.IR-01 | Control 12 Network Infrastructure Management | A.8.20 Networks security |
| Origin TLS and JWT validation | SC-8 Transmission Confidentiality and Integrity | PR.AA-03 | Control 3 Data Protection | A.8.5 Secure authentication |
| Log export and review | AU-6 Audit Record Review, Analysis, and Reporting | DE.CM-01 | Control 8 Audit Log Management | A.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
- Cloudflare: Access policies
- Cloudflare: Service tokens
- Cloudflare: Session management
- Cloudflare: Tunnel permissions and token rotation
- Cloudflare: Tunnel with firewall
- Cloudflare: Validate JSON web tokens
- Cloudflare: Mutual TLS authentication
- NIST: SP 800-53 Rev. 5
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