Open History to see the last commit
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).
32
33Desktop restarts forget the previous local bearer token, so its reusable
34bootstrap grant replaces earlier sessions for the same subject and method.
35Revocation and insertion share a [database
36transaction](../../apps/server/src/persistence/AuthSessions.ts); a failed
37replacement must leave the old credential usable. Pairing and browser sessions
38do not follow this replacement rule.
39
40### Reusable dev credential
41
42Web development environments can accept one `T3CODE_DEV_AUTH_TOKEN` across
43worktrees and ports on one hostname. The token and startup URLs that contain it
44grant administrative access. Desktop and non-development servers ignore it. See
45the [development runbook](../operations/development.md#reusable-dev-credential)
46for setup.
47
48Each environment hashes the value and seeds its own database record at startup.
49Environments do not share SQLite data, signing keys, environment IDs, session
50records, pairing grants, or revocation state. Local revocation persists after
51restart and does not affect another worktree. Removing or rotating the value
52and restarting invalidates the old credential and its WebSocket tickets.
53
54Normal credentials keep precedence. A rejected normal credential never falls
55back to the reusable credential. OAuth exchanges create ordinary local bearer
56or DPoP children with normal expiry and revocation. The reusable cookie expires
57after 30 days.
58
59## The environment is the filesystem boundary
60
61Projects are organizational boundaries, not filesystem sandboxes.
62`orchestration:read` permits reading files the server account can read, including
63absolute paths outside a project. This lets clients display artifacts that an
64agent writes in a temporary directory. Relative paths and writes still follow
65the [workspace path rules](../../apps/server/src/workspace/WorkspaceFileSystem.ts).
66
67Signed asset URLs are bearer credentials. A URL for media on the host grants
68access to one canonical file and its device/inode identity, not its containing directory.
69[Asset access](../../apps/server/src/assets/AssetAccess.ts) rechecks the opened
70file's identity when serving it, so atomic replacement requires a new URL while
71editing the same file in place does not. An HTML file authorized this way cannot
72load sibling assets; directory-scoped workspace previews are a separate grant.
73Clients should share the authored file reference so they do not disclose the
74temporary URL's credential.
75
76Host videos can change in place. Their [HTTP
77responses](../../apps/server/src/http.ts) omit cache validators because file
78metadata cannot prove byte-for-byte identity for `If-Range`. Adding weak
79validators would turn native-player seeks into full downloads.