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