Access
Cloudflare Access puts an authentication gate — an interactive login, a machine
service-token check, or a device-posture check — in front of a hostname this project already
publishes. This page walks through creating an identity provider, attaching a
CloudflareAccessPolicy to a Gateway, one of its listeners, an HTTPRoute, or a
GRPCRoute, minting a service token, and the specific traffic shapes Access can’t protect at
all. Access works the same way in both Tunnel Mode and DNS Mode.
Prerequisites
Section titled “Prerequisites”- A Cloudflare Zero Trust organization already set up on your account. Access is a Zero Trust product — this project configures policies within that organization, not the organization itself.
- A Cloudflare API token carrying the Access-specific permissions, in addition to whatever your deployment mode already needs — see Token Scopes for the exact permission set.
- A
Gatewayalready running in either mode, the same prerequisite Routing assumes. See Quickstart — Tunnel Mode or Quickstart — DNS Mode if you don’t have one yet.
Create an identity provider
Section titled “Create an identity provider”CloudflareAccessIdentityProvider configures who can log in — Google Workspace, GitHub, Entra
ID, Okta, or a one-time PIN (OTP) emailed to the requester. It’s cluster-scoped: an
identity provider is account-wide, not namespace-scoped, so only a privileged operator can
create one — the same scope CloudflareGatewayConfiguration already has, for the same reason.
spec.configurationRef is a plain name reference, {name: <configuration>} — the same
corev1.LocalObjectReference shape CloudflareTunnel/CloudflareDNSRecord already use. It
takes only name. There’s no namespace field on it, because this object has no
namespace of its own to resolve a bare name against in the first place.
The simplest worked example needs no external OAuth tenant at all — a one-time-PIN provider, which emails a login code to whatever address the requester types in:
apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareAccessIdentityProvidermetadata: name: my-otp-idpspec: configurationRef: name: tunnel-config provider: type: OTPFor the other four types, see
Identity provider client secrets
for the clientSecretRef/per-type field shape — it isn’t repeated here.
Here’s how far each provider.type is actually verified, stated at the tier this project has
real evidence for rather than rounded up:
provider.type |
Claim | Tier |
|---|---|---|
GoogleWorkspace |
The provider object is created and updated as specified | Live-verified against the real API |
GitHub |
Same | Live-verified |
EntraID |
Same | Live-verified |
Okta |
Same | Live-verified |
OTP |
Same, with an empty configuration, plus creating a real Access application against it | Live-verified |
| (any of the four real providers) | A user can actually log in through it | NOT verified, by anyone |
This project creates and maintains the identity provider object correctly, verified per type against the real Access API; whether a login through Google Workspace, GitHub, Entra ID, or Okta actually succeeds depends on the real credentials you supply, and that is not something this project verifies for you — Cloudflare itself doesn’t check those credentials until someone attempts to log in through them. OTP is the one type where the whole object-creation path is proven end to end with nothing external needed; the one-time-PIN email itself still isn’t something this project’s own testing automates.
Attach a CloudflareAccessPolicy
Section titled “Attach a CloudflareAccessPolicy”CloudflareAccessPolicy is the object that actually gates traffic. Its targetRefs may name
a Gateway (optionally scoped to one listener with sectionName), an HTTPRoute, or a
GRPCRoute — see Policy Attachment for the full targeting and
conflict rules (oldest-CreationTimestamp-wins, the hostname-contention layer specific to
this policy kind, and so on), which apply here unchanged and aren’t repeated on this page.
What’s specific to Access: winning a hostname generates one Cloudflare Access application per
hostname, not per targetRef — a policy naming both a Gateway and one of its own Routes
produces one application per distinct hostname, never two. A wildcard listener hostname
(*.example.com) produces no application of its own; each concrete hostname a Route
contributes under it gets its own. And because an application protects a hostname, attaching
a policy to one Route protects every request to that hostname — including traffic served by
other Routes, in other namespaces, that happen to share it. Every other Route that newly comes
under protection this way gets a Warning Event on itself, and the same happens in reverse if
protection is later removed — kubectl describe on a Route you don’t own, if you suspect it
shares a protected hostname with one you do.
Here’s a first policy, gating an entire Gateway behind an interactive login that admits
anyone who completes one:
apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareAccessPolicymetadata: name: my-access-policy namespace: defaultspec: targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: my-gateway rules: - decision: Allow include: - everyone: {}The policy’s namespace must be the Gateway or Route’s own namespace, not an arbitrary
one. targetRefs is same-namespace by construction — it has no field to name a different
namespace — so the example above uses default, the namespace the quickstarts’ own Gateway
(my-gateway) lives in. Targeting a Route instead of a Gateway directly works the same way:
use the Route’s namespace.
Two things about this example, stated here because this is the first policy on this page and both matter before you rely on it for anything real:
An Access application accepts login through every identity provider configured on your
Cloudflare account, not just the one you created above. v1alpha1 has no field that scopes an
application to a specific identity provider: if your account has more than one identity
provider configured, every everyone-decision policy on the account implicitly trusts all of
them, not only the one this page just created.
This example — Allow + everyone, with only an OTP identity provider configured on the
account — is not a real access gate. OTP with no email restriction lets anyone who can
receive mail at any address request a code and log in — Cloudflare’s own documentation calls
this exact combination out by name as a misconfiguration that admits the public. It’s shown
here only because it needs no external OAuth tenant to demonstrate the login flow. For a real
deployment, either configure a real identity provider (Google Workspace, GitHub, Entra ID,
Okta) so login is scoped to your organization’s actual users, or wait for
email/emailDomain-restricted rule forms, which aren’t available in v1alpha1 yet.
rules[].decision
Section titled “rules[].decision”| Value | Meaning |
|---|---|
Allow |
Admits a request matching any include entry, after an identity is established through a login. |
NonIdentity |
Admits a matching request without establishing a user identity at all — what a service-token check needs, since it doesn’t complete an interactive login. |
There’s no Bypass/Deny value: this project only ships the two decisions it has verified
work, and Bypass specifically fails open — a bypass rule matching more traffic
than intended would silently disable Access for it, which this project won’t ship unobserved.
A NonIdentity rule’s include list may not contain an everyone entry. include
entries are OR’d, so an everyone entry alongside a real check would still admit every
unauthenticated request through the everyone arm — exactly the fail-open shape Bypass was
excluded for, reassembled out of two individually legal values. Every entry of a NonIdentity
rule must be a serviceToken or devicePosture entry; the API server rejects anything else.
The three include forms
Section titled “The three include forms”| Form | Matches | Classification |
|---|---|---|
everyone: {} |
Any requester who completes a login through any identity provider configured on the account | Interactive |
serviceToken: {name: <CloudflareAccessServiceToken>} |
A request carrying that token’s CF-Access-Client-Id/CF-Access-Client-Secret header pair |
Non-interactive |
devicePosture: {ruleID: <uuid>} |
A WARP-enrolled device satisfying the referenced posture integration | Interactive — not yet classified as a non-interactive form, so it’s treated as interactive by default; a device that fails the posture check is served a browser block page rather than a non-interactive rejection |
“Interactive” versus “non-interactive” matters for gRPC traffic specifically — see
What Access can’t protect below. There’s deliberately no require
or no exclude list anywhere in this schema, and no email/emailDomain form yet — only the
three forms above ship in v1alpha1.
Confirm the first policy is enforcing
Section titled “Confirm the first policy is enforcing”Wait for the identity provider and the generated Access application to report ready:
kubectl wait cloudflareaccessidentityprovider/my-otp-idp --for=condition=Ready --timeout=30skubectl wait cloudflareaccessapplication --all -n default --for=condition=Ready --timeout=60sCloudflareAccessPolicy doesn’t carry a top-level Ready/Accepted condition at all —
like every policy kind in this project, it reports through status.ancestors[] instead (see
Policy Attachment), so kubectl wait --for=condition=Accepted does nothing useful here. Poll the ancestor’s own condition with
--for=jsonpath instead:
kubectl wait cloudflareaccesspolicy/my-access-policy -n default \ --for=jsonpath='{.status.ancestors[0].conditions[?(@.type=="Accepted")].status}'=True \ --timeout=30sIf the hostname this policy protects was already live before the policy existed — true
for every example on this page, since it follows the quickstarts’ own already-running
Gateway — unauthenticated requests keep succeeding for a few seconds after all of the above
report ready, while the Access application’s rules propagate to Cloudflare’s edge. This is
carve-out 1 of the ordering guarantee, not a bug: poll for the real
redirect below rather than treating an early 200 as a failure. Replace app.$ZONE below
with whatever hostname your Gateway or Route already serves — $ZONE is the same variable
the quickstarts set.
for i in $(seq 1 30); do code=$(curl -s -o /dev/null -w '%{http_code}' -I "https://app.$ZONE") [ "$code" = "302" ] && break sleep 2donecurl -sI "https://app.$ZONE"An unauthenticated request is redirected to the login page — 302, with a Location header
on <your-team-name>.cloudflareaccess.com/cdn-cgi/access/login/… (<your-team-name> is your
account’s own Zero Trust team domain; see Prerequisites). Wait a few seconds
after the first 302 and check again to confirm it’s stable, not just one lucky poll — this
is the “before” state the service-token check below compares against: once the service token
exists, this same unauthenticated check must still answer 302, never a bare 200.
Service tokens
Section titled “Service tokens”A CloudflareAccessServiceToken mints a machine credential — the
CF-Access-Client-Id/CF-Access-Client-Secret header pair a workload sends instead of
completing an interactive login. Unlike the identity provider above, it’s namespaced: a
service token is a consumer credential, so the workload that sends it lives in a namespace
and needs the values mounted there, and deleting one breaks exactly one consumer rather than
every tenant’s login.
apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareAccessServiceTokenmetadata: name: my-service-token namespace: defaultspec: configurationRef: name: tunnel-configThe service token’s namespace must match the policy that references it. A
CloudflareAccessPolicy’s serviceToken.name reference resolves in the policy’s own
namespace, the same same-namespace rule targetRefs follows above — so the token lives in
default here, alongside the policy.
The controller writes the minted credential into a Secret in this object’s own namespace — see Service token credentials for the exact Secret shape and key names, which isn’t repeated here. That write happens exactly once, from Cloudflare’s create response: Cloudflare returns the client secret exactly once and omits it from every later read, so there’s nothing for a later reconcile to re-fetch or repair.
Cloudflare also injects a one-year expiry on every token nobody asked for. Once
status.expiresAt passes, the controller emits a ServiceTokenExpired Warning Event once —
not on every resync past expiry — so watch kubectl get events rather than expecting the
object’s own conditions to flag it.
Rotation is delete-and-recreate the CloudflareAccessServiceToken object, not an in-place
mechanism. Cloudflare’s client secret can never be re-fetched once minted, so there is no
way for this project to rotate the Cloudflare-side credential of a live object without
replacing it. Delete the object — which, under the default deletionPolicy: Delete, revokes
the token at Cloudflare and always removes its Secret — and create a new one, cutting your
workload over to the new credential — or run two
CloudflareAccessServiceToken objects side by side and migrate consumers from one to the
other before deleting the old one, if you need zero downtime during the swap.
Now the earlier policy, updated to also admit this service token — either a human login or a request carrying this token’s credentials gets through:
apiVersion: cfgateway.dreamfuselabs.com/v1alpha1kind: CloudflareAccessPolicymetadata: name: my-access-policy namespace: defaultspec: targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: my-gateway rules: - decision: Allow include: - everyone: {} - decision: NonIdentity include: - serviceToken: name: my-service-tokenThis policy is shown targeting a Gateway, where it’s fine. Note that the combination itself
is interactive as a whole — the Allow/everyone rule alone makes it so, regardless of the
NonIdentity/serviceToken rule alongside it — so if this exact policy targeted a GRPCRoute
instead, it would be rejected under What Access can’t protect
below.
Verify
Section titled “Verify”With the updated policy applied above, wait for the service token and the policy’s ancestor status to report ready, then confirm the service token’s credentials get through and the unauthenticated redirect from above still holds.
kubectl wait cloudflareaccessservicetoken/my-service-token -n default --for=condition=Ready --timeout=30skubectl wait cloudflareaccesspolicy/my-access-policy -n default \ --for=jsonpath='{.status.ancestors[0].conditions[?(@.type=="Accepted")].status}'=True \ --timeout=30sRead the two values out of the Secret the CloudflareAccessServiceToken wrote (see
Service token credentials) into
shell variables:
CLIENT_ID=$(kubectl get secret my-service-token -n default -o jsonpath='{.data.client-id}' | base64 -d)CLIENT_SECRET=$(kubectl get secret my-service-token -n default -o jsonpath='{.data.client-secret}' | base64 -d)Cloudflare’s edge needs a few seconds to pick up the updated policy’s new rule. This is a
later update to an application that already exists, not the first-publish case the
ordering guarantee measures and puts a margin on — don’t assume that
margin still applies here. Poll the header request itself until it returns 200 rather than
assuming instant propagation:
for i in $(seq 1 30); do code=$(curl -s -o /dev/null -w '%{http_code}' \ -H "CF-Access-Client-Id: $CLIENT_ID" \ -H "CF-Access-Client-Secret: $CLIENT_SECRET" \ "https://app.$ZONE") [ "$code" = "200" ] && break sleep 2donecurl -s \ -H "CF-Access-Client-Id: $CLIENT_ID" \ -H "CF-Access-Client-Secret: $CLIENT_SECRET" \ "https://app.$ZONE"This should print your backend’s response body — hello from tunnel mode, if you’re
following straight on from the Tunnel Mode quickstart.
Re-run the unauthenticated check from before the service token existed: it must still answer
302, never a bare 200 — adding the service-token rule admits more credentials, it
doesn’t remove the login requirement the Allow/everyone rule already established.
curl -s -o /dev/null -w '%{http_code}\n' -I "https://app.$ZONE"A policy whose rules are all NonIdentity — no Allow/everyone rule at all — answers
an unauthenticated request with 403 and no Location header instead of the 302 shown
above, since there’s no login page to redirect to. Neither policy on this page is shaped that
way, so this walkthrough doesn’t exercise it; it’s asserted live by this project’s own
end-to-end test suite.
What Access can’t protect
Section titled “What Access can’t protect”Three traffic shapes are rejected outright, with Accepted=False, Reason=UnsupportedFeature
on the generated Access application and no call made to Cloudflare at all — see
UnsupportedFeature. The hostname itself still
publishes and keeps serving; Access just can’t be the thing protecting it.
| Traffic shape | Why |
|---|---|
A TLS-passthrough listener (protocol: TLS, mode: Passthrough) |
The connection never terminates at Cloudflare’s edge, so there’s no HTTP layer for Access to act on — the same structural reason TLSRoute can’t carry Access either. |
A DNS-mode record with proxied: false |
Cloudflare’s edge is out of the request path entirely; an Access application would report success while protecting nothing. This project rejects the combination outright rather than silently forcing proxied: true over an explicit choice you made. |
| gRPC traffic behind an interactive rule set | grpc-go rejects Access’s login-redirect response outright. This applies as soon as any rule protecting the hostname is interactive — a decision: Allow rule, or any include entry that is everyone, devicePosture, or an unclassified future form. A GRPCRoute is permitted only when every rule protecting the hostname has decision: NonIdentity and every include entry in every one of those rules is serviceToken — since a service-token response carries no redirect, though this project hasn’t independently confirmed gRPC compatibility for that combination with a real client. |
Every Tunnel Mode hostname is proxied by construction — the tunnel’s own routing DNS record is
always created with proxied: true — so the proxied: false rejection above never applies in
this mode.
Access only applies to a proxied record. Check dnsDefaults.proxied on the
CloudflareGatewayConfiguration your Gateway resolves, and any per-record override — see
TLSRoute for the other place proxied: false gets forced rather
than rejected. If you need both Access protection and a DNS-only hostname, that combination
isn’t available: pick one.
If a previously-protected hostname transitions into one of these rejected shapes later (for
example, someone flips proxied: false on a hostname an Access policy already protects), the
policy’s ancestor status reports Accepted=False, Reason=[InvalidParameters](/reference/conditions/#invalidparameters) once every hostname
under that targetRef is rejected — the first place to look when something goes wrong — and the
hostname keeps serving, now unprotected, loudly reported through a Warning Event, never
silently. Whether the Cloudflare-side application itself is removed depends on
deletionPolicy: under the default Delete it’s removed; under Orphan it stays live at
Cloudflare, still enforcing its last-synced rules — protecting nothing in the proxied: false
and TLS-passthrough cases, where the edge is out of the path entirely, but still gating
traffic (and potentially breaking gRPC clients that can’t complete an interactive login) if
the trigger was a route turning GRPCRoute-served instead. The
reverse direction (fixing the misconfiguration) isn’t instantaneous either: the hostname keeps
serving unprotected while the application walks back through its normal creation sequence,
which is at minimum the propagation window described next.
The ordering guarantee
Section titled “The ordering guarantee”This project will not publish a hostname’s routing DNS record until Cloudflare has accepted its Access application and a short settle delay has passed — so there’s no window where the hostname is live and reachable but not yet gated. That guarantee is about the create path only, and it has four carve-outs, stated plainly rather than left for you to discover:
- Attaching a policy to a hostname that’s already live. It keeps serving unauthenticated until the new application is created and propagates — the normal brownfield-adoption path, and not a window this guarantee can close, since the record already existed before any policy named it.
- A user-authored
CloudflareDNSRecord. This project never gates a record it didn’t generate itself, and in Tunnel Mode such a record that already holds the hostname’s claim (that is, it’s the oldest claim for that hostname — see Lifecycle and Ownership) wins, so the generating reconciler skips that hostname entirely — no gate is ever consulted for it. - A hostname Access structurally can’t protect (the three rejections above). It publishes unprotected by design, and that’s reported on the generated Access application rather than hidden.
- A first-publish interleaving race across namespaces. If the reconciler that publishes a
hostname runs before the Access policy protecting it has actually resolved to that hostname
(typically because the policy’s Route hasn’t yet been accepted by its parent
Gateway), the hostname publishes unprotected, and the gate doesn’t re-engage for it afterward. Protection still arrives moments later through the normal path — this is a narrow, one-time timing window at first publish, not a permanent hole.
The settle delay itself: a measured 2–5 second gap between Cloudflare accepting an Access
application and that application actually enforcing at the edge, observed across live test
runs. This project waits 12 seconds past Ready before trusting a freshly created
application, as a safety margin over that measurement — stated explicitly as a margin over
what was observed, not a Cloudflare SLA. It applies once, on first publish, only to hostnames
carrying an Access policy; nothing already published pays this cost again.
Device posture
Section titled “Device posture”Referencing a device-posture integration by UUID in a policy’s include list is supported —
but Access does not validate the UUID you give it, at creation or at attachment time. An
operator who typos a posture-rule UUID gets a Ready=True Access application and no error
anywhere. The controller doesn’t read posture rules at all — there’s no code path that calls a
posture-rule listing endpoint — so there’s nothing for it to validate your UUID against either;
there’s no client-side validation to add. Double-check the UUID against the Cloudflare
dashboard before relying on it, and whether enforcement itself behaves as expected for your
posture rule is something this project hasn’t independently verified.
Mutual TLS (mTLS) client-certificate authentication is not supported by this project. There’s no CRD for managing mTLS certificates and no policy rule form that references one.
Cleanup
Section titled “Cleanup”Delete objects in the order that avoids leaving something orphaned mid-teardown:
- Delete every
CloudflareAccessPolicythat targets theGateway/Route you’re tearing down first. Under the defaultdeletionPolicy: Delete, each one’s generated Access application is removed from Cloudflare as part of this, and the hostnames it protected go back to serving unauthenticated (or stop serving at all, if you’re deleting theGateway/Route too). UnderdeletionPolicy: Orphan, the application stays live at Cloudflare and keeps enforcing its last-synced rules even though the Kubernetes object is gone. - Delete any
CloudflareAccessServiceTokenobjects the policy referenced. The Secret is always deleted; under the defaultdeletionPolicy: Deletethe token is also revoked at Cloudflare, whileOrphanleaves the Cloudflare-side token valid. - Delete the
CloudflareAccessIdentityProvideronly once you’re sure nothing else on the account still needs that login method. No policy field actually references an identity provider by ID — as noted above, an Access application accepts every identity provider configured on the account — so deleting one doesn’t leave any policy pointing at a dangling reference. Under the defaultdeletionPolicy: Delete, what actually happens is account-wide: that login method disappears from every Access application on the account at once, not just the ones this page created; if it was the account’s only identity provider, every interactive rule anywhere on the account now has nowhere to authenticate.deletionPolicy: Orphanleaves the Cloudflare-side identity provider in place, and referencing an existing provider byspec.existingIDnever deletes anything at Cloudflare regardless ofdeletionPolicy. - Then tear down the
Gateway/Route/tunnel itself, the same order Routing and the quickstarts already describe.
Deleting a CloudflareAccessPolicy before the Gateway/Route it protects is gone — which is
exactly what Step 1 above recommends — is safe and expected; it’s exactly the ordinary “stop
protecting this, keep serving it” path. A service token that’s still referenced by a live
policy is the orphan hazard worth avoiding: deleting it leaves the policy’s reference
unresolvable, which reports Accepted=False, Reason=[InvalidParameters](/reference/conditions/#invalidparameters) on every one of that
policy’s ancestors. An identity provider has no equivalent per-policy signal, because — as
above — no policy references one directly; its deletion consequence is account-wide, not a
dangling reference on any one policy.
Credentials and Secrets covers every Secret shape this page references in full, including GitOps-friendly ways to manage them.