ADR 0033 — The orchestrator is an OAuth2 resource server; roles map to permissions ​
- Status: accepted (2026-10-02), on the owner's request of 2026-10-02; the details are the planner's (plan 10, section 3.4) and the owner may revisit them. Owner decision 4 of the same day binds it: admins read every thread and act only on their own; the user key stays the e-mail claim (
sublater). Amends the bullet "Authentication stays at the edge" of ADR 0012 and "The edge owns identity" ofarchitecture.md; closes open question 20 (programmatic clients); replaces slice 14 ofmvp.md(OIDC for MCP). The portInboundAuththat ADR 0009 names is built asAuthenticator. Built (2026-10-02, PR S14): the port and its testkit, the JWT and the header authenticators,auth.modeandauth.jwt, the 401/503 responses and/readyz. Built (2026-10-02, PR S15): the roles and permissions, their enforcement on threads, agents and files,GET /api/me, the administrators' listing, the roles of an MCP token and the bound on a stream (sections 4 to 7, with the points where the build differs from what they planned, in Status: built in S15). Built (2026-10-02, PR S17): the web reads/api/meand follows it (Status: built in S17). Built (2026-10-02, PR S16): the dev stack: a mock issuer, a real oauth2-proxy behind Caddy'sforward_auth, the orchestrator onauth.mode: jwt, tokens in every scenario script anddev/rbac-e2e.sh(section 8, with what the build settled in Status: built in S16). Sections 1 to 3 are what S14 built. Amended (2026-10-03): owner decision 4 ("admins read every thread") and the built-inadminscope of section 4 are superseded by ADR 0039, on the owner's decision of that day ("Admins shouldn't read every thread, it's dangerous and not GDPR compliant"): no role reads or acts on another person's thread, ascopeofanyis refused at startup,GET /api/threads?owner=is removed, andadminis operational and content-free. Everywhere below that says an administrator reads another person's thread, lists everyone's threads, sees a read-only view of another's thread (403 read_only) or has Mine / All threads in the sidebar describes what was built on 2026-10-02 and is no longer so; the rest of this ADR stands. Amended (2026-10-04): the web's answer to a 401 (S17 item 5, S16 item 10) is no longer a redirect first. On the owner's request ("Token refresh should work without a full page refresh") a 401 is now refreshed at the edge and the call sent again, the session is kept warm while the app is open, and only when the edge has none is the person asked, in a popup, with the page kept; the full-page redirect remains for a refused popup. What a 401 is at the edge, why it happened, and what was verified:web/README.md, "Signing in again". The orchestrator, the tokens and the roles are unchanged. Trade-offs of that amendment (2026-10-04; the owner may change them). (1) Idle bound: each keep-warm question after oauth2-proxy's--cookie-refreshis a refresh grant, which resets Keycloak's SSO Session Idle, so a tab nobody uses would keep a session alive for ever. The page therefore keeps the session warm only while the tab is visible and the person has been there (a key, a pointer, a wheel, a touch or a return to the window) in the last 30 minutes (IDLE_LIMIT_MS,web/src/lib/api/session-refresh.ts); a hidden or untouched tab lets the session age out, and the stream's reconnect that meets a 401 still refreshes. (2) A different person: a session that comes back as someone other than the one the page has been (the edge'suserinfosays whose) is never used to send what was held: the held calls are rejected and the page is read again. (3) A request may be sent up to three times (the original, after a refresh, after being held), which is safe because only the identity layer answers 401, before any handler runs, and an agent's own 401 is a 502 (orch-apiauth.rs,problem.rs, and the testtests/only_identity_answers_401.rsthat keeps it so). (4) Assumption: the web-only fix assumes Keycloak's Revoke Refresh Token is off (unverified for this realm); with rotation on, a Redis session store for oauth2-proxy is required. Amended 2026-10-07 by ADR 0054: the orchestrator also takes DPoP-bound access tokens (auth.dpop), the web signs in as a public client of its own, and the edge no longer gates the web whenauth.browseris on. Amended (2026-10-16): how keys and claims are read (section 2), after a review of the platform's port of this checker (aap-auth-oidcinvymalo/another-agentic-platform). The policy of section 2 stands (the four algorithms, the 60 s leeway,iatrequired andemail_verifiednotfalseas they were, the key cache and its bounds); what changes is how the keys and the claims are read. (1) Keys: a JWK member is read as the number it is, not as the text an issuer writes. An RSAnandeby their magnitude (a leading zero or a sign byte is dropped, and the 2048 bits are counted on it), a P-256 coordinate left-padded to its 32 octets (refused when it has more than 32 significant octets or is empty), an Ed25519 key as exactly its 32 octets (a zero in front is a part of it), and the=padding some issuers write is accepted. A key of one of those shapes was admitted and never verified, and an Ed25519 key that starts with a zero octet (about one in 256) was skipped. (2) Every key under a token'skidis tried (a rotation that kept the name, two sets merged), where only the first was. (3)issis one text: a list that holds the issuer, which the library accepts, is refused. (4) The reason is the same every time:issandaudare checked here, after the library has checked the signature,expandnbf, in the orderexp,nbf,iss,aud,iat,email_verified, the user; the library's own required-claims check names the first it finds in the order of a hash set, so a token that lacked several was refused with another reason from one request to the next. (5) The user is somebody: the value ofuserClaimis refused when it holds a control character (Unicode Cc: U+0000–U+001F, U+007F–U+009F; the whole value is looked at, before it is trimmed) as well as when it is blank. (6) Discovery: exactly one terminating/of the issuer is removed before/.well-known/openid-configurationis appended (all of them were). (7) A warning is logged once, at startup, for an issuer orjwksUrlover plainhttp; the URL is not in it, andproductionstill refuses it. (8) The crypto provider ofjsonwebtokenis installed explicitly (aws-lc-rs), so that a second backend linked into the binary cannot make the first verification panic. Behaviour a deployment could see: a token whoseissis a list, or whose user claim holds a control character (Unicode Cc: U+0000–U+001F, U+007F–U+009F), was accepted and is refused; a JWKS key of the shapes in (1), or a second key under a sharedkid, that did not verify now does. Amended (2026-10-16, the key cache of section 2): the fetch no longer holds the lock, and a stale copy is served while it refreshes. Found by the review of the same port, where a good token waited 2.8 s behind a 3 s JWKS: the cache held its lock across the fetch, so one token with an inventedkidmade every request wait behind the issuer, a copy past its refresh interval was not served while a refresh ran, a request dropped mid-fetch cancelled the fetch, andready()could wait on one. The policy of section 2 stands (10 minutes, an unknownkidat most once in 30 s, 5 s after a failure, an hour of grace,Unavailableand never a refusal, the same log lines); what changes is who waits. (1) The fetch runs on a task of its own, one at a time, and the lock is held to read or change the copy and nothing else. (2) A copy older than 10 minutes and within the hour is used at once, and a refresh starts in the background;ready()answers at once while a copy can verify. (3) With no copy, or one past the grace, a request waits for the fetch (bounded: each request to the issuer times out); a token that names an unknownkidwaits for the fetch and no other request does. (4) A request that is dropped does not cancel the fetch, and the keys it brings are recorded. A fetch task that has begun records its outcome however it ends (an answer, a panic, the runtime stopping) and only then wakes its waiters; a task that never ran (its runtime stopped with it still queued) records nothing, its waiters wake and the next request starts a fetch. Behaviour a deployment could see: the first request after a long quiet is verified against the copy it finds, which may be up to 70 minutes old, and the keys an issuer withdrew stop verifying when the refresh is over, not when it starts; a slow or hanging issuer holds up no request that has a copy, and/readyzdoes not wait on it while one verifies. Verified 2026-10-16:tests/slow.rsof the crate, over real sockets, seven of its cases failing on the previous code, and the unit tests ofsrc/lib.rsfor the ways a fetch task ends; the behaviour against a real issuer is unverified. The diagrams of the cache as built are in the crate's README. Amended (2026-11-24): a deployment behind its own BFF reads the user fromsub. Owner decision 4 of 2026-10-02 keeps the e-mail as the chart's defaultuserClaim(email), and this note does not change it. A deployment that puts its own BFF in front of the orchestrator (card ANR-655) turns this chart's web and the edge off and has the BFF present its own token: the person is that token'ssub, the audience names the orchestrator (auth.jwt.audiences: [orchestrator], which the deployment's identity provider issues: card F9, Franck), and the roles still come fromauth.rolesClaim(agentic_roles). Nothing else here moves: the token rules, the claim reading of 2026-10-16 and the 401/503 answers stand, andsubis read as the text it is (blank, or a control character, is still no user). The shape CI renders and has the pinned image read isdeploy/chart/tests/bff-only.values.yaml.
Context ​
The owner, 2026-10-02: "We need RBAC. We'll keep an OAuth2 proxy on top of the web and ensure the backend is an OAuth2 resource server."
What exists (verified 2026-10-02 in the code at dbc136a):
- Identity is the header
X-Auth-Request-Email, read byorch-api(auth.rs), withAUTH_DEV_USERas the fallback. The edge owns identity; the orchestrator "must only run behind a proxy that strips client-supplied copies". - Ownership is
threads.owner, the e-mail (0001_init.sql). There are no roles: everyone who is in is the same. - MCP uses static bearer tokens (
MCP_TOKENS_FILE, ADR 0019); the thread-tools endpoint uses HMAC tokens (ADR 0023). Both are machine routes, outside the identity layer. - A programmatic client (a CLI, CI) has no oauth2-proxy cookie (question 20), and OIDC for MCP was slice 14.
What is wrong with a header. It is a bearer credential nobody signed: any process that can reach the orchestrator without passing the proxy is whoever it says it is. A header carries one fact (the e-mail), so roles cannot ride on it, and a client that is not a browser has no way to present it honestly.
oauth2-proxy facts (verified 2026-10-02, https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview, version 7.15.x):
--pass-authorization-header: "pass OIDC IDToken to upstream via Authorization Bearer header".--set-authorization-header: "set Authorization Bearer response header (useful in Nginx auth_request mode)".--pass-access-token: "pass OAuth access_token to upstream via X-Forwarded-Access-Token header".--skip-jwt-bearer-tokens: "will skip requests that have verified JWT bearer tokens (the token must haveaudthat matches this client id or one of the extras fromextra-jwt-issuers)".--extra-jwt-issuers: "a list of extra JWTissuer=audiencepairs";--oidc-groups-claim: "which OIDC claim contains the user groups".- Caddy's
forward_authhascopy_headers: "a list of HTTP header fields to copy from the response to the original request, when the request has a success status code" (verified 2026-10-02, https://caddyserver.com/docs/caddyfile/directives/forward_auth; that page has no oauth2-proxy example, so the wiring of S16 is a design to be run, not a documented recipe).
Decision ​
1. The port ​
Authenticator is a port of orch-ports (ADR 0009), carried by Ports::Auth and PortSet.auth:
pub struct Credentials<'a> { pub bearer: Option<&'a str>, pub identity_header: Option<&'a str> }
pub struct Principal { pub user: UserId, pub email: Option<String>, pub name: Option<String>, pub roles: BTreeSet<Role> }
pub trait Authenticator: Send + Sync + 'static {
fn authenticate(&self, c: &Credentials<'_>) -> impl Future<Output = Result<Principal, AuthError>> + Send;
fn ready(&self) -> impl Future<Output = Result<(), AuthError>> + Send; // default: Ok
fn accepts_bearer(&self) -> bool; // default: false
}
pub enum AuthError { Missing, Invalid { credential, detail }, Unavailable { detail, source }, NotConfigured }- Fail closed, and say which way.
MissingandInvalidare refusals (401).Unavailableis not one: what the credential is checked against (the issuer's keys) cannot be read, so nobody is let in, but the caller may retry (classTransient, 503 withRetry-After). This differs from the plan's "401 for all requests" while the keys have never been fetched: a 401 would tell a client its token is bad, and make a CLI log in again for nothing. - No error carries a credential, and
DebugofCredentialshides both. A refusal names what is wrong ("the token has expired", "the token is not for this API (issuer or audience)"), never a value. - The API reads the HTTP, the authenticator the credential. The edge turns
Authorization: BearerandX-Auth-Request-EmailintoCredentials(another scheme,Basic, is not a bearer; a header that cannot be read as text is present and empty, so it is refused and never mistaken for absent) and stores thePrincipaland itsUserIdin the request extensions. A 401 carriesWWW-Authenticate: Bearer realm="orchestrator"when the authenticator reads bearer tokens, witherror="invalid_token"when a token was presented and refused (RFC 6750). /readyzfollowsready(): 503 while the keys have never been fetched (or are too old to trust)./healthzdoes not: the process is alive.- Implementations:
orch-auth-header(today's behaviour, moved out oforch-api),orch-auth-jwt(section 2),RefuseAll(a process that serves no routes, and the default ofPortSet: a bundle that forgot to choose lets nobody in) andByCredential(a request with a bearer is the bearer authenticator's alone, and a refused token is never reconsidered as the header; a request without one is the header's). - The testkit has two suites (
authenticator_conformance!, any implementation;bearer_token_conformance!, the policy of signed tokens below) and the in-memoryMemoryAuth.
2. The JWT authenticator (orch-auth-jwt, auth.mode: jwt) ​
sequenceDiagram
participant C as Client
participant P as oauth2-proxy / edge
participant O as Orchestrator (JwtAuth)
participant I as Issuer
C->>P: request (cookie), or a CLI with its own token
P->>O: Authorization: Bearer JWT (the ID token, or the CLI's own)
O->>O: alg allowed? kid?
opt no keys, or older than 10 min, or unknown kid (at most once in 30 s)
O->>I: GET discovery, GET jwks
I-->>O: keys
end
O->>O: signature, iss, aud, exp, nbf, iat, email_verified, user claim
O-->>P: 200 with the Principal in the request, or 401, or 503Amended 2026-10-16: the order and the rules are in the Status block.
stateDiagram-v2
[*] --> NoKeys: the process starts (nothing is persisted)
NoKeys --> Fresh: a fetch gives a usable key
NoKeys --> NoKeys: the fetch fails (not again for 5 s): 503, /readyz 503
Fresh --> Stale: 10 minutes old
Stale --> Fresh: a fetch succeeds
Stale --> Stale: the fetch fails: the copy still verifies
Stale --> NoKeys: older than 10 minutes plus one hourAmended 2026-10-16: who waits for the fetch is in the Status block, and the diagrams as built are in the crate's README.
- Algorithms: RS256, RS384, ES256, EdDSA, and nothing else.
noneand the HMAC family are refused whatever key they name (the algorithm confusion attack), and a key only verifies tokens of its own family; an RSA key under 2048 bits, a symmetric key, a key for encryption or another curve is skipped. - Claims:
issequalsauth.jwt.issuerexactly; one ofauth.jwt.audiencesis amongaud;exp,iat,issandaudare required;nbfis honoured; 60 s of leeway;email_verifiedmust not befalse(boolean or text). A token over 16 KiB is refused unread. Amended 2026-10-16: the order and the rules are in the Status block. - The keys are fetched from
auth.jwt.jwksUrl, or from thejwks_uriof{issuer}/.well-known/openid-configurationwhoseissuermust be the configured one. They are a copy this process may lose (ADR 0001): fetched on first use and byready(), refreshed after 10 minutes, fetched again for an unknownkidat most once in 30 s, not retried for 5 s after a failure, one request for any number of concurrent callers. A copy that cannot be refreshed goes on verifying for one more hour (an issuer's blip is not an outage of the chat); after that,Unavailable. Amended 2026-10-16: the fetch runs on a task of its own and a stale copy is served while it refreshes; see the Status block. - The fetch is bounded: a timeout, no redirect followed, a body of at most 1 MiB, a
jwks_urithat ishttp(s)without credentials and never plain HTTP under an HTTPS issuer. There is no filter on the address: the issuer is the operator's own configuration, an identity provider in the cluster is a private address, and the repository applies no address filter to the registry's or the model's URL either (both refuse redirects; verified 2026-10-02 by search of the adapters). - Identity.
auth.jwt.userClaim(defaultemail, so thethreads.ownerrows that exist stay theirs) names the claim of the user;UserId::newtrims and lower-cases it.subcan be the key later, through a migration (anowner_subcolumn): that lower-casing is wrong for an opaque id, so it is a decision for then, not a default now.auth.jwt.rolesClaimis a dotted path (realm_access.roles,groups; a claim whose own name has dots is found by that name first); a list gives its texts, a text is one role, anything else is none, and a bad roles claim never refuses a token. - Library.
jsonwebtoken11.1.0 overaws-lc-rs(verified 2026-10-02,cargo info; MIT; marked passively-maintained by its author), the crypto backendrustlsalready brings. The decisions above are ours (the allowed list, the key choice, the leeway), not the library's defaults.
3. Configuration and migration ​
auth.mode is proxy_header (the default: nothing changes), jwt, or jwt_or_proxy_header; auth.jwt holds issuer, audiences, jwksUrl, userClaim, rolesClaim (docs/api/config.md).
- S14 ships the port with
proxy_headerthe default. - The dev stack switches to
jwt(S16); production configuration moves tojwt, andjwt_or_proxy_headeris there for one release. proxy_headerremains for one user on a local machine, and is refused whenserver.environmentisproduction(a key that S9 reserved and S14 builds). A production process also refuses anhttp://issuer orjwksUrl: whoever is on the path to it could serve their own keys.auth.devUserexists only withproxy_header.- A mode whose implementation is not compiled in (Cargo features
auth-jwt,auth-header, both on by default) is exit 78 naming the feature (as a surface is). A process that serves no routes needs none.
4. Roles and permissions ​
auth.roles maps a role name to permissions and agents, auth.defaultRole is what a valid token with no known role gets (null: 403). The vocabulary follows the platform's (another-agentic-platform docs/architecture/08-security.md §52): agent.read, agent.invoke, thread.read, thread.write, artifact.read, each with a scope (own or any), and admin.
auth:
defaultRole: user
roles:
user: { permissions: [agent.read, agent.invoke, thread.read, thread.write, artifact.read], scope: own, agents: ["*"] }
admin: { permissions: [agent.read, agent.invoke, thread.read, thread.write, artifact.read, admin], scope: { read: any, write: own }, agents: ["*"] }The default admin is owner decision 4: read any, write own. (Superseded 2026-10-03 by ADR 0039: the default admin is a user who also holds admin, over its own threads like everyone, and scope: any is refused.)
5. Enforcement ​
A pure orch_app::authz::allows(&Principal, Action, &Resource) -> bool, unit-tested over a matrix, applied to list_agents (filtered), describe_agent and validate_target (403 without agent.invoke for that agent); reading a thread or connecting (the owner, or thread.read with scope any; otherwise 404, so a thread's existence never leaks); messages, UI actions, cancel, rename and fork (the owner, or thread.write with scope any); the artifacts route; GET /api/threads?owner= (admins only). MCP static tokens map to a principal and a role in configuration; thread-tools stays HMAC (a machine, ADR 0023).
6. Streams ​
The token is validated when a stream connects. A stream is capped at the token's exp plus the leeway, and at one hour; the client reconnects with Last-Event-ID and gets a fresh token from oauth2-proxy's session (ADR 0012, the connect stream is resumable).
Amended 2026-11-21 (ADR 0082): an hour is no longer the longest stream. A stream ends after the deployment's lifetime — 60 s by default, ApiConfig::sse_lifetime — and its budget is the shortest of the token's exp plus its leeway, an hour, and that lifetime. A credential with no expiry is bounded by the lifetime like any other, so no stream is unbounded here; ending is the ordinary path, and the client reopens with the last id: it saw and is shown each later event once.
7. GET /api/me (the web reads it, built in S17) ​
{user, roles, permissions, agents}, so the web hides what its person cannot do. It is a convenience, never a check: the orchestrator enforces.
8. The edge and the dev stack (built in S16) ​
oauth2-proxy stays in front of the web and the API and forwards Authorization: Bearer <JWT> (the ID token by default, whose aud is oauth2-proxy's client id, so it works with any OIDC provider; an access token with an API audience is configurable). A programmatic client sends its own JWT; oauth2-proxy skips it with --skip-jwt-bearer-tokens, and the orchestrator validates it again: this is question 20 and slice 14. The dev stack gets dev/mock-oidc/ (a dependency-free Node stub with discovery, jwks, authorize, token and users with roles) and a real oauth2-proxy behind Caddy's forward_auth (--set-authorization-header, copy_headers Authorization); the scenario scripts get a token from the stub. navikt/mock-oauth2-server is the alternative if the stub grows.
Status: built in S15 ​
Built (2026-10-02, PR S15). orch_app::authz is the pure model (Policy, Access, Permission, Scope, Resource, Denied; unit-tested over a matrix), applied by App on every read and every act, so that no surface can forget it; auth.roles and auth.defaultRole are keys (config.md); GET /api/me, GET /api/threads?owner=, the role of an MCP token and the bound on a stream are in; getMe, the 403s and Thread.owner are in chat-api.yaml. Where the build differs from, or settles, what sections 4 to 7 planned:
- 403 and 404, by one rule. A permission no role of the person holds is 403 whatever is asked for, so the answer is the same for a thread that exists and one that does not (
code: forbidden). A permission the roles hold but not over this resource is 404 for a thread the person may not read, and for a thread they may read and not change (an administrator's view of another's) 403read_only: the 404 of section 5 for "messages, UI actions, cancel, rename and fork" would hide a thread the person is reading. An agent is 403 either way (agents are not secret: the web lists them). A person whose roles grant nothing at all gets 403no_accessfrom every route butGET /api/me, which still answers (with emptyrolesandpermissions) so that a client can say why. - The owner needs the permission. Section 5 reads "the owner, or
thread.readwith scopeany". The build readsthread.readwith scopeownorany: a role withoutthread.readdoes not read its own threads either. The built-in roles hold it, so nothing changes for them. agentslimits both agent permissions.agent.read(listing,describe_agent, the capabilities document,GET /api/registry) andagent.invoke(validate_target, so start and fork) are each judged per role against that role'sagents. Beyond section 5: a message to an existing thread takesagent.invokefor the thread's agent too (it starts the agent's work),describe_agenttakesagent.readand notagent.invoke, and the default agent (App::default_agent, MCP'sstart_jobwithoutagent) is the first one the person may invoke. Anagentsentry is an id or"*"; there is no other pattern.auth.defaultRoleandnull. Absent, it isuserwhenauth.rolesis absent (the built-in pair, so the default changes nothing) and none whenauth.rolesis given: a deployment that defines its roles names the default or has none.defaultRole: nullis the one place where the configuration readsnullas a value (the schema says so,x-null-is-a-value). It is a role ofauth.roles(exit 78 otherwise).auth.rolesreplaces the built-ins. Given, it defines every role;scopeisown,anyor{ read, write }, andagentsdefaults to["*"]. Ascopeoragentsthat its role would ignore, a permission listed twice and an emptyagentsare errors.- The MCP token's role is one
rolein the entry ofMCP_TOKENS_FILE(mcp.tokensFile), one ofauth.roles(exit 78 otherwise); none means the default role. A token has no roles claim and no expiry. Thread-tools stays HMAC and machine: it asks the application no permission. GET /api/meis{user, email?, name?, roles, permissions: [{permission, scope?}], agents: {read, invoke}}.rolesare the roles that count (the person's roles thatauth.rolesdefines, or the default role),scopeis the widest of the roles that hold a permission over threads, andagentsis a list of ids or["*"]for each agent permission. It isno-store.- The administrators' listing is
GET /api/threads?owner=<e-mail>(one person's) andowner=*(everyone's, which the ADR did not name; the web's "All threads" of S17 needs it). Both take theadminpermission and athread.readof scopeany; the caller's own address is the plain list, for anyone. It isThreadStore::list_all_threads, a method besidelist_threads. - A thread says its owner.
Thread.owner(the e-mail, which is the user key) is serialised in every API answer and in the export'sthread, so that a client that reads other people's threads can tell its own from the rest. It was in the log already, as theactorof the owner's messages. - Streams (section 6) end at the token's
expplus 60 s, and after an hour at most, for the AG-UI connect and run streams:Principal.expires_atcarries theexp. A stream of a credential with no expiry (the proxy header, an MCP static token) is not bounded here. The MCPwait_for_jobis bounded bymcp.waitMaxSecsas before. Amended 2026-11-21 (ADR 0082): a credential with no expiry is bounded too — by the deployment's lifetime (60 s by default), like every other stream, and the budget is the shortest of the three.sse::stream_budgetreturns a duration, never "unbounded". - A fork needs the parent to be the person's own: it is an act (
thread.write), and the store copies a thread into its owner's threads, so a role withthread.writeof scopeanythat forks another's thread is refused by the store (404). No built-in role has that scope.
Unverified: the behaviour against a real oauth2-proxy and issuer (S16 runs one); that a role claim whose names differ only in case from auth.roles is what an operator wants refused (roles are compared exactly, and the docs say so).
Status: built in S17 ​
Built (2026-10-02, PR S17), the web only (web/README.md). The web reads GET /api/me once per page load and follows it; it is never a check, and an identity that cannot be read hides nothing. Where the build settles what section 7 left open:
- Read-only is a rule of the person's permissions and the thread's
owner: nothread.write, or its scopeownon another's thread, or an agentagent.invokedoes not cover. The message box becomes a line ("Read only: this is alice@example.com's thread."), with a chip in the top bar; rename, describe, fork, edit and the actions of a card are off. The web's reading of the permissions is the orchestrator's (S15 note 3: a message to an existing thread takesagent.invokefor its agent). - The agent picker lists the agents
agents.invokecovers;GET /api/agentsis already filtered byagent.read. - An administrator (
adminandthread.readof scopeany) has Mine / All threads in the sidebar (GET /api/threads?owner=*, each thread with its owner). - No access is a screen, not a list of 403s, decided by
permissionsbeing empty inGET /api/me. - A 401 redirects to the edge's sign-in (
<path>?rd=<this page>) only when the web is built withNEXT_PUBLIC_SIGN_IN_PATH, at most once in 30 seconds; without it a 401 is the error line it was, which the system e2e behind a proxy header expects. The variable is build-time (Next inlinesNEXT_PUBLIC_*). Amended 2026-10-04: a 401 first asks the edge (GET /oauth2/userinfo) to refresh and sends the call again, and the full-page redirect, with its once-in-30-seconds pause, is the last resort (a refused popup); see the amendment at the top. - The web's mock plays the roles (
POST /__mock/config?me=), so the web's tests run against the 403s and 404s of S15.
Checked by S16 (2026-10-02): oauth2-proxy's /oauth2/start and /oauth2/sign_in both honour rd with a relative path (Status: built in S16, item 10). Unverified: the web against a real orchestrator with roles (the system e2e still runs as one person with the built-in user role).
Status: built in S16 ​
Built (2026-10-02, PR S16). dev/mock-oidc/ (a dependency-free Node stub), a real oauth2-proxy and Caddy's forward_auth in compose.yaml and dev/Caddyfile, auth.mode: jwt with the roles user, admin and chat-only in dev/orchestrator.yaml, dev/auth-header.sh for the scripts, dev/rbac-e2e.sh (dev/README.md). Where the build differs from, or settles, what section 8 planned:
- oauth2-proxy is
quay.io/oauth2-proxy/oauth2-proxy:v7.15.5-alpine, pinned by tag and by the digest of its image index (verified 2026-10-02, quay.io registry API: v7.15.5 was pushed on 2026-10-01 and is the newest release; the-alpinevariant has the shell andwgeta healthcheck needs, the plain one is distroless). The flags are those of the 7.15.x configuration page (verified 2026-10-02, https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview). - The wiring section 8 called "a design to be run" was run with oauth2-proxy v7.15.5 and Caddy 2.11.4 built from source, as processes beside the mock and stand-in upstreams (verified 2026-10-02; the containers were not):
forward_authsends a GET with no body, so the AG-UI POST body is still there for the proxy that follows;copy_headers Authorizationdeletes the client's ownAuthorizationbefore it sets the one oauth2-proxy answered with (read inforwardauth/caddyfile.goat v2.11.4), so a client cannot pass a header through when oauth2-proxy returns none; with--set-authorization-headerthe 202 of/oauth2/authcarriesAuthorization: Bearer <ID token>for a cookie session and, for a bearer it verified, the same token it was given. - A refusal is the client's, a redirect is the browser's.
/api/*and/agui/*answer oauth2-proxy's 401 as it is (a program must not be redirected); the web's catch-all turns that 401 into a redirect to/oauth2/start, and--skip-provider-buttonsends the browser straight to the issuer./mcp,/webhooks/*and the probes never meet oauth2-proxy. A token that oauth2-proxy refuses never reaches the orchestrator, so the wrong-audience 401 ofdev/rbac-e2e.shis oauth2-proxy's; the orchestrator's own audience check is the Rust tests' (S14). - The issuer has two addresses. The tokens'
issand what the orchestrator and oauth2-proxy are configured with is the compose network'shttp://mock-oidc:8080; a browser reaches the issuer'sauthorizeon the publishedhttp://127.0.0.1:8099. So oauth2-proxy skips discovery (--skip-oidc-discovery, with--oidc-issuer-url,--oidc-jwks-url,--redeem-url, and--login-urlfor the browser). The orchestrator's discovery works as ever: the document says the configured issuer. - A script's token is a
client_credentialstoken of the mock with auserparameter (an extension of the mock, which a real issuer does not have) and the same audience as the browser's, the client iddev-chat(auth.jwt.audiences); another audience can be asked for (audience=), which is how a wrong-audience token is made. oauth2-proxy verifies it with the provider's own verifier first and with the--extra-jwt-issuerspair second (the same issuer and audience, so the pair adds nothing here and shows the setting a real deployment needs for a client with its own audience). - Tokens last an hour (
TOKEN_TTL_SECS), the most an AG-UI stream lasts (section 6): a stream is ended at the token'sexpplus 60 s and after an hour at most, so an hour is the longest stream there is, and a session of the web ends with its token (a request is then a 401 until the page is reloaded, which signs in again: S17's re-login redirect is the web's own answer, item 10). The mock issues no refresh token. Amended 2026-10-04: the web no longer waits for a reload; it asks the person to sign in again in a popup, with the page kept.Amended 2026-11-21: an hour is still the most, but a stream now ends at the deployment's lifetime (60 s by default) long before it, and reopens with its lastid:(ADR 0082). login_hintis howauthorizepicks a user, but oauth2-proxy sends none, so a person chooses before signing in with/login-as?user=on the mock (a cookie for the host127.0.0.1), then signs out and in. With nothing chosen the user isdev@example.com, so a person who changes nothing is the user they were before.- MCP tokens stay static; the one of the dev stack has
role: user(S15). The roles:userandadminas the built-ins, andchat-only(agents: [chat]), withdefaultRole: userfor a token with none (guest@example.com).server.environmentstaysdevelopment: the issuer is plain http. - Not staged: an issuer that is down while the orchestrator starts. It means stopping
mock-oidcand restarting the orchestrator inside a scenario, which would leave the stack broken if the script died; the Rust smoke test runs the real binary against an issuer that is not there, and the README gives the three commands for doing it by hand. - The web's 401 redirect (S17) is wired and verified.
compose.yamlbuilds the web withNEXT_PUBLIC_SIGN_IN_PATH=/oauth2/start(build.args; the Coder E2E workflow's own build of the image passes the samebuild-args). Verified 2026-10-02 with the real oauth2-proxy v7.15.5 and Caddy 2.11.4 as processes, the stack's flags and Caddyfile, the mock issuer, a cookie jar and no session:/oauth2/start?rd=/threads/xgoes to the issuer, back to/oauth2/callback, and lands on/threads/x(200 from the web upstream); with a query and a fragment,rd=/threads/x%3Fa%3D1%26b%3D2%23fraglands on/threads/x?a=1&b=2#frag;/oauth2/sign_in?rd=does the same (--skip-provider-buttonmakes it start at once). Anrdofhttp://evil.example/xor//evil.example/xis refused by oauth2-proxy's redirect validation and the person lands on/, so no--whitelist-domainis needed for a path of this origin./oauth2/startis the one used: it does not depend on the sign-in page.
Verified later on 2026-10-02, on containers: the real oauth2-proxy image, the mock issuer, Caddy and the real orchestrator binary on dev/orchestrator.yaml (with stand-ins for the web and for the adam agents): dev/rbac-e2e.sh and seven other scripts pass, a browser walk signs in as dev and as admin, and an issuer that is down while the orchestrator starts gives /readyz 503 until it is back (item 9's by-hand check). Unverified: the Rust and web image builds, the scenarios that need the adam image (coder, chat, researcher, coder-share) and split: the first run is the Coder E2E workflow; a browser session past the token's hour.
Consequences ​
- A deployment that runs
jwttrusts only what it can verify. A client-suppliedX-Auth-Request-Emailis no identity in that mode (the smoke test sends one beside a bad token and gets 401). - A new failure mode, and a visible one. The issuer being down makes the API 503 and
/readyzfail while the keys have never been fetched; Kubernetes keeps the pod out of the service rather than serving 401s. An outage after the first fetch is invisible for up to an hour more. - The default changes nothing, and a production process cannot keep it by accident (
server.environment). - Everything that took
ApiConfig.authmoved to the port: tests that needed a development user buildHeaderAuth::new().with_dev_user(..)into theirPortSet. - Authorization (S15). S14 authenticated: every principal was allowed what everyone was. Roles are read from the token, carried in
Principal, and mapped to permissions byauth.roles(Status: built in S15). - Unverified: the behaviour against a real Keycloak or another issuer (the tests run against a local issuer with RSA, P-256 and Ed25519 keys); the
iatis required but not compared with the clock (a token issued in the future is accepted untilexp).
Alternatives rejected ​
- Validate in the proxy only. The orchestrator would still trust a header, and a CLI would still have no way in.
- A runtime-pluggable auth module. Against ADR 0009: implementations are chosen at build time and by configuration.
subas the user key now. It orphans everythreads.ownerrow; the owner kept the e-mail (decision 4).- Treat an unreachable issuer as 401. It blames the caller for the operator's outage.