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

environment-auth.md

80 lines4.3 KB

1# Environment authentication
2​
3The environment issues its own sessions and enforces their capabilities. Cloud
4identity and relay credentials belong to a separate trust boundary, described in
5[T3 Connect](./t3-connect.md). A relay token is never an environment login.
6​
7## Authority survives transport changes
8​
9Pairing delegates a set of scopes. Exchanging a bootstrap credential can narrow
10that grant but cannot widen it. Ordinary pairing does not grant access-management
11or relay-management authority. Creating another pairing link requires both
12`access:write` and every scope being delegated. The
13[auth handlers](../../apps/server/src/auth/http.ts) enforce this at issuance;
14client labels and device metadata have no authorization role.
15​
16The access read model contains pairing metadata, never recoverable pairing
17secrets. Only the creation response returns the raw credential. Otherwise read
18access to the connections list would become a way to acquire another client's
19authority.
20​
21Browser cookies, bearer tokens, and DPoP tokens adapt the same scoped session
22model. DPoP binds a token to a client's proof key; an invalid proof must fail
23rather than fall back to bearer authentication. The OAuth token-exchange
24vocabulary gives these grants a familiar meaning, but the environment does not
25implement a general-purpose OAuth authorization server.
26​
27Bearer and DPoP clients obtain short-lived WebSocket tickets through authenticated
28HTTP so long-lived tokens stay out of socket URLs. Browser sessions can
29authenticate the upgrade with their cookie. A successful handshake grants no
30extra authority: [every RPC declares a required
31scope](../../apps/server/src/auth/RpcAuthorization.ts), and the WebSocket RPC
32group's `RpcScopeAuthorization` middleware checks it before any handler runs.
33​
34Desktop restarts forget the previous local bearer token, so its reusable
35bootstrap grant replaces earlier sessions for the same subject and method.
36Revocation and insertion share a [database
37transaction](../../apps/server/src/persistence/AuthSessions.ts); a failed
38replacement must leave the old credential usable. Pairing and browser sessions
39do not follow this replacement rule.
40​
41### Reusable dev credential
42​
43Web development environments can accept one `T3CODE_DEV_AUTH_TOKEN` across
44worktrees and ports on one hostname. The token and startup URLs that contain it
45grant administrative access. Desktop and non-development servers ignore it. See
46the [development runbook](../operations/development.md#reusable-dev-credential)
47for setup.
48​
49Each environment hashes the value and seeds its own database record at startup.
50Environments do not share SQLite data, signing keys, environment IDs, session
51records, pairing grants, or revocation state. Local revocation persists after
52restart and does not affect another worktree. Removing or rotating the value
53and restarting invalidates the old credential and its WebSocket tickets.
54​
55Normal credentials keep precedence. A rejected normal credential never falls
56back to the reusable credential. OAuth exchanges create ordinary local bearer
57or DPoP children with normal expiry and revocation. The reusable cookie expires
58after 30 days.
59​
60## The environment is the filesystem boundary
61​
62Projects are organizational boundaries, not filesystem sandboxes.
63`orchestration:read` permits reading files the server account can read, including
64absolute paths outside a project. This lets clients display artifacts that an
65agent writes in a temporary directory. Relative paths and writes still follow
66the [workspace path rules](../../apps/server/src/workspace/WorkspaceFileSystem.ts).
67​
68Signed asset URLs are bearer credentials. A URL for media on the host grants
69access to one canonical file and its device/inode identity, not its containing directory.
70[Asset access](../../apps/server/src/assets/AssetAccess.ts) rechecks the opened
71file's identity when serving it, so atomic replacement requires a new URL while
72editing the same file in place does not. An HTML file authorized this way cannot
73load sibling assets; directory-scoped workspace previews are a separate grant.
74Clients should share the authored file reference so they do not disclose the
75temporary URL's credential.
76​
77Host videos can change in place. Their [HTTP
78responses](../../apps/server/src/http.ts) omit cache validators because file
79metadata cannot prove byte-for-byte identity for `If-Range`. Adding weak
80validators would turn native-player seeks into full downloads.