Expand description
The browser sign-in of a headless srv that serves its own UI (--frontend-dir) on loopback:
the /auth/* routes, the check that admits a browserβs session in auth_middleware, and the
headers of the served UI. The sessions themselves are in super::local_session.
Every answer to a failed sign-in route is the same 403 not accepted, after the same short wait,
whatever was wrong; the reason goes to the log only, never the secret.
The routes are registered here, not in routes.rs: they authenticate themselves (a container
token never reaches them: its listener refuses a path with no audience).
StructsΒ§
- Code
Body π - Confirm
Body π - Handle
Body π - Hello
Body π - Shape π
- What the running server accepts: set once the web listener is bound.
EnumsΒ§
ConstantsΒ§
- COOKIE_
ONLY_ πGET - Routes that take the cookie alone: GETs that change nothing and that an element loads by URL.
The UI fetches every file with its headers, so none needs it; each entry added here is a
reviewed decision, and the test in
tests/local_session_route_tests.rsholds it to a GET route. - COOKIE_
PREFIX π - The cookieβs name is this, then the instance id.
- ENTER_
CSS π - ENTER_
HTML π - ENTER_
JS π - The code is in the fragment. The history entry loses it before anything is sent; the page then
waits for the personβs answer in the terminal and keeps the token in
sessionStorageonly. A page opened with no code (a visitor with no session, or a browser that was disconnected) says how to open AgentMux and is no refusal: it is the same words for everyone and tells nothing about the server. - FAILURE_
DELAY π - A refused sign-in waits this long before it answers, in an async sleep.
- MAX_
DELAYED π - At most this many refusals wait at once; beyond it a refusal answers at once.
- TOKEN_
HEADER π - The per-tab token on a fetch.
- WAIT_
HOLD π - How long a waiting pageβs request is held before it asks again.
- WS_
PROTOCOL π - The protocol srv selects on
/ws; the other protocol the page offers is the token.
StaticsΒ§
- CHANNELS π
- SHAPE π
- SHUTDOWN π
- What ends the server: the token the signal handlers cancel.
agentmux stopon Windows, which has no signal to send, asks for it through/auth/shutdown. - STORE π
FunctionsΒ§
- admit_
session π - Does this request come from a live browser session?
HostandOriginexact, and the cookie and token (or the cookie alone where listed, withSec-Fetch-Site: same-origin). - channel_
gate π openand the other commands: the shape of a non-browser caller, and a request that proves the caller holds the key on a channel it began withhandle_hello. The key itself is never sent, and is not accepted on these routes.- channels π
- check_
shape π Hostis exactly an allowed one,Origin(where sent) is exactly an allowed origin, andSec-Fetch-Sitesuits the kind. A missing or unreadable header counts as wrong.- content_
security_ πpolicy - The policy of the served UI and the sign-in page.
'unsafe-inline'for styles only: the terminal and layout set inline styles.'wasm-unsafe-eval'lets the code highlighterβs WebAssembly engine (Oniguruma, in shiki) compile and nothing else: scripts still come from this origin only, andevalof text stays refused.base-uri 'self'lets a library resolve a relative address against a base on this origin (the drag-preview picture does, for the fonts) and no other. - cookie_
value π - enable π
- Turn the sign-in on, once the web listener has its port. Only for a headless srv that serves a UI.
- enabled π
- handle_
code π POST /auth/code: a new one-time code.- handle_
confirm π POST /auth/confirm {code, accept}: the personβs answer for the session that code made. An accept is taken only from a process found outside every agentβs process tree; one from an agentβs tree, from a process that cannot be found, or through a proxy is not taken (the answer says what works). Every accept, taken or not, is recorded with how it arrived (super::confirm_peer).- handle_
enter π POST /auth/enter {code}: spends the code and makes a pending session; the answer is the handle to wait on and the check phrase to show. The session has no access yet.- handle_
hello π POST /auth/hello {nonce}: srv proves toopenthat it holds the key and which address it is bound to, beforeopensends anything else. It asks for no secret, so anyone may call it; what it returns proves only what srv holds, and is made for this callerβs nonce alone.- handle_
logout π POST /auth/logout: end every browser session.- handle_
page π GET /auth/enter: the page. It holds no secret; the code is in the fragment, which is never sent.- handle_
pending π POST /auth/pending {code}: what became of the codeopenminted.- handle_
script π - handle_
sessions π POST /auth/sessions: how many browsers are signed in now, and how each recent confirm arrived (when, the sessionβs check phrase, how). Nothing that names or reaches a session.- handle_
shutdown π POST /auth/shutdown: end the server, as a termination signal does. The answer is sent first; the server leaves a moment later, by the same path as the signal (every request in flight and every agent is closed as it is then).- handle_
signout π POST /auth/signout: end this browserβs session, and no other. It takes the session pair like any route of the UI, from a same-origin fetch of the page; srv also tells the browser to drop the cookie.- handle_
signout_ πall POST /auth/signout-all: end every browser session, this one included, and clear the file that keeps them across a restart. It takes the session pair like any route of the UI, so a signed-in person can end every sign-in without a shell on the machine.- handle_
style π - handle_
wait π POST /auth/wait {handle}: held until the person answers in the terminal. A confirmed session is handed over once, here: the cookie inSet-Cookieand the token in the body.- hval π
- is_
websocket_ πroute - The routes a browser opens as a WebSocket, which can carry no header: the token travels as a protocol.
- no_
store π - proved π
- A 200 answer that carries the proof of the channel for the request it answers.
- refusal π
- refuse π
- The same 403 for every refusal, in the same time: the wait is the same for every reason.
- route_
class π - How a route takes a session. Every route needs the cookie and the token, except the GETs named
in
COOKIE_ONLY_GET. - routes π
- The
/auth/*routes. - session_
ended π - Completes when the browser session behind a WebSocket ends; never for a connection that came with the key.
- session_
token π - The token a request carries:
X-AM-Session, or on a WebSocket route the protocol offered besideWS_PROTOCOL. - set_
shutdown π - Give the shutdown route the token that ends the server.
- sign_
in_ πexists - Whether something here can vouch for a browserβs connection as the personβs: this srv serves its own sign-in, or a browser has signed in.
- store π
- ui_
headers π - Middleware for the served UIβs files.
- ui_
host_ πok - Is the UIβs file asked for on an address this server serves? The files hold no secret, but a name that is not the serverβs own (a DNS-rebinding page, a stray alias) gets nothing from it: the same rule as the sign-in and API routes.
- with_
ui_ πheaders