Repository navigation
Description
Depends on: nothing open (#2490, #2491, #2492, #2607 are done)
Problem
Only the TUI signs in at AS-1 (#2491). Studio is not registered there: mecak8s configures one AS-1 public client (--identity-broker-as1-tui-client-id, cmd/mecak8s/flags.go), and AS-1 accepts only that client as a token-exchange source (#2607). A Studio pointed at an AS-1 deployment reuses the TUI's advertised client ID and tokens, and fails with token_used. user-docs/operating/studio.md tells operators not to use such a deployment.
Design
- credentials-and-lifecycle.md: (1) AS-1 access token
- credentials-and-lifecycle.md: (3) Session open and the broker refresh token
Requirements
mecak8s and AS-1
- Register Studio at AS-1. A Studio client ID setting next to the TUI's, registered at AS-1 with Studio's redirect URIs, PKCE,
resourceequal to the Mecatl API audience, and refresh-token rotation. - Accept it as a source client. AS-1's
allowed_source_clientsand mecak8s's accepted client IDs include Studio's client ID. The flag checks that today require the TUI client allow Studio's too. - Helm. The chart takes Studio's AS-1 client ID.
Studio
- Own client ID. Studio gets its own client ID setting (env
STUDIO_OIDC_CLIENT_ID, Helmoidc.clientID), overriding the advertised client ID. - Server signal. Studio reads
com.stacklok.mecatl.identity_broker_sign_infrom mecak8s's protected-resource metadata. It sends RFC 8707resourceonly when the signal is set, and keeps sendingaudience. - Fresh token before session open. Studio forces a refresh before
createSession,forkSession,clearSession, and the first run, retry, or MCP authorization flow for a session this replica has not run successfully. It records a session as run only after success. A forced refresh bypasses the 60-second reuse cache. - One retry on 401. Studio refreshes and retries once on 401, only for unary calls and for streams and routes that pull the first item before committing headers (run, retry, MCP authorization).
A reverted first attempt is in PR #2572's history at commit 28bafe6 (apps/server/src/auth/service.ts, apps/server/src/auth/upstream.ts, apps/server/src/routes/chat.ts, deploy/helm/mecatl-studio).
Known pitfalls (from review of the first attempt):
- Concurrent forced refreshes in one browser create a rotation chain, and the browser may keep a retired refresh token. A long retired-to-new mapping defeats rotation and replay detection; prefer a short, single-use mapping, or avoid divergent chains.
- Refreshing after a response is committed loses the rotated cookie.
- Spreading a guarded service froze its getters, and the guard skipped prototype methods.
- Each Studio replica remembers its own opened sessions, so there are extra refreshes. Accepted.
- Retrying a write is safe only while mecak8s refuses before doing work; check that session create, fork, and clear still refuse a spent token before any side effect.
How it fits
Step 1 of the flow for Studio users, as #2491 is for the TUI. Removes the "Only the TUI signs in at AS-1" shortcut in #2451.
Done when
Studio signs in at AS-1 (the offline harness's and the real hosted AS-1), refreshes before opening a session, and retries once on 401; a Studio session opens a broker session with a converted refresh token; mecak8s accepts both the TUI and Studio clients; and the limitation note in user-docs/operating/studio.md is removed.
Activity