Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

environment-auth.md

141 lines6.7 KB

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
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"
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.
88​
89`dpop-access-token` is advertised alongside `browser-session-cookie` and
90`bearer-access-token` in the descriptor's `sessionMethods`
91(`EnvironmentAuthPolicy.ts`), so clients can discover support rather than
92assume it. Relay-brokered clients use this mode so that a leaked token cannot be
93replayed without the corresponding key.
94​
95### WebSocket Ticket
96​
97`POST /api/auth/websocket-ticket` accepts any authenticated session and returns
98a short-lived, single-purpose WebSocket ticket, issued through
99`EnvironmentAuth.issueWebSocketTicket` with a five-minute default TTL. The
100client presents its bearer or DPoP credential in headers to get the ticket, then
101appends only that ticket to the socket URL as `wsTicket`. This keeps long-lived
102tokens and browser cookies out of WebSocket URLs while letting the handshake
103authenticate.
104​
105The ticket carries its session's scopes; each RPC method then enforces
106`orchestration:read`, `orchestration:operate`, `terminal:operate`,
107`review:write`, `relay:write`, or `access:read` as appropriate, through
108`RPC_REQUIRED_SCOPES` in `apps/server/src/auth/RpcAuthorization.ts`. Review feedback submission currently dispatches
109an orchestration operation, so clients performing it also need
110`orchestration:operate`. Creating a ticket is not authorization to call every
111RPC method.
112​
113## Standards Alignment
114​
115- Bearer access tokens are used through the `Authorization: Bearer` scheme from
116 RFC 6750.
117- The token endpoint profiles the request and response vocabulary from OAuth 2.0
118 Token Exchange (RFC 8693), including `subject_token`, `requested_token_type`,
119 `access_token`, `issued_token_type`, and `token_type`.
120- Scope values follow the OAuth 2.0 scope model from RFC 6749: space-delimited,
121 unordered capabilities with subset checking during exchange.
122​
123This is intentionally not a general-purpose OAuth authorization server. The
124environment bootstrap token type is private, the bootstrap cookie and WebSocket
125connection-token routes are product-specific adapters, and the API returns its
126typed `HttpApi` errors rather than implementing every OAuth error response
127surface.
128​
129## Upgrade Behavior
130​
131Migration `031_AuthAuthorizationScopes` is a hard cutover from role-bearing auth
132records to scoped records. It deletes existing pairing links and sessions while
133leaving non-authentication environment state unchanged. Upgraded clients must
134pair again; old `owner` or `client` credentials are never silently mapped to new
135capabilities.
136​
137## Relay Boundary
138​
139Relay-managed tunnels use their own tokens and keys. The relay can reuse scope
140parsing and token-exchange conventions, but an environment access token is not a
141relay token and cannot be presented to the relay.