feat(proxy): authenticate option sets each caller's tenant
Merged
V3
1mo ago+710+710+012345678901234567890123456789-61-61-01234567890123456789
Summary
createDaemonProxy checks every client against one shared clientToken and never sets a tenant, so an embedder serving many callers had to rewrite requests itself, and upload tickets carried the shared token instead of the caller's credential.
New optional authenticate(request) (replaces clientToken; null → the usual 401). The proxy then:
- stamps the returned tenant on
/rpc(meta.tenantId+sessionIsolation: 'tenant', leasetenantId, overridingflags.tenant/flags.sessionIsolation) and thex-agent-device-tenantheader elsewhere, overwriting what the client sent; - serves request diagnostics only for
<tenant>:sessions (the daemon does not partition a declared tenant); - puts the caller's own
authorization/x-agent-device-tokenon upload tickets.
Without authenticate, nothing changes. Docs: proxy README, remote-proxy.md. 5 files.
Validation
Commit b342c0b. pnpm check:affected --run: all runnable checks passed (fail-open full set, triggered by untracked local state files).
- 7 new proxy unit tests; each fails when its stamp, ticket or diagnostics check is removed. 20/20 pass.
- Built CLI + local daemon + built
@agent-device/proxywithauthenticate:click @e1as alice → sessionalice:default; as bob →bob:default; alice with--tenant bob --session-isolation none→alice:default.- bob GET alice's diagnostics → 401
Session is outside this tenant; alice → 200. install … Fake.ipaas alice:PUT /upload/direct/… auth=Bearer alice-key -> alice.- unknown key →
UNAUTHORIZED.
agent-device proxy(clientToken) still works:session listok, wrong token → 401, sessioncwd:…:default(no tenant), upload via ticket reaches the install step (DEVICE_NOT_FOUND, empty private sim set).