Sign-in with Cloudflare Access
This page is part of self-hosting. It assumes you
deploy with scripts/selfhost.sh from the main repository; the same text is
kept next to the code in
docs/SELF-HOSTING.md.
Wayglass applies Zero Trust to people the same way it applies it to changes:
nobody is trusted because of where they connect from, and every session is
short and tied to one identity. Agents keep their keys. People sign in with
your organisation’s login through Cloudflare
Access,
and the Worker mints each of them a human key bound to their email that
expires after 12 hours (24 at most). Their approvals are recorded as
you@example.com, and wayglass why shows Approved: you@example.com (Access).
Wayglass never talks to an identity provider. Access runs the login with whatever login methods your Zero Trust organisation has, and the Worker verifies the signed token Access attaches to each request. So Okta, Microsoft Entra ID, Google Workspace, GitHub, any OIDC or SAML provider, and the built-in one-time PIN all work, and switching providers later needs no change to Wayglass.
With Access on, the Worker also refuses the web app (/, /console/, every
static file) and /v1/public/* to anyone without a valid Access token. The key
API (/v1/*) is not gated: agents reach it with their keys, and the Worker
refuses it without one.
What Access needs
Section titled “What Access needs”| Hostname | None to add. Without --domain, the apps protect the Worker’s own <name>.<subdomain>.workers.dev, read from the account (GET /accounts/{id}/workers/subdomain). With --domain, they protect that hostname in one of your zones. Access protects paths of either kind of hostname the same way. |
| Zero Trust organisation | Created once in the dashboard (below). The free plan is enough for up to 50 users. |
| API token | The permissions from What you need, plus Access: Apps and Policies › Edit and Access: Organizations, Identity Providers, and Groups › Read. If the organisation has no login method yet, the script adds one-time PIN, which needs Edit on that second permission instead of Read. |
Create the Zero Trust organisation (once). The script cannot do this for
you. Open one.dash.cloudflare.com, pick a
team name and the Free plan. Your team domain is
<team>.cloudflareaccess.com; it is shown under Settings and can be
changed later. If the account has no organisation, the script stops and says
so before it creates anything. Cloudflare may ask for a payment method even on
the Free plan.
workers.dev needs no zone. A fresh account works as long as it has a
workers.dev subdomain, which the dashboard offers the first time you open
Workers & Pages (or npx wrangler subdomain <you> from worker/). If it
has none, the script stops before creating anything and says so. Do not use
the Worker’s one-click Enable Cloudflare Access (or “Protect this Worker”)
setting for Wayglass: it puts sign-in in front of every path, including the
/v1 key API, so agents could no longer reach it. The script uses three
hostname-based applications instead. Preview and version URLs
(<version>-<name>.<subdomain>.workers.dev) are not covered by them; there the
Worker refuses the web app and sign-in for lack of an Access token, and /v1
still needs a key.
The one command
Section titled “The one command”# on workers.dev (fresh account, no zone)scripts/selfhost.sh --access --allow 'you@example.com,@example.com'
# or on a custom domain in one of your zonesscripts/selfhost.sh --domain wayglass.example.com \ --access --allow 'you@example.com,@example.com'Add --dry-run first to see the plan: it reads your organisation, login
methods and existing applications, and creates nothing.
--allow decides who may sign in. Give it once with a comma-separated list,
or repeat it:
| Entry | Matches |
|---|---|
you@example.com |
That email address |
@example.com |
Every email address at that domain |
group:<name> |
Members of a group in your identity provider; see the table below for what <name> is for each provider |
--idp <name or id> (repeatable) picks which login methods the sign-in page
offers, by name (--idp Okta), id or type (--idp onetimepin). Without it,
the script uses every login method the organisation has. If it has none, the
script adds one-time PIN. With exactly one login method, Access skips its
chooser and goes straight to it.
The script then:
-
Picks the hostname (
--domain, or<name>.<subdomain>.workers.dev) and reads the organisation’s team domain (GET /accounts/{id}/access/organizations). -
Lists its login methods (
GET .../access/identity_providers) and picks them as above, adding one-time PIN if there are none. -
Creates three self-hosted Access applications, or updates them in place if they exist. They are matched by name, so a rerun never makes duplicates:
Application Covers Policy <name> webthe whole host, plus /v1/publicAllow, the people in --allow; 24 h session<name> human sign-in/v1/humanAllow, the same people; 12 h session <name> key API/v1Bypass, everyone <name>is the Worker name (--name, defaultwayglass). Access applies the most specific path, so/v1/humanand/v1/publicstay behind sign-in, and the rest of/v1reaches the Worker. The bypass is safe because the Worker checks a key on every/v1route itself; Access in front of it would only turn agents away, since they carry keys, not browser sessions. -
Writes the team domain and the two applications’ audience (AUD) tags into
worker/wrangler.selfhost.jsoncasACCESS_TEAM_DOMAIN,ACCESS_AUD(sign-in) andACCESS_WEB_AUD(web app), and deploys. None of these is secret. -
Checks the result with
curl:/and/v1/human/loginmust answer302tohttps://<team>.cloudflareaccess.com/..., and/v1/whoamimust answer401without a key. New applications and a new custom domain can take a few minutes; if the check fails, rerun with--keep-key.
It never changes the organisation’s settings or its login methods (apart from adding one-time PIN when there is none), and never touches other Access applications.
Sign in
Section titled “Sign in”wayglass login --human --worker https://wayglass.example.comwayglass doctor # "session" shows when the human session endsThe browser opens the Access login, then a Wayglass page asks you to confirm;
the key returns to a one-time listener on 127.0.0.1 in a form POST, never in
a URL, and is stored in credentials.yaml (mode 0600) with its expiry. On a
machine without a browser, open the printed URL in a browser on the same
machine. Run it again when the session ends. The web app signs a person in
through Access by itself: the Access login that let you reach the page is the
only one you see (a key can still be used at #/signin/key). Sign out
revokes that session’s key on the Worker (POST /v1/keys/self/revoke, which
any bound key may call on itself) and ends the Access session at
/cdn-cgi/access/logout. Your identity provider’s own session (Okta, for
example) is separate, so the next sign-in may not ask for a password.
Login methods (identity providers)
Section titled “Login methods (identity providers)”Set the provider up in Zero Trust › Integrations › Identity providers before running the script; Cloudflare’s guide for each one is linked below. Every provider that redirects back to Access uses the same callback URL:
https://<team>.cloudflareaccess.com/cdn-cgi/access/callbackRegister it in the provider as the redirect URI (OIDC) or Assertion Consumer Service URL (SAML).
| Provider | Cloudflare guide | group:<name> matches |
Notes |
|---|---|---|---|
| Okta | Okta | the Okta group name | Add a groups claim to the Okta app, or groups never reach Access. Okta set up as SAML counts as SAML below. |
| Microsoft Entra ID | Entra ID | the group’s Object ID, not its display name | Grant the app the directory permissions the guide lists, or group checks fail. |
| Google Workspace | Google Workspace | the group’s email address, such as group:reviewers@example.com |
Finish the admin consent link after saving. Group changes can take up to 24 hours to reach Access. Plain Google (consumer accounts) has no groups. |
| GitHub | GitHub | an organisation (group:acme) or a team (group:acme/reviewers) |
The person must grant the OAuth app access to that organisation. |
| Generic OIDC | Generic OIDC | the value of a groups claim |
Add groups under the provider’s custom OIDC claims, and make sure the provider sends an email claim. |
| Generic SAML | Generic SAML | the value of a groups attribute |
Send an attribute named groups and an email in the assertion. |
| One-time PIN | One-time PIN | not supported | Access emails a code to the address; only addresses --allow matches receive one. No provider to set up. |
| Cloudflare | Cloudflare | not supported | Members of your Cloudflare account sign in with their Cloudflare login. New organisations get this one by default. |
The Worker needs an email in the token Access issues; every provider above
supplies one when set up as its guide says. group: entries become one rule
per selected provider that has groups; the script refuses a group: entry when
none of the selected providers has groups.
Add or remove people later
Section titled “Add or remove people later”Rerun the same command with a new --allow list. The script updates the
policy on the web and sign-in applications in place. You can also edit the
<name> reviewers policy on both applications in Zero Trust › Access
controls › Applications; a rerun overwrites that policy with --allow, so
keep the two in step.
Removing someone from the policy stops new sign-ins. A human key they already
hold stays valid until it expires (12 hours by default). To cut it off now,
run wayglass keys list and wayglass keys revoke <id> with the admin key.
Set it up by hand
Section titled “Set it up by hand”If you prefer the dashboard, or your token cannot have Access permissions, create the same three applications in Zero Trust › Access controls › Applications (each Add an application › Self-hosted):
<domain>and<domain>/v1/public, with an Allow policy for your reviewers. Copy its Application Audience (AUD) Tag.<domain>/v1/human, session duration 12 h, with the same Allow policy. Copy its AUD tag. An application with no policy lets nobody in.<domain>/v1, with a Bypass policy that includes Everyone.
Then deploy with the values (none is secret):
scripts/selfhost.sh --keep-key --domain wayglass.example.com \ --access-team <team>.cloudflareaccess.com \ --access-aud <AUD of the /v1/human app> --access-web-aud <AUD of the web app>Without --access-web-aud, the Worker accepts the --access-aud tag on web
routes too (one application for the whole host). A gate with audiences but no
valid team domain refuses everything.
How the Worker checks the token
Section titled “How the Worker checks the token”The Worker does not trust Access blindly: it verifies the
Cf-Access-Jwt-Assertion header (or the CF_Authorization cookie) itself:
RS256 signature from https://<team>/cdn-cgi/access/certs, issuer, audience,
expiry, and an email claim. It refuses anything else. Service tokens carry no
email, so they cannot mint a human session. Every session is logged as
key.created with source: access (GET /v1/keys/events, admin key).
With every Access setting empty there is no gate, so the anonymous --public
view works as before. If you expose the web app to anyone but yourself, turn
Access on.
Troubleshooting Access
Section titled “Troubleshooting Access”| Symptom | Cause and fix |
|---|---|
selfhost.sh says the account has no Zero Trust organisation |
Create it once at one.dash.cloudflare.com, then rerun. |
selfhost.sh says the token cannot read the Zero Trust organisation |
Cloudflare answers 403 with code 10000 on GET .../access/organizations when the token lacks Access: Organizations, Identity Providers, and Groups › Read, even if it can list applications. Add that permission (Edit if one-time PIN must be added) and rerun. |
selfhost.sh says the account has no workers.dev subdomain |
Register one in Workers & Pages, or pass --domain. |
selfhost.sh says the token was refused on an /access/ call |
Add the two Access permissions above to the token. |
/ answers 302 to <team>.cloudflareaccess.com |
Working as intended: Access wants a sign-in. |
/ answers 403 from the Worker, with no redirect |
The request reached the Worker without an Access token: the web application does not cover this host, or Access is not in front of it yet. Check the application’s hostname. |
| The Access page says “That account does not have access” | You signed in, but the policy does not include you. Add your email, domain or group to --allow and rerun. |
| The sign-in page says “wrong audience” | ACCESS_AUD or ACCESS_WEB_AUD does not match the application. Rerun --access, or copy the AUD tags again in the manual setup. |
| The sign-in page says “wrong issuer” | --access-team does not match the organisation’s team domain. |
| The sign-in page says “no Cloudflare Access token” | The /v1/human application does not cover this host. |
| The sign-in page says “token names no person” | The provider sent no email claim. Fix the provider so it sends one. |
| Login fails at the provider, or groups do not match | In Zero Trust › Integrations › Identity providers, select Test next to the provider. It shows the identity and groups Access receives; compare them with your --allow entries. |
/v1/whoami answers 302 instead of 401 |
The <name> key API bypass application is missing, so agents cannot reach the API. Rerun --access. |