ADR-0042: A generated application as a local product: one origin, a first run, and the tailnet¶
Status: Accepted Date: 2026-10-18 Deciders: Alex Nodeland
Makes make up in a generated application give a working portal with chat, on the stack as it runs on one machine, and reachable from a person's other devices on their tailnet. Amends ADR-0038, whose portal signed in to Supabase from the browser.
Context¶
ADR-0038 put portalr in the template, and the smoke test runs it, but a person following the README hit four walls, found by generating an application and running it beside a stack on one machine:
- The UIs weren't served.
.env.examplehas an emptyPORTAL_UI_DIR, formake serve.make envcopies it to.env, Compose'senv_fileputs it in the container, and the empty value replaced the image's/ui, so/portalr/app/answered "this UI isn't built". The smoke test wrote its own.envand never saw it. This is a fix, not a decision: Compose setsPORTAL_UI_DIRover.env, as it setsAPP_HOST, and the smoke test now writes its.envover.env.example. - The browser signed in to Supabase directly, at
PORTAL_SUPABASE_URL(http://127.0.0.1:54321). From another device that address is the device's own, and on stackr's PostgreSQL adapter there is no Supabase gateway at all: GoTrue alone serves/token, not the/auth/v1/tokensupabase-js asks for (scripts/smokeskipped the portal's scenarios there for this reason). - A new person has nothing. Signing in works, and then the app says "There is no workspace here you can open": no tenant, no operator, and no workspace. A workspace is listed when grantr knows it, which it does once something is granted on it. Getting there took a user made through the admin API,
make operator,make tenant, and a grant through grantr's API. - Reaching it from another device needs an address other than
127.0.0.1, and the owner's rule is that local stacks bind127.0.0.1only, never the LAN by default, never the internet.
Decision¶
- The portal signs in on the application's own origin.
PORTAL_SUPABASE_URL=/, now.env.example's default, makesconfig.jsonname this origin, and the application passes Supabase Auth's three sign-in calls on:POST /auth/v1/token,GET /auth/v1/userandPOST /auth/v1/logout, the ones portalr's UIs make and the only ones a single host's edge passes (ADR-0038). It matches them by path and method as routes, so nothing else under/auth/v1is served: not the admin API, not sign-up, not a changed user. The upstream URL is a constant per route, never built from the request's path, so no spelling of a path reaches another one, the failure ADR-0038's edge found in its first version. It sends the query, the body and three headers (apikey,authorization,content-type), and returns the status, the body and two headers (content-type,cache-control); none is logged. The upstream is where the deployment's commands find people,AUTH_ADMIN_URLorAUTH_ISSUER:stackr.envnames local Supabase's gateway on the stack's network, andSTACK_AUTH_ADMIN_URL=http://gotrue:9999names GoTrue on the PostgreSQL adapter. The browser then reaches one origin, so the content security policy'sconnect-srcis'self'alone, and there is no CORS. An absolutePORTAL_SUPABASE_URLstill works as before, and a single host's overlay still sets one,https://app.<domain>, where the edge passes the calls itself. - The three calls are passed on as Supabase Auth would answer them, and no more. They are unauthenticated by design, as Supabase Auth's own are: the token call is how a person gets a token. A body over 64 KiB is refused (413) before anything is sent. The client's address isn't forwarded, so GoTrue's rate limits on sign-in count every person reaching the application as one, which on a tailnet is the people a person shares it with.
- The portal reads a workspace's tracker items on this origin. With a tracker, the application mounts relayr's tracker reads at their own
/relayr/v1paths, and the portal'sSitenames them (Surfaces(relayr="")), so the app shows what a workspace filed. relayr'stracker_reads_routerresolves who asks as reflexr's routes do:automation.py's resolver, once private, is now its publicresolve_actor, whichtracking.pyis given. make first-run EMAIL=...is the first person in, a command over the pieces the template had (first_operator,provision_tenant,grant). It makes the person's account in Supabase Auth if they have none, through the admin API with the email confirmed and a password it asks for twice and never shows; makes them the deployment's operator if it has none; creates a tenant they own (TENANT,homeby default); and gives them a workspace in it to administer (WORKSPACE,main) if they can't open it yet, which names the workspace to grantr, so the app lists it. Each step is skipped once done, so it can run again, and it repairs a tenant made without the workspace.EMAILmay be an existing user's id instead, for whom no account is made.make tailnetserves the application on the machine's tailnet name, over HTTPS, withtailscale serve, for the tailnet only: nevertailscale funnel. One handler,/to the application on127.0.0.1, is all it needs, since the portal signs in on the application's own origin. It changes the one HTTPS port it is given (TAILNET_PORT, 443), refuses a port something else is served on, or that Funnel puts on the internet, andmake tailnet-offremoves only what it set up there, Funnel included if someone turned it on. tailscale's own output is shown, since it says when the machine must first allow Serve or HTTPS. It finds the CLI on the PATH or in the macOS app, and installs nothing. Its ports stay on127.0.0.1: Tailscale reaches them there.
Amended (2026-10-27) by portalr ADR-0084: one handler is no longer all it needs. The tailnet name is a second portal origin, and mini apps and the editors are origins of their own beside it, so
make tailnetalso serves mini apps' port (wherePORTAL_APPS_URLnames it) and each running editor's, each on the same port there as on127.0.0.1, tailnet only. It plans every port first and changes none unless each is free or already its own: a site, a TCP forward or Funnel on any refuses the whole plan, port 8443 is never in it, and a failedserveremoves only the ports that run added. It writes one key to the application's.envin place, mode kept,PORTAL_EXTRA_URLS=https://<name>[:<port>], whichmake tailnet-offremoves (refusing to replace a value set by hand), and says to runmake up. The template reads it (origins(..., canonical=PORTAL_URL)), givesSitethe portal'soriginand an alias beside each other origin (beside), and tells the sandbox and each editor every portal origin.AUTH_SITE_URL, and with it email links, is left alone.
Options considered¶
Where the portal signs in¶
| Option | For | Against |
|---|---|---|
| The application passes three calls (chosen) | One origin wherever the application is reached; works with GoTrue alone; no setting changes between this machine and a tailnet | The application carries a small proxy, which its tests hold to the three calls |
| The browser calls Supabase directly (ADR-0038's local default) | Nothing in the application | Breaks on every origin but this machine's, and on the PostgreSQL adapter |
tailscale serve maps /auth/v1/... to Supabase |
No code | Only on the tailnet, only with Supabase's gateway (GoTrue alone has no /auth/v1), and this machine's own origin still needs another answer |
| Caddy in front of the application locally, as on a single host | The edge's tested allow-list | A second service and a second port for every local run |
The first person in¶
| Option | For | Against |
|---|---|---|
| A command, over grantr's existing pieces (chosen) | Deliberate; runs again safely; no request path changes | A terminal step before the first sign-in |
| The first person to sign in becomes the operator and owner | No step at all | Whoever signs in first owns the deployment, and every request pays a check for a moment that happens once |
| A configured email is claimed at its first sign-in | No terminal step after configuring it | A check on every request's path for the same once, and the account still has to be made, which the UIs don't offer: they sign in only, and an invitation's link has no page to set a password |
Reaching it from other devices¶
| Option | For | Against |
|---|---|---|
tailscale serve (chosen) |
The tailnet's own identity and HTTPS; nothing binds beyond 127.0.0.1; installs nothing |
Needs Tailscale on the machine and the devices |
APP_BIND=0.0.0.0 |
Already there | The LAN, unauthenticated, and plain HTTP |
tailscale funnel |
Any device | The internet: never |
Consequences¶
- Easier: a generated application, beside the stack on either adapter, goes from
make upandmake first-runto a signed-in portal with chat, on this machine and on a tailnet, with no setting changed between them. - Easier: the portal's scenarios could run on the PostgreSQL adapter too, which
scripts/smokestill skips; that is left for later. - Harder: the application now proxies three calls, which its tests pin, and which must follow supabase-js if portalr's UIs ever make another.
- Not done: invitations still go to Supabase's gateway (
PORTAL_AUTH_URL), so they don't work with GoTrue alone, and an invited person has no page to set a password; WordCraft's editor isn't in the template yet, and when it is, its own origin needs a second tailnet port (portalr ADR-0049).
Amended (2026-10-28) by portalr ADR-0088: connected apps' links (
Site.links,PORTAL_LINKS) are beside each other origin by the same port-sibling rule as the editors, andmake tailnetserves each loopback link's port beside the portal, tailnet only, never 8443;deploymentAtmoved to@portalr/client, and returnslinkstoo.