Open History to see the last commit
1# Environment Authentication Profile
2
3> For maintainers. Using T3 Code? See [docs/user](../user/).
4
5The environment server and the relay use separate credentials, issuers, and trust
6boundaries. They intentionally use a similar OAuth-shaped model so that permission
7checks and token exchange behavior can be audited against established concepts.
8
9## Authorization Model
10
11Environment authorization is capability-based. A session carries zero or more
12OAuth-style scope strings:
13
14| Scope | Permission |
15| ----------------------- | ------------------------------------------------------------------------ |
16| `orchestration:read` | Read snapshots, status, events, configuration, and filesystem/VCS state. |
17| `orchestration:operate` | Dispatch user operations and mutate environment-side workspace state. |
18| `terminal:operate` | Create, attach, input, resize, clear, restart, and terminate terminals. |
19| `review:write` | Read review diff previews used to compose review feedback. |
20| `access:read` | Inspect pairing links and client sessions. |
21| `access:write` | Create or revoke pairing links and client sessions. |
22| `relay:read` | Inspect managed relay connectivity. |
23| `relay:write` | Link, configure, or unlink managed relay connectivity. |
24
25Ordinary pairing links grant the four client-operation scopes and read access to
26managed relay connectivity:
27`orchestration:read orchestration:operate terminal:operate review:write relay:read`.
28The desktop bootstrap credential and command-line administrative bootstrap
29credentials additionally grant `access:read access:write relay:write`.
30
31## Authentication Flows
32
33### Browser Session
34
35`POST /api/auth/browser-session` consumes a one-time bootstrap credential and creates a
36browser session cookie. The cookie is an HTTP transport adapter for the same
37scoped session model; the response never exposes the session secret to browser
38JavaScript.
39
40### Bearer Access Token
41
42Non-browser clients use `POST /oauth/token` with an
43`application/x-www-form-urlencoded` body:
44
45```text
46grant_type=urn:ietf:params:oauth:grant-type:token-exchange
47subject_token=<bootstrap credential>
48subject_token_type=urn:t3:params:oauth:token-type:environment-bootstrap
49requested_token_type=urn:ietf:params:oauth:token-type:access_token
50scope=orchestration:read orchestration:operate terminal:operate review:write relay:read
51```
52
53Clients may additionally submit `client_label`, `client_device_type`, and
54`client_os` extension parameters so the authorized-clients UI can identify the
55device that established the session. These are presentation hints only; the
56environment derives transport metadata such as IP address and user agent from
57the request and does not use these fields for authorization.
58
59The response has the token-exchange shape:
60
61```json
62{
63 "access_token": "<opaque session token>",
64 "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
65 "token_type": "Bearer",
66 "expires_in": 2592000,
67 "scope": "orchestration:read orchestration:operate terminal:operate review:write relay:read"
68}
69```
70
71Sessions issued from a plain bearer exchange use the store's
72`DEFAULT_SESSION_TTL` of 30 days. The shorter one-hour `expires_in: 3600` applies
73only to DPoP-bound exchanges, where the token is additionally constrained by a
74proof key. See `SessionStore.ts` and `EnvironmentAuth.ts`.
75
76Requested scopes must be a subset of the one-time bootstrap credential grant.
77An ordinary paired client therefore cannot exchange its grant for
78`access:read`, `access:write`, or `relay:write`.
79
80### DPoP-Bound Access Token
81
82The same `/oauth/token` exchange supports proof-of-possession tokens. A client
83that sends a `DPoP` header has its proof verified by `verifyRequestDpopProof`;
84the resulting JWK thumbprint is stored on the session, which is then issued with
85method `dpop-access-token` and a one-hour TTL instead of the bearer default. An
86invalid proof gets a DPoP challenge header and a credential error rather than a
87bearer token. Newer servers include a safe `dpopFailureReason` category in that
88error. When an older server omits the category, clients mention clock skew as
89one possible cause rather than presenting it as confirmed.
90
91`dpop-access-token` is advertised alongside `browser-session-cookie` and
92`bearer-access-token` in the descriptor's `sessionMethods`
93(`EnvironmentAuthPolicy.ts`), so clients can discover support rather than
94assume it. Relay-brokered clients use this mode so that a leaked token cannot be
95replayed without the corresponding key.
96
97### WebSocket Ticket
98
99`POST /api/auth/websocket-ticket` accepts any authenticated session and returns
100a short-lived, single-purpose WebSocket ticket, issued through
101`EnvironmentAuth.issueWebSocketTicket` with a five-minute default TTL. The
102client presents its bearer or DPoP credential in headers to get the ticket, then
103appends only that ticket to the socket URL as `wsTicket`. This keeps long-lived
104tokens and browser cookies out of WebSocket URLs while letting the handshake
105authenticate.
106
107The ticket carries its session's scopes; each RPC method then enforces
108`orchestration:read`, `orchestration:operate`, `terminal:operate`,
109`review:write`, `relay:write`, or `access:read` as appropriate, through
110`RPC_REQUIRED_SCOPES` in `apps/server/src/auth/RpcAuthorization.ts`. Review feedback submission currently dispatches
111an orchestration operation, so clients performing it also need
112`orchestration:operate`. Creating a ticket is not authorization to call every
113RPC method.
114
115## Standards Alignment
116
117- Bearer access tokens are used through the `Authorization: Bearer` scheme from
118 RFC 6750.
119- The token endpoint profiles the request and response vocabulary from OAuth 2.0
120 Token Exchange (RFC 8693), including `subject_token`, `requested_token_type`,
121 `access_token`, `issued_token_type`, and `token_type`.
122- Scope values follow the OAuth 2.0 scope model from RFC 6749: space-delimited,
123 unordered capabilities with subset checking during exchange.
124
125This is intentionally not a general-purpose OAuth authorization server. The
126environment bootstrap token type is private, the bootstrap cookie and WebSocket
127connection-token routes are product-specific adapters, and the API returns its
128typed `HttpApi` errors rather than implementing every OAuth error response
129surface.
130
131## Upgrade Behavior
132
133Migration `031_AuthAuthorizationScopes` is a hard cutover from role-bearing auth
134records to scoped records. It deletes existing pairing links and sessions while
135leaving non-authentication environment state unchanged. Upgraded clients must
136pair again; old `owner` or `client` credentials are never silently mapped to new
137capabilities.
138
139## Relay Boundary
140
141Relay-managed tunnels use their own tokens and keys. The relay can reuse scope
142parsing and token-exchange conventions, but an environment access token is not a
143relay token and cannot be presented to the relay.