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

environment-auth.md

113 lines5.3 KB

1# Environment Authentication Profile
2​
3The environment server and the relay use separate credentials, issuers, and trust
4boundaries. They intentionally use a similar OAuth-shaped model so that permission
5checks and token exchange behavior can be audited against established concepts.
6​
7## Authorization Model
8​
9Environment authorization is capability-based. A session carries zero or more
10OAuth-style scope strings:
11​
12| Scope | Permission |
13| ----------------------- | ------------------------------------------------------------------------ |
14| `orchestration:read` | Read snapshots, status, events, configuration, and filesystem/VCS state. |
15| `orchestration:operate` | Dispatch user operations and mutate environment-side workspace state. |
16| `terminal:operate` | Create, attach, input, resize, clear, restart, and terminate terminals. |
17| `review:write` | Read review diff previews used to compose review feedback. |
18| `access:read` | Inspect pairing links and client sessions. |
19| `access:write` | Create or revoke pairing links and client sessions. |
20| `relay:read` | Inspect managed relay connectivity. |
21| `relay:write` | Link, configure, or unlink managed relay connectivity. |
22​
23Ordinary pairing links grant the four client-operation scopes and read access to
24managed relay connectivity:
25`orchestration:read orchestration:operate terminal:operate review:write relay:read`.
26The desktop bootstrap credential and command-line administrative bootstrap
27credentials additionally grant `access:read access:write relay:write`.
28​
29## Authentication Flows
30​
31### Browser Session
32​
33`POST /api/auth/browser-session` consumes a one-time bootstrap credential and creates a
34browser session cookie. The cookie is an HTTP transport adapter for the same
35scoped session model; the response never exposes the session secret to browser
36JavaScript.
37​
38### Bearer Access Token
39​
40Non-browser clients use `POST /oauth/token` with an
41`application/x-www-form-urlencoded` body:
42​
43```text
44grant_type=urn:ietf:params:oauth:grant-type:token-exchange
45subject_token=<bootstrap credential>
46subject_token_type=urn:t3:params:oauth:token-type:environment-bootstrap
47requested_token_type=urn:ietf:params:oauth:token-type:access_token
48scope=orchestration:read orchestration:operate terminal:operate review:write relay:read
49```
50​
51Clients may additionally submit `client_label`, `client_device_type`, and
52`client_os` extension parameters so the authorized-clients UI can identify the
53device that established the session. These are presentation hints only; the
54environment derives transport metadata such as IP address and user agent from
55the request and does not use these fields for authorization.
56​
57The response has the token-exchange shape:
58​
59```json
61 "access_token": "<opaque session token>",
62 "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
63 "token_type": "Bearer",
64 "expires_in": 3600,
65 "scope": "orchestration:read orchestration:operate terminal:operate review:write relay:read"
67```
68​
69Requested scopes must be a subset of the one-time bootstrap credential grant.
70An ordinary paired client therefore cannot exchange its grant for
71`access:read`, `access:write`, or `relay:write`.
72​
73### WebSocket Ticket
74​
75`POST /api/auth/websocket-ticket` accepts any authenticated session and returns
76a short-lived, single-purpose WebSocket ticket. This keeps bearer tokens and
77browser cookies out of WebSocket URLs while allowing the socket handshake to
78authenticate. The ticket carries its session's scopes; each RPC method then
79enforces `orchestration:read`, `orchestration:operate`, `terminal:operate`,
80`review:write`, or `access:read` as appropriate. Review feedback submission
81currently dispatches an orchestration operation, so clients performing it also
82need `orchestration:operate`. Creating a ticket is not
83authorization to call every RPC method.
84​
85## Standards Alignment
86​
87- Bearer access tokens are used through the `Authorization: Bearer` scheme from
88 RFC 6750.
89- The token endpoint profiles the request and response vocabulary from OAuth 2.0
90 Token Exchange (RFC 8693), including `subject_token`, `requested_token_type`,
91 `access_token`, `issued_token_type`, and `token_type`.
92- Scope values follow the OAuth 2.0 scope model from RFC 6749: space-delimited,
93 unordered capabilities with subset checking during exchange.
94​
95This is intentionally not a general-purpose OAuth authorization server. The
96environment bootstrap token type is private, the bootstrap cookie and WebSocket
97connection-token routes are product-specific adapters, and the API returns its
98typed `HttpApi` errors rather than implementing every OAuth error response
99surface.
100​
101## Upgrade Behavior
102​
103Migration `031_AuthAuthorizationScopes` is a hard cutover from role-bearing auth
104records to scoped records. It deletes existing pairing links and sessions while
105leaving non-authentication environment state unchanged. Upgraded clients must
106pair again; old `owner` or `client` credentials are never silently mapped to new
107capabilities.
108​
109## Relay Boundary
110​
111Relay-managed tunnels use their own tokens and keys. The relay can reuse scope
112parsing and token-exchange conventions, but an environment access token is not a
113relay token and cannot be presented to the relay.