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

04_environment-auth.md

158 lines12.8 KB

1# Environment authentication
2​
3The environment issues its own sessions and enforces their capabilities. Cloud identity and relay
4credentials belong to a separate trust boundary, described in [T3 Connect](./06_t3-connect.md). A relay
5token is never an environment login. See [SECURITY.md](../../SECURITY.md) for the overall threat
6model.
7​
8## Scoped sessions and delegation
9​
10- **Narrowing only.** Pairing delegates a set of scopes. Exchanging a bootstrap credential can
11 narrow a grant, never widen it. Client labels and device metadata have no authorization role.
12- **`access:write` hands out what the session holds and revokes anything.** Every route that
13 returns a credential to the caller requires `access:write` and every scope that credential
14 carries: a pairing link, an MCP sign-in approval, a link code from a linked environment, and a
15 guest link (which reads a thread). Revoking is not capped by the caller's scopes. Admitting a
16 T3 Connect device is not delegation; see [T3 Connect](./06_t3-connect.md).
17- **Why the default grant includes management scopes.** `terminal:operate` and
18 `orchestration:operate` already grant OS-user execution (which can invoke `t3 auth session issue`),
19 so withholding access or relay management from the default grant would not be a real boundary.
20 Narrower clients receive explicit scopes.
21- **No recoverable secrets in read models.** Only the creation response returns a raw pairing
22 credential; access listings expose metadata only.
23- **DPoP binding.** Browser cookies, bearer tokens, and DPoP tokens share the scoped session model.
24 DPoP binds tokens to a client proof key; an invalid proof must fail rather than fall back to
25 bearer auth. Plain paired DPoP sessions renew in place so live sockets and Sharing & access rows
26 stay stable; T3 Connect, CLI, and desktop sessions never self-renew so revoking/unlinking cuts
27 them off.
28- **WebSocket tickets and per-RPC authorization.** Bearer and DPoP clients mint short-lived tickets
29 over authenticated HTTP so long-lived tokens never appear in socket URLs. DPoP RPC tickets stay
30 proof-key bound at upgrade. A successful handshake grants no extra authority: every RPC declares
31 and checks its required scope in [`RpcAuthorization.ts`](../../apps/server/src/auth/RpcAuthorization.ts).
32- **Secret references need `providers:manage`.** A request that names a secret for the server to
33 read needs `providers:manage` on top of its method's scope, whether the reference is saved in
34 settings or used once, as in a secret request answered with a reference. Typed values need only
35 the method's scope. Clients hide the secret provider picker from sessions without it.
36- **Project scripts need `orchestration:operate`.** The host runs a saved project script itself,
37 on worktree creation and on settle, so saving one needs `orchestration:operate` on top of
38 `settings:write`, whether it arrives in a settings patch or a project update.
39- **Backward-compatible scope evolution.** Token exchange intersects requested scopes with the
40 pairing grant, dropping retired/unknown names and failing before consuming a link if none remain.
41 Stored grants are never expanded when scopes split. Auth responses preserve legacy `scopes`
42 alongside exact `permissions` so older clients and servers stay compatible.
43​
44## Non-standard principals
45​
46- **Guest links are not sessions.** [GuestShareService](../../apps/server/src/guest/GuestShareService.ts)
47 issues HMAC tokens bound to one share in the thread projection—never `SessionStore` rows—so no
48 RPC, WebSocket, or MCP route can accept one. Closing, replacing, or archiving the share revokes
49 every token. Guest routes also require T3 Connect to still serve the link's hostname (never rely
50 on the request `Host` header alone).
51- **MCP clients (`mcp-client`) are a separate audience.** Outside agents authenticate on `/mcp` via
52 PKCE OAuth ([McpOAuth](../../apps/server/src/auth/McpOAuth.ts)), with stateless client
53 registration so unauthenticated callers cannot grow server state. Users grant read-only access or
54 a runtime-mode ceiling rather than raw scopes. Every non-`/mcp` HTTP and WebSocket route rejects
55 `mcp-client` sessions (except the read-only thread relay and client-pairing routes restricted to
56 [peer links](./05_remote.md#peer-links)). Every MCP tool must statically declare its access level in
57 [`McpToolAccess.ts`](../../apps/server/src/mcp/McpToolAccess.ts), and thread-only tools must still
58 refuse outside callers in handlers—hiding from tool listings is only discovery. A workflow run
59 picks its own modes, so only a caller at the broadest mode a thread may run in here (full access,
60 or an administrator's ceiling below it) can start or change runs, change what workflows store, or
61 read webhook paths. Narrower callers can still read runs.
62- **A project's worktree layout commands run only as a person approved them.** The commands come
63 from the project folder's `t3.json` and run as the server's OS user, so each runs only after a
64 client session holding `terminal:operate` approved its exact text for that project.
65 [`TaskFolders`](../../apps/server/src/workspace/TaskFolders.ts) is the only place they run and
66 checks the approval, managed policy, and who asked at every run. Recording an approval is a
67 client RPC only: `t3code/no-layout-command-approval-writes` keeps the write side out of every
68 other module, MCP tools included. For an agent's own worktree request, a thread below Full access
69 gets neither these commands nor the project's setup script, approved or not. The asking thread's
70 modes are read when each is about to run, a thread recorded above the administrator's
71 `maxRuntimeMode` is not in Full access, and neither is an asking thread that can no longer be
72 read. A command that waited for another one's turn is checked again, who asked, file and
73 approval, before it starts; one refused then ran nothing, so the project's `remove` does not run
74 for it either.
75- **A repository's push hooks run for an agent below Full access only as a person approved
76 them.** `pull_request_create` pushes as the server's OS user, and Git would run the checkout's
77 `pre-push` and `reference-transaction` hooks, which the agent may have written. By the rule
78 above for who is in Full access, a thread below it gets every Git command of that call with
79 hooks off (`GitVcsDriver.RepositoryHooks`), except the push itself once a person approved the
80 hooks by a digest of their contents. Hooks are the files in the hooks directory and the ones
81 Git's configuration defines (`hook.<name>.command` with `hook.<name>.event`, which Git 2.54 and
82 later run, read from every configuration file Git reads and whatever those include). Off means
83 `-c core.hooksPath=/dev/null` on the command line, which every supported Git honors, and
84 `hook.<name>.enabled=false` for each configured hook. The driver reads the hooks again as its
85 last step before starting that push. If they are not the approved ones, nothing is pushed and
86 the person is asked about the hooks as they are now; if none is left to run, the push goes ahead
87 with hooks off and no request. A hook file or a setting that cannot be read (anything but a
88 missing file) fails the push: unknown never counts as no hook.
89 The approved push gets a hooks directory of its own for as long as it runs, made under
90 `push-hooks` in the server's state directory (outside every checkout, and not the system temp
91 directory), holding one launcher per approved hook that starts the hook by its own path (so
92 husky's `$0`-relative lookups still work); a file that appears among the repository's hooks
93 during the push is not run, and every configured hook but the approved ones is disabled. Git
94 skips a hook file it may not execute and pushes without it, so before Git starts the driver
95 writes one more script there the same way and runs it. Unless that script ran and exited 0
96 (the directory is on a `noexec` mount, the run was refused, or it did not end in time), nothing
97 is pushed and the tool says the hooks could not be started. That is checked for the launchers
98 only: a hook the launcher cannot start in turn fails the push in Git, as any failing hook does.
99 Windows has no such permission and is not checked. The digest covers what it names and no more: each configured
100 hook's name, command and the points of the push that start it, each hook file Git starts and, where that file is the shim husky 9
101 and Vite+ install (`. "$(dirname "$0")/h"`), the runner `h` beside it and the script of the
102 hook's name one directory up, such as `.husky/pre-push`. A named file edited after that last
103 read and before Git starts it runs as edited, as does a configured hook added in that time.
104 Only hooks are limited: other programs Git's configuration can name for a push, such as
105 `core.sshCommand`, a credential helper or a remote helper, run as configured.
106 The tool asks by MCP elicitation
107 ([`McpClientInput`](../../apps/server/src/mcp/McpClientInput.ts)): a sessionless client is
108 answered with the request and calls the tool again with the reply, so a handler that asks must
109 be safe to run from the start twice. It reads that reply before any push
110 (`McpClientInput.answered`): a decline pushes nothing, whatever the hooks are by then. A call
111 asks at most three times; the request's state carries the count, so it holds across a
112 sessionless client's calls. A client that cannot be asked gets the push with hooks off.
113 The Claude and Codex adapters never answer a request T3 Code's own tool made, whatever the
114 turn's runtime mode and whatever was allowed for the session: it always reaches the person.
115 In those threads the approval is the person's answer in the app, not the client's reply. The
116 request is kept with the thread's MCP session under an id of its own and the state it was
117 asked for; the adapter, which receives the person's pending-request response, leaves the
118 answer with the thread's requests that ask that message; and the tool pushes only when the
119 request the reply names (by the id in its state) holds an approval for that state. That reads
120 the request once and ends it. A reply of "accept" for a request the person did not approve,
121 or one that is gone because the server restarted or the thread's session was replaced, pushes
122 nothing: the tool fails saying T3 Code has no approval from the person, and the next call
123 asks again. A decline or cancel in the reply pushes nothing whatever the app recorded.
124 For a client T3 Code shows no request for (an outside MCP client that declared elicitation,
125 or a provider whose adapter does not pass on the person's answer), the client's reply is all
126 there is and is taken as the person's answer.
127 What those files go on to run, such as a package script or a file they source, is not part of
128 the digest, so an approval is for the named files and not for everything the push executes.
129- **Peer-link client pairing.** Only a full-access peer link may mint a one-time client pairing on
130 the linked environment (since full-access agents can already run `t3 auth pairing create`). The
131 linked side enforces this itself, and the operation stays a human-triggered RPC/HTTP route rather
132 than an MCP tool. The same route mints a code that links another environment at a chosen access
133 level, and the linking side's RPC requires the caller to hold that level's scopes.
134​
135### Reusable dev credential
136​
137Web development servers can accept a fixed `T3CODE_DEV_AUTH_TOKEN` across worktrees and ports on one
138hostname (see the [development runbook](../operations/00_development.md#reusable-dev-credential)). It
139grants administrative access and is ignored by desktop and non-development servers.
140​
141Each environment hashes the value into its own database record and keeps independent SQLite state,
142signing keys, and revocation state. Normal credentials always take precedence: a rejected normal
143credential never falls back to the reusable dev credential.
144​
145## The environment is the filesystem boundary
146​
147Projects are organizational boundaries, not filesystem sandboxes. `filesystem:read` permits reading
148any file the server's OS user can read (for example, artifacts an agent writes in a temp directory);
149relative paths and writes remain constrained by
150[`WorkspaceFileSystem.ts`](../../apps/server/src/workspace/WorkspaceFileSystem.ts).
151​
152Signed asset URLs are bearer credentials for a single canonical file, rechecked by device/inode
153identity on serve ([`AssetAccess.ts`](../../apps/server/src/assets/AssetAccess.ts)). They never
154grant access to sibling files, with one exception: the URL of an HTML page opened from a workspace
155also serves the files that page loads (styles, scripts, images, media, fonts and other pages) from
156the page's own folder and the folders below it. It serves no hidden file, and no file that a link
157in that folder points to outside it. Because `filesystem:read` is checked only at mint time, an
158issued URL remains valid until it expires even if the session or grant is revoked.