# Exposing a local app to outside testers (Cloudflare Tunnel) Use when a local web app (often one whose backend calls a local Hermes API-server profile) must be reachable by a few named people at `.` without moving it to a host. Static sites go to Pages instead; a tunnel is only for apps that need the Mac. ## Order 1. **Separate instance.** Build the public variant in its own worktree and run it on its own port bound to `127.0.0.1`, so the demo/dev instance is untouched. Copy `.env.local` file-to-file (`cp`), never read it. 2. **App-side gate behind an env flag** (`_ACIK=1`), because Cloudflare Access may be disabled on the account: - access-code screen -> server-side check -> signed httpOnly, Secure, SameSite=Lax cookie; every page AND every `/api/*` returns 401 without it; - per-IP limits keyed on `CF-Connecting-IP` (wrong codes/min, requests/min); valid only because the app listens on loopback and the tunnel is the sole ingress; - a persistent daily model-call quota in a file outside the repo, reset at local midnight, safe under concurrency; run exactly ONE process on that file; - model/options never taken from the client; length caps; errors that leak nothing; CSP + frame-ancestors + Referrer-Policy; robots disallow; dev pages 404. - Keep the code in `~/./erisim.kodu` (mode 600) and start with `ACCESS_CODE="$(cat file)"`. The code is meant to be shared, so giving it to the user in chat is fine. 3. **Tunnel via API (remotely managed)**, keys passed only into that command's environment by your secret manager (e.g. ` -m -- `), never printed, and unset after: - `POST /accounts/{A}/cfd_tunnel` `{"name":..,"config_src":"cloudflare","tunnel_secret":}` - `PUT /accounts/{A}/cfd_tunnel/{TID}/configurations` ingress: `[{hostname, service:"http://127.0.0.1:"},{service:"http_status:404"}]` - `GET .../{TID}/token` -> write to `~/./tunnel.token` with `umask 077`; never print. - DNS: `POST /zones/{Z}/dns_records` CNAME `` -> `.cfargotunnel.com`, proxied. A DNS record with no running connector exposes nothing. - Token scopes differ per key: an account token may do tunnels/Pages but not zone DNS; a separate DNS key may list/edit records but not Rulesets (redirects). Probe each key read-only before asking the user for more scope. 4. **Security review before starting the connector** (security reviewer, context-only brief: release type, what changed, where, form/user data). Typical blocking finding: privacy text claiming chats are not stored while the Hermes API-server profile records every request in its `state.db` and forwards it to the model provider; make the text match the real data flow. Start the endpoint profile from an empty working directory so no local instruction files end up in its system prompt. 5. **Run the connector:** `cloudflared tunnel --no-autoupdate run --token "$(cat tokenfile)"`. `launchctl bootstrap` is refused from inside the gateway, so start it as `terminal(background=true, persist_on_release=true)` and give the user the one-line `launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/