Cf access
Reach Cloudflare Access–gated hosts (internal CI, dashboards, APIs, MCP servers) from the CLI, from Node clients, and from long-running processes whose credential would otherwise expire. Use when a request to an internal host answers with a redirect to cdn-cgi/access/login or a 403, when an MCP server or daemon behind Cloudflare Access works right after launch and stops hours later, when an Access app has no service-token policy so only browser SSO can mint a JWT, or when the user mentions cf-access, cloudflared access login/token, CF_Authorization, the cf-access-token header, or asks to install, repair, or inspect the local Access token broker and proxy.From its SKILL.md
npx -y skills add hardworker/agentic-toolkit --skill cf-accessAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
17.8 KB, as published. Nobody here has run it
Cloudflare Access from the CLI
A token broker (cf-access), a localhost proxy that keeps injecting fresh tokens (cf-access-proxy), and a Node preload that routes gated traffic into the proxy with no client changes (cf-access-preload.cjs).
The broker and curl mode work anywhere cloudflared runs; the launchd daemon in install.sh is macOS-only.
Why a broker is needed
- An Access app whose policy allows only an IdP (Google Workspace, Okta, …) has no service-token path. A JWT can only come from a browser SSO round-trip — a headless client cannot get one on its own, ever.
cloudflaredkeeps an org-wide session plus a per-app token cache at~/.cloudflared/<host>-<aud>-token. So the first login is the only interactive one: it warms the org, and every other app in the same org then mints silently. That is whycf-access loginwith no arguments is the normal entry point.- App tokens are short-lived (typically ~24h). Anything that reads its credential once at startup — most MCP servers, any daemon taking a header from env — works for a day and then fails with a login redirect that looks nothing like an auth error. The proxy exists for exactly that case.
Three layers — pick by what the client can do
| The client can | Use | Renewal |
|---|---|---|
| take a fresh header/env on every invocation (shell, curl, short-lived CLI) | cf-access token / cookie / curl / env | per invocation |
| only be pointed at a URL (any language, any runtime) | proxy fixed port — a line in ~/.config/cloudflare-access/proxy | per request, by the proxy |
| be a Node process with no useful config surface | NODE_OPTIONS=--require …/cf-access-preload.cjs → proxy dynamic port | per request, by the proxy |
Direct mode is simplest and should be preferred for anything short-lived. Reach for the proxy the moment the process outlives its token.
Files
All of these live in this skill's directory, beside this SKILL.md.
| File | Role |
|---|---|
cf-access | token broker: token, cookie, env, curl, login, list |
cf-access-proxy | localhost HTTP fronts; injects and renews cf-access-token per request |
cf-access-preload.cjs | --require shim: patches http/https/fetch to route allowed hosts into the proxy |
cf-access-hosts.cjs | the suffix allowlist, required by both the proxy and the preload so the boundary has one owner |
install.sh | symlinks them into a bin dir, seeds config, loads the launchd agent |
apps.example, hosts.example, browser.example | config templates (placeholders — edit after install) |
Install
<skill-dir>/install.sh # symlink + seed config + load the daemon
<skill-dir>/install.sh status # links, config, cloudflared, daemon, port, token TTLs
<skill-dir>/install.sh uninstall # unload daemon, remove our symlinks; keeps config and tokens
--bin-dir DIR (default ~/.claude/bin) and --no-daemon are the only flags. Any CF_ACCESS_* knob set in the environment is written into the plist — CF_ACCESS_HOLD=60 ./install.sh — and later plain re-runs preserve it. This matters because launchd hands the daemon nothing else: a knob that is not in the plist has no effect on it. Installs are symlinks, so editing a script in the skill directory is live immediately — but the daemon holds the old code until it restarts:
launchctl kickstart -k gui/$(id -u)/local.cf-access-proxy
This matters when the preload and proxy change together: a header the new preload sends is only stripped by a new enough daemon. Restart as part of updating, not after.
Requires cloudflared (brew install cloudflared) and node. Then one interactive step:
cf-access login
Config
~/.config/cloudflare-access/ — three files, all optional except as noted:
| File | Purpose |
|---|---|
apps | app origins login/list operate on. Origins only, no paths |
hosts | domain suffixes the proxy will forward to. Required for the proxy — with no hosts file nothing is allowed, and the preload patches nothing |
proxy | optional fixed ports: <port> <upstream-origin> per line, hot-reloaded (polled every 2s, no restart). A trailing # label names the route, for clients that cannot name themselves |
browser | optional: an account address (resolved to the browser profile signed in as it) or a command that opens the SSO page — for sending work SSO to a work profile instead of the default browser. CF_ACCESS_BROWSER overrides it |
hosts holds suffixes rather than apps so an app added under the domain next month needs no configuration. It is also the allowlist that keeps the dynamic port from being an open forwarder on loopback — only put domains you own in it.
Broker subcommands
| Command | Purpose |
|---|---|
cf-access token [--no-login] <app> | print a valid JWT, refreshing if under 10 min of life. --no-login never opens a browser (for scripts) |
cf-access cookie <app> | CF_Authorization=<jwt>, for tools that want a cookie |
cf-access env <app> <VAR> -- <cmd…> | exec cmd with VAR=<jwt> — the MCP-launcher form. env(1), so VAR may contain hyphens |
cf-access curl <url> [args…] | curl with cf-access-token: injected |
cf-access login [<app>…] | refresh stale tokens; default is every app in apps |
cf-access list | remaining lifetime per configured app |
cf-access browser | the browser command SSO will use, after resolving an account address |
Which browser opens SSO, and the URL as a fallback. cloudflared has no --no-browser flag, but when it cannot exec an opener it prints the login URL and waits for the callback. Every login therefore runs it with the opener hidden, which buys two things: the URL is always reported, so a browser that never appears is no longer a dead end —
cf-access: if no browser opens, log in here:
https://<team>.cloudflareaccess.com/cdn-cgi/access/cli?...
— and browser / CF_ACCESS_BROWSER decides who receives it. Every login opens on the local page below and logs one sso line, direct calls included. Except at a terminal (stderr is a tty): you already know who asked, so the browser goes straight through. Three forms:
| Value | Meaning |
|---|---|
| unset | the platform opener (open, or xdg-open off macOS) — the default browser |
[email protected] | the profile signed in as that account, in whichever Chromium browser has it |
open -na "Google Chrome" --args --profile-directory="Profile 2" | any command; the URL is appended |
Prefer the account address. --profile-directory wants the profile's folder name (Default, Profile 2), which is opaque and does not change when the profile is renamed — so naming the account is both clearer and rename-proof. Chrome, Chrome Beta/Canary, Brave, Edge, Vivaldi and Arc are searched in that order; CF_ACCESS_BROWSER_APPS replaces the list (App Name:support-dir per line, relative to ~/Library/Application Support) to reorder it or pin one browser. An address matching no profile warns and falls back to the platform opener rather than failing the login.
cf-access browser prints what will actually be used. If open -na gets swallowed because the browser is already running, use its binary directly: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --profile-directory="Profile 2".
Two details worth knowing, because both look like bugs otherwise: an app URL is truncated to its origin (cloudflared caches per hostname, a path would miss the cache), and login clears the cached token first — cloudflared access login otherwise hands back the cached token even seconds from expiry. The cleared token is stashed and restored if the login fails.
Proxy behaviour
- Dynamic port (default
8780): the upstream comes from anx-cf-access-upstreamheader (x-cf-access-schemefor http). One listener covers every allowed host, so a new app needs no route entry. A bareGET /answers400 missing x-cf-access-upstream— that is the health checkinstall.sh statususes. - Gating is learned, not configured. The first request to an origin goes out bare; only a redirect to
cdn-cgi/access/loginproves a token is needed. Non-gated hosts therefore never trigger an SSO attempt, and a newly gated host starts getting tokens on its own. - A client's own credential wins. A request already carrying a service token (
CF-Access-Client-Id+CF-Access-Client-Secret), acf-access-token, or aCF_Authorizationcookie is forwarded untouched and triggers no SSO. Only if Access rejects it does the broker step in and retry — so a working credential is never overridden, and a broken one still gets service. - No request ever waits on a human indefinitely. A request holds for at most
CF_ACCESS_HOLDseconds (default 20, under the usual 30s client timeout) and is then answered511, while the login keeps running in the background — so the client's retry lands on a token.CF_ACCESS_HOLD=0never waits at all. A mint that wedges is abandoned afterCF_ACCESS_LOGIN_DEADLINE(default 120s); the proxy stops waiting on it whether or not the child can be killed, becausecloudflaredignoresSIGTERMand holds its pipe open. - No login waits on a human indefinitely either.
cf-accessitself abandons an unanswered browser SSO afterCF_ACCESS_LOGIN_DEADLINE, killingcloudflaredand its children (SIGKILL, andpkill -Pfor the grandchild that holds the pipe). The bound is in the broker, so it protects every caller — a shell,cf-access envlaunching an MCP server, the proxy — not just the proxy. A stashed token is put back when the login is abandoned. - Every browser window says what caused it. One line as the proxy decides SSO is needed:
sso https://ci.example.com GET "/api/jobs"?… ← "pid=8123 ppid=8100 server.mjs" session="<uuid>"
The only signal a round-trip happened — token ok covers cached reads too. Fires before the attempt; a failure follows as token FAILED.
The window opens on a local page naming app, session and trigger, linking on to Cloudflare. Not an iframe: the IdP sends X-Frame-Options: DENY.
A direct call names itself — cf-access curl pid=… ppid=…, session from CLAUDE_CODE_SESSION_ID — into the same log, so one grep sso covers both.
The session name comes from the desktop record (matched on either id), else the CLI's name; with no title yet, its worktree or directory. A coarse name beats a uuid.
Path only, never the query string. Identity is x-cf-access-client + x-cf-access-session; a fixed-port client can send neither, so its route answers instead — fixed port 8790 ("admin panel MCP"), or peer :<port> unlabelled.
- Renewal. Tokens are cached per origin until 10 min before expiry, minting is single-flight (a stampede collapses into one mint), and a browser login is rate-limited to once a minute so a burst of failures cannot stack up tabs. Single-flight is also what makes the trace honest: the request that creates the mint is named, and the ones that join it are not — they did not cause the window.
- Request bodies are buffered so a token retry replays the request byte-for-byte.
- Status codes it originates:
511no token available (runcf-access login <origin>),403host not inhosts,508the upstream is the proxy itself,502transport error,400missing upstream header.
Wiring an MCP server
Pick by lifetime. A server that is spawned per session and dies with it can take the token at launch; one that runs for days must go through the proxy.
Per-launch token — the client reads a header from env at startup:
{
"mcpServers": {
"internal": {
"command": "/absolute/path/to/bin/cf-access",
"args": ["env", "https://ci.example.com", "TOOL_HEADER_cf-access-token", "--",
"node", "/path/to/server.mjs"]
}
}
}
MCP configs generally do not expand ~ or $HOME — write the absolute path.
Proxy, no server changes — the server keeps its real URL, the preload reroutes it:
{
"mcpServers": {
"internal": {
"command": "node",
"args": ["/path/to/server.mjs"],
"env": {
"NODE_OPTIONS": "--require /absolute/path/to/bin/cf-access-preload.cjs",
"SERVER_API_URL": "https://ci.example.com"
}
}
}
}
For a non-Node client, give it a fixed port instead — 8790 https://ci.example.com # the CI dashboard in ~/.config/cloudflare-access/proxy, then point the client at http://127.0.0.1:8790. Label the line: it is the only name that traffic gets.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
client gets a 302 to cdn-cgi/access/login | no token, or the client never went through the proxy | cf-access login <origin>; check the client is Node (the preload only patches Node) or give it a fixed port |
511 no token for <origin> from the proxy | SSO needed and not possible headlessly | cf-access login <origin> in a session with a browser |
403 <host> is not an allowed upstream | host missing from hosts | add the domain suffix; no restart needed — the proxy and already-running preloaded clients both pick it up within 2s |
508 … is this proxy | an upstream origin points back at a proxy port | fix the proxy route or the client's URL |
token FAILED in the log | login failed, or inside the 60s cooldown | run cf-access login <origin> by hand and watch it |
| worked yesterday, dead today | token expired in a process that snapshotted it | move that client to the proxy or the preload |
an MCP server times out at exactly its client timeout (30s), repeatedly, while curl to the same host is fine | the client is being held behind an SSO the proxy cannot complete headlessly | check the log for is Access-gated — minting a token with no token ok after it; run cf-access login <origin> once, then retry. Lower CF_ACCESS_HOLD to fail faster |
log says client credential rejected by Access | the client's service token is not on the app's policy (Access reports service_token_status: false on its login page) | fix the service token in Cloudflare, or accept the broker fallback — but know the client now depends on a browser token |
an sso line but no window | the org session was warm, so cloudflared minted silently — no human needed. A token ok for the same origin follows within seconds | none |
| a browser window appeared and you don't know who asked | — | the window names its cause; after the fact grep sso ~/Library/Logs/cf-access-proxy.log |
the trace says peer :<port> | a fixed route with no label; otherwise not Node, or undici/node:http2, which the preload does not patch | label the route in proxy; else lsof -nP -iTCP:<port> while the request is open |
| a client you never wired is going through the proxy | NODE_OPTIONS is set globally (e.g. in ~/.claude/settings.json), so every Node process is patched | intended for blanket coverage; scope it to one client's env if you want it narrower. The sso trace names which client it was |
cf-access list shows no token right after a successful login | login was for a different origin (path or scheme mismatch) | use the exact origin, no path |
| no browser window appears during a login | wrong or swallowed opener command | open the URL the login printed; then fix it with cf-access browser as the check |
| SSO opens in the wrong browser profile | browser names a command or an account whose profile lives elsewhere | set it to the work account address; confirm with cf-access browser |
| daemon keeps restarting | node/cloudflared not on the daemon's PATH | re-run install.sh (it writes the plist with the detected node) and read ~/Library/Logs/cf-access-proxy.log |
Rules
- A JWT is a bearer credential for a whole app. Never print one into a shared transcript, a commit, an issue, or a log. Pass tokens by env or header;
cf-access tokenexists for piping, not for pasting. - The log is world-readable, never rotated, and written by both proxy and broker, so what reaches it is an allowlist, never a dump: pid, script name, session id, route label, request path. Never argv, environment values or headers — the proxy holds the client's
CF_Authorizationat that point. Wire values are quoted and bounded; a session id not shaped like one is dropped, not escaped at every use. - Never widen
hoststo a domain the user does not control — every entry is a host the loopback proxy will forward to on behalf of anything running as the user. - The proxy binds
127.0.0.1only. Do not change that, and do not add an auth-free route to a host outside the user's org. - Do not hand-edit files in
~/.cloudflared/— they are cloudflared's cache, keyed by the token's ownaud. cf-access loginis interactive by design: it opens a browser tab and the user completes SSO. In a headless or CI context usetoken --no-loginand fail loudly instead of hanging.- Diagnose with
install.sh statusbefore touching anything; it distinguishes "no token", "daemon down", "host not allowed", and "not installed", which produce very similar client-side symptoms.