Expand description
The Actor request guard: the authenticated initiator of a mutating request.
Identity is tokens-first (no OAuth on the critical path). A request carries a rerun token via
the X-Cortex-Token header or a ?token= query parameter; the guard resolves it to an owner
through config().auth.rerun_tokens, or fails the request with 401. Mutating routes take an
Actor so the initiator is threaded into the owner of every write (attributable actions —
the observability mandate) and so writes are denied by default (an empty token map rejects
everyone, rather than letting anyone wipe results).
Structs§
- Actor
- The authenticated initiator of a mutating request, resolved from a rerun token.
- Actor
Carriers - The raw credential carriers on a request, extracted without any lookup (cheap, sync): the
bearer token (the
X-Cortex-Tokenheader or?token=query) and theADMIN_COOKIEsession cookie. The audit fairing extracts these synchronously so it can resolve them to an owner off the response path (the cookie now needs a DB session lookup — seeresolve_carriers). A token in a POST form body (the un-signed-in human forms) is deliberately not visible here. - Admin
Session - A signed-in admin’s browser session — the
Actor’s counterpart for the human admin UI. TheADMIN_COOKIEcookie carries a random opaque session id (not a credential); this guard resolves it against the server-sidesessionstable on every request, so sign-out (which deletes the row) immediately ends the session and a forged cookie is a useless random id. Established by the admin token or a passkey at sign-in. Gated admin screens take anAdminSession; an unauthenticated browser is sent to the sign-in page (handled per-route viaOption<AdminSession>). - Return
To - The current request’s path + query, captured for the
?next=return-to-after-login flow on gated GET screens. An infallible request guard (always succeeds).
Enums§
- Admin
Reject - The rejection of an admin-gated human screen: either a redirect to the sign-in page (the
browser isn’t signed in) or a genuine error status (e.g.
404unknown resource,503pool exhausted). This lets a gated page keep its real error cases while sending an unauthenticated browser to sign in — rather than showing it a bare401. The agent APIs are unaffected: they keep the token-basedActorguard, so a machine still gets a clean401, not an HTML redirect.
Constants§
- ADMIN_
COOKIE - The cookie carrying a signed-in admin’s session token (set by the
/admin/loginpage).
Functions§
- actor_
carriers - Extracts the
ActorCarriersfrom a request (no lookups). - owner_
for_ token - Resolves a rerun token to its owner, mirroring the
Actorguard’s lookup. For form-based human submissions (a<form method=post>token field), where the guard — which only reads theX-Cortex-Tokenheader or?token=query — can’t see a token in the request body. - require_
admin - Requires a signed-in admin for a human screen, else a redirect to the sign-in page. The
first line of every admin-gated page handler (which returns
Result<Template, AdminReject>): a handler’s existingStatuserrors convert through?(seeAdminReject’sFrom<Status>), so it keeps its real404/503while unauthenticated browsers are bounced to/admin/login. - require_
admin_ to - Like
require_admin, but for a GET screen: an unauthenticated browser is redirected to the sign-in page with a?next=pointing back atreturn_to, so it lands here again after signing in. - resolve_
carriers - Resolves
ActorCarriersto an owner: the bearer token against the configured admin tokens, the session cookie against thesessionstable (hence theconnection). The token wins if both are present (an explicit API credential is the more specific intent).Noneif neither resolves. - safe_
next - Validates a post-login
nextdestination: the path if it is a safe local path, else/admin. - sign_
in_ url - Builds the sign-in URL:
/admin/login, with?bad=truewhen a previous attempt failed and&next=<encoded>whennextis a safe local path to return to after login (open-redirect guarded — a non-localnextis dropped).