Files
ai-agent/docs/remote-access.md
gabrielvidalandClaude Opus 5.5 bfcb3d3b3b fix(remoteaccess): what the security review found — revocation that revokes
- removing a passkey ends every session it opened (sessions record the id);
- an open Chrome view on the internet address re-checks its session every
  5 s and closes when it ends (sign-out, passkey removed, access off);
- Sign out there always ends the owner's session unless the guest cookie
  beside it is a live impersonation — a cookie a guest's *.gabvdl.xyz site
  planted can no longer turn it into a no-op;
- the passkey link and "back on" need Authelia on the admin host, not just
  "not the internet address": the host token / loopback (what a run started
  from a stolen session can call) are refused; making a link now pushes;
- switching internet access off cancels an open link;
- ceremony tickets capped per address (10) so one address can't drain them;
- docs: what the off switch can't undo (the owner is a shell).
- 13 regression tests (test_remote_access: 51).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 15:19:41 +01:00

113 lines
6.2 KiB
Markdown

# The owner's internet address (`backend/remoteaccess/`)
Since 2026-11-24. Gabriel's work Mac has to sit on his employer's tailnet, so
it can't reach the admin host (`ai-agent.lab.gabvdl.xyz`: the personal
tailnet + Authelia). His phone stays on the personal tailnet; **the Orus Mac
is the one device this is for.** Decided in form
`owner-sign-in-on-hub-gabvdl-xyz-v2_iv6s9t`.
## What it is
`OWNER_HOSTS` (homelab: `hub.gabvdl.xyz`) is a host on which the whole app
answers **as the owner**, with no Authelia in front. On it:
- the **only** credential is the owner's own session cookie,
`__Host-aia_owner` (host-only, `Secure`, `HttpOnly`, `SameSite=Strict`),
opened by a **passkey**. `Remote-User`, the host token, a read-only key, a
guest's cookie or where the request came from make nobody the owner there
(`core/auth.py` returns before any of those is looked at). Without a session
only the `public` routes answer — the sign-in.
- a session ends **7 days** after the sign-in however busy it is
(`OWNER_SESSION_TTL_S`; `OWNER_SESSION_IDLE_S` can end it earlier when
unused, default off). Then a passkey again.
- the owner's **impersonation** of a guest works as on the admin host (the
guest cookie with `imp` decides, under a live owner session).
- what serves machines — `/proxy/`, `/worker-link/`, `/mcp`, `/oauth/` — is
refused there (Traefik's `ai-agent-owner-machines` router, and the backend
treats the host as public: an owner worker's proxy token is refused).
## Why the hub's own passkey, not Pocket ID
Pocket ID (the guests' login) was the first idea. It isn't enough for the
account that is a shell on the lab:
- Pocket ID mails a sign-in code (`EMAIL_ONE_TIME_ACCESS_AS_UNAUTHENTICATED_ENABLED`
— the guests need it), and **any Pocket ID session, a mailed-code one
included, may enrol a passkey** (scope `account:passkeys:enroll`, v2.19.3).
So whoever reads the owner's mailbox adds their own passkey and passes a
"passkey only" (`amr: phr`) check.
- Any Pocket ID admin compromise can mint a login code for any account — and
Pocket ID had 18 security advisories in 2026, six high/critical.
So the hub checks the passkey itself (`remoteaccess/webauthn.py`, ~200 lines
on `cryptography`, no library): ceremony type, the server's one-time
challenge, the exact origin `https://<host>`, the RP ID hash, *user present*
**and** *user verified*, the signature, the sign counter. Attestation is
`none`: a passkey is trusted because of **how it was added**.
## Adding a passkey: a one-time link from the admin host
Settings → Security → Internet access → **Add a passkey** — on the admin
host, **through Authelia** (`Remote-User` from Traefik, the owner): the
backend refuses it on the internet address *and* from host-side callers (the
host token, loopback), which a run started from a stolen internet session
could reach — so such a session can't give itself a lasting way back in → `https://hub.gabvdl.xyz/remote/add-passkey#<token>`:
15 minutes, one use, a newer link voids the older, the token stored hashed
and carried in the fragment (never in a server log). Opened on the device
that will sign in, it creates a discoverable passkey (RP ID = the host) and
signs in. No mail, no recovery code: a lost passkey = a new link from the
tailnet.
## The switches and the alarms
- **Switch internet access off** (Settings → Security, beside *Lock guests*):
every session there is dropped, an open link is cancelled, an open Chrome
view there closes within 5 s, and no ceremony is taken until it is switched
back on — from the admin host, through Authelia, only.
- **Removing a passkey** ends every session it opened (a session records its
passkey's id).
- **What the switch can't do:** the owner is a shell on the lab. A session
that was used before it was cut off may have left anything behind (a cron
job, a key, a changed file) — the switch stops new sign-ins, it doesn't
undo what was done. Treat an unexpected `owner_login` push as a lab
compromise, not a sign-out.
- Pushes (default on): `owner_login` (every sign-in there — IP, browser,
which passkey), `remote_passkey_added`, `remote_passkey_invited`. Logged
too: `owner_login_refused`, `remote_passkey_removed`, `remote_signed_out`,
`remote_locked|unlocked` (filter **Internet** in the log).
- A failed ceremony counts toward the per-address lockout the worker proxies
use (`workers.guests.BadTokens`: 20 in 10 min → refused for an hour) — so
someone behind the same NAT (an office) can lock the owner out for an hour;
accepted. Ceremony tickets are capped per address (10), so a flood from one
address can't evict the owner's.
## The edge (homelab)
- Traefik `ai-agent-owner` router on `websecure` + `public`,
`letsencrypt-http`, `strip-forward-auth-headers` + rate limit.
- raspy2 passes `hub.gabvdl.xyz` through (TLS ends on the homelab) **only for
FR + DE addresses**: the TCP middleware `geo-allow-tcp`, which the
geo-lock tool generates beside its HTTP list. `geo-lock off` removes that
file and the address closes (fails shut). It is noise reduction, not
protection — a VPN defeats it.
- The homelab router has TLS options of its own (`ai-agent-owner`), so a
connection opened for the guest name (not geo-locked) asking for
`Host: hub.gabvdl.xyz` gets 421 — no fronting round the lock.
- The `public` entrypoint trusts PROXY headers from raspy2 and the Docker
gateways only, so a container can't claim a visitor address (which the
lockout and the sign-in pushes rely on).
## API
| route | who |
|---|---|
| `POST /api/remote/passkey/login/options`, `…/login` | anyone, on the internet address only (404 elsewhere) |
| `POST /api/remote/passkey/add/options`, `…/add` | anyone holding a live link, idem |
| `GET /api/remote` | `security.manage` — address, on/off, passkeys, sessions |
| `POST /api/remote/lock` | `security.manage` — on again from the admin host only |
| `POST\|DELETE /api/remote/passkeys/invite`, `DELETE /api/remote/passkeys/{id}`, `DELETE /api/remote/sessions/{id}` | `security.manage`; the link is made on the admin host only |
Tests: `test_remote_access.py` (the gate there, sessions, the switch, the
whole passkey round trip with a software authenticator), `test_webauthn.py`
(every check that must refuse).