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
25Pairing-link lists and access-stream snapshots and updates contain metadata only.
26The raw credential is returned only by the creation request, after the server checks
27`access:write` and the delegated scopes. Web and desktop clients keep that response
28in memory for sharing. They do not recover credentials from access read models.
29
30Ordinary pairing links grant the four client-operation scopes and read access to
31managed relay connectivity:
32`orchestration:read orchestration:operate terminal:operate review:write relay:read`.
33The desktop bootstrap credential and command-line administrative bootstrap
34credentials additionally grant `access:read access:write relay:write`.
35
36## Host file access
37
38Clients with `orchestration:read` can read files anywhere the environment's server account can
39read, following the environment-wide authorization model rather than introducing per-project
40filesystem permissions. `projects.readFile` accepts an absolute path and returns the text of that
41host file; only workspace-relative paths pass its root check, and `projects.writeFile` never
42accepts an absolute path. Clients use this to show files an agent wrote outside the workspace, such
43as a report in a temp directory, read-only.
44
45## Media preview access
46
47Clients with `orchestration:read` can request a `media-file` URL through `assets.createUrl` for
48supported images, videos, HTML, and PDF files anywhere the environment's server account can read.
49A thread ID supplies the workspace for relative paths; absolute paths refer to the environment
50host, not the client.
51
52[`AssetAccess.ts`](../../apps/server/src/assets/AssetAccess.ts) resolves symlinks, requires a regular
53file, and validates the resolved file's literal extension. It opens the file and signs its canonical
54path and device/inode identity for one hour. The token grants access to that exact file, not adjacent
55files or its containing directory. Serving rechecks the canonical path, media type, and opened
56descriptor's identity, then streams full or partial responses from that descriptor. Replacing a
57file atomically requires a freshly signed URL; editing it in place does not. Because the token names
58one file, an HTML document served this way cannot load sibling assets; the directory-scoped
59`workspace-file` resource remains the route for HTML inside the workspace. Uploaded attachments keep
60their separate asset resource.
61
62Signed asset URLs are bearer credentials. Anyone who obtains a URL and can reach the environment
63can fetch that file until it expires. Clients should copy the authored reference, not the temporary
64URL. Responses use `nosniff`; SVG responses retain their restrictive sandbox policy. Video reads
65support byte ranges so playback does not require a complete download first.
66
67Host videos can change in place, so their responses use `private, no-store` and omit `ETag`
68and `Last-Modified`. File metadata cannot prove byte-for-byte identity for `If-Range`; advertising
69those validators would encourage native players to send conditional seeks that require a full
70response. Ordinary range requests receive partial responses. An explicitly supplied `If-Range`
71still falls back to a full response because no strong validator is available. Host image previews
72keep their private cache policy and weak metadata validators.
73
74The server serves media in place without importing it into attachment storage. Deletion makes
75future server reads fail, though an already loaded client or its cache can retain bytes. Native
76viewers may use temporary client-side files for display or explicit sharing; those are not durable
77environment copies.
78
79## Authentication Flows
80
81### Browser Session
82
83`POST /api/auth/browser-session` consumes a one-time bootstrap credential and creates a
84browser session cookie. The cookie is an HTTP transport adapter for the same
85scoped session model; the response never exposes the session secret to browser
86JavaScript.
87
88### Bearer Access Token
89
90Non-browser clients use `POST /oauth/token` with an
91`application/x-www-form-urlencoded` body:
92
93```text
94grant_type=urn:ietf:params:oauth:grant-type:token-exchange
95subject_token=<bootstrap credential>
96subject_token_type=urn:t3:params:oauth:token-type:environment-bootstrap
97requested_token_type=urn:ietf:params:oauth:token-type:access_token
98scope=orchestration:read orchestration:operate terminal:operate review:write relay:read
99```
100
101Clients may additionally submit `client_label`, `client_device_type`, and
102`client_os` extension parameters so the authorized-clients UI can identify the
103device that established the session. These are presentation hints only; the
104environment derives transport metadata such as IP address and user agent from
105the request and does not use these fields for authorization.
106
107The response has the token-exchange shape:
108
109```json
110{
111 "access_token": "<opaque session token>",
112 "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
113 "token_type": "Bearer",
114 "expires_in": 2592000,
115 "scope": "orchestration:read orchestration:operate terminal:operate review:write relay:read"
116}
117```
118
119Sessions issued from a plain bearer exchange use the store's
120`DEFAULT_SESSION_TTL` of 30 days. The shorter one-hour `expires_in: 3600` applies
121only to DPoP-bound exchanges, where the token is additionally constrained by a
122proof key. See `SessionStore.ts` and `EnvironmentAuth.ts`.
123
124Requested scopes must be a subset of the one-time bootstrap credential grant.
125An ordinary paired client therefore cannot exchange its grant for
126`access:read`, `access:write`, or `relay:write`.
127
128### DPoP-Bound Access Token
129
130The same `/oauth/token` exchange supports proof-of-possession tokens. A client
131that sends a `DPoP` header has its proof verified by `verifyRequestDpopProof`;
132the resulting JWK thumbprint is stored on the session, which is then issued with
133method `dpop-access-token` and a one-hour TTL instead of the bearer default. An
134invalid proof gets a DPoP challenge header and a credential error rather than a
135bearer token. Newer servers include a safe `dpopFailureReason` category in that
136error. When an older server omits the category, clients mention clock skew as
137one possible cause rather than presenting it as confirmed.
138
139`dpop-access-token` is advertised alongside `browser-session-cookie` and
140`bearer-access-token` in the descriptor's `sessionMethods`
141(`EnvironmentAuthPolicy.ts`), so clients can discover support rather than
142assume it. Relay-brokered clients use this mode so that a leaked token cannot be
143replayed without the corresponding key.
144
145### WebSocket Ticket
146
147`POST /api/auth/websocket-ticket` accepts any authenticated session and returns
148a short-lived, single-purpose WebSocket ticket, issued through
149`EnvironmentAuth.issueWebSocketTicket` with a five-minute default TTL. The
150client presents its bearer or DPoP credential in headers to get the ticket, then
151appends only that ticket to the socket URL as `wsTicket`. This keeps long-lived
152tokens and browser cookies out of WebSocket URLs while letting the handshake
153authenticate.
154
155The ticket carries its session's scopes; each RPC method then enforces
156`orchestration:read`, `orchestration:operate`, `terminal:operate`,
157`review:write`, `relay:write`, or `access:read` as appropriate, through
158`RPC_REQUIRED_SCOPES` in `apps/server/src/auth/RpcAuthorization.ts`. Review feedback submission currently dispatches
159an orchestration operation, so clients performing it also need
160`orchestration:operate`. Creating a ticket is not authorization to call every
161RPC method.
162
163## Standards Alignment
164
165- Bearer access tokens are used through the `Authorization: Bearer` scheme from
166 RFC 6750.
167- The token endpoint profiles the request and response vocabulary from OAuth 2.0
168 Token Exchange (RFC 8693), including `subject_token`, `requested_token_type`,
169 `access_token`, `issued_token_type`, and `token_type`.
170- Scope values follow the OAuth 2.0 scope model from RFC 6749: space-delimited,
171 unordered capabilities with subset checking during exchange.
172
173This is intentionally not a general-purpose OAuth authorization server. The
174environment bootstrap token type is private, the bootstrap cookie and WebSocket
175connection-token routes are product-specific adapters, and the API returns its
176typed `HttpApi` errors rather than implementing every OAuth error response
177surface.
178
179## Upgrade Behavior
180
181Migration `031_AuthAuthorizationScopes` is a hard cutover from role-bearing auth
182records to scoped records. It deletes existing pairing links and sessions while
183leaving non-authentication environment state unchanged. Upgraded clients must
184pair again; old `owner` or `client` credentials are never silently mapped to new
185capabilities.
186
187## Relay Boundary
188
189Relay-managed tunnels use their own tokens and keys. The relay can reuse scope
190parsing and token-exchange conventions, but an environment access token is not a
191relay token and cannot be presented to the relay.