Repository navigation
feat(openclaw-id): add the tunnel transport, OpenClaw ID sign-in and relayed-device Gateway auth - #192345
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Local |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs real behavior proof before merge. What this changesThis PR adds OpenClaw ID tunnel transport, local account sign-in, and membership-bound Gateway authentication and scheduled execution. Example: An admitted viewer connects through the OpenClaw ID tunnel to a token-authenticated Gateway.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep this maintainer-authored feature open. The previous protocol revocation finding is resolved, and no additional concrete correctness defect was established. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe tunnel authenticates device keys and forwards HTTP and WebSocket traffic through private ingress; Gateway membership and execution owners determine permissions and revalidate retained device grants. flowchart LR
Browser[Admitted browser device] --> Tunnel[QUIC tunnel child]
Tunnel --> Ingress[Private Gateway ingress]
Ingress --> Auth[Gateway authentication]
Auth --> Membership[Membership authority]
Auth --> Execution[HTTP and WebSocket execution]
Execution --> Scheduled[Scheduled work and recovery]
Scheduled --> Membership
Technical reviewBest possible solution: Retain the existing membership and execution owners, with device-bound grants verified through their final effects and existing persisted state preserved. Do we have a high-confidence way to reproduce the issue? This is a new capability: current main provides membership authority but lacks the tunnel entrance that this PR supplies. Is this the best way to solve the issue? The design reuses the membership, authentication, admission, and recovery owners; separating transport custody from membership decisions and retaining process grants independently of mutable payloads serves distinct lifecycle requirements. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8dd41fc95291. Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: No additional concrete exploit was established, but required final-effect authority evidence remains incomplete. EvidenceWhat I checked:
PR surfacePR surface statistics unavailable: the file list is incomplete. Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (9 earlier review cycles; latest 8 shown)
Reviewed November 6, 2026, 9:14 AM ET / 14:14 UTC (Revision 10). |
1eb1706 to
e9522d1
Compare
e164242 to
530a604
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
9269511 to
f6264ac
Compare
7c7e47b to
548e343
Compare
f6264ac to
5c6b8e6
Compare
548e343 to
9049570
Compare
|
@clawsweeper re-review |
4f86c57 to
c546781
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…relayed-device Gateway auth (openclaw#192345) * feat(openclaw-id): add the tunnel transport, OpenClaw ID sign-in and relayed-device Gateway auth * fix(openclaw-id): an HTTP request from a removed tunnel device does nothing more A relayed HTTP request kept the role it was admitted with, so a POST /tools/invoke waiting in a before-tool-call hook still ran its tool after the device was removed. Every authority check on a relayed HTTP request now asks the membership authority whether the device is still admitted with the same kind, account and role; a removal, a role change or OpenClaw ID turning off fails the next check, including the last one before the tool runs. * fix(openclaw-id): keep durable work bound to the device that authorized it Scheduled jobs, condition scripts, script payloads, shell commands, stream watchers and HTTP execution created over the tunnel now keep the original device's authority (claw, root, listing seq, owner device) with the job. Every run, restart and recovery rechecks it against the local membership record and cancels the work when the device is removed, re-approved, its role changes or the switch turns off. Recovery waits only for the local record. - WebSocket and run authority follow current membership; HTTP and WebSocket members use the canonical OpenClaw ID profile. - Stream watchers keep the process grant apart from the payload grant. - Another operator's timing edits keep the original requester; they never promote a member's job to the editor. - Restored Control UI continuations are owner-only only under admin scope. - A stopped Gateway ends local authority even during a cold first load. * test(openclaw-id): bound the ingress test WebSocket server payload * fix(openclaw-id): keep a device's scheduled grant when another device edits its timing * fix(openclaw-id): publish the token-binding writer before the tunnel admits devices * fix(gateway): keep the tunnel principal on plugin HTTP route clients * fix(gateway): never auto-approve a tunnel node by its synthetic address * test(openclaw-id): check the tunnel child exits on its own * fix(openclaw-id): keep the long-path ingress socket under the OpenClaw temp root * refactor(cron): break the stream operator source import cycle * refactor(openclaw-id): break the sign-out type cycle with the service * refactor(gateway): give the stream job scope key its own export name * fix(scripts): narrow operator source variants in the cron context replay * chore(test): allocate the OpenClaw ID tunnel regression test lines * test(gateway): give the deferred profile fixture a real auth result * test(gateway): keep real SSH verify exports in the tunnel node mock * fix(openclaw-id): let the tunnel child exit without forcing it The child now records its exit status, closes the ingress server and iroh endpoint, and releases the IPC channel so Node exits on its own, as the no-forced-process-exit guard requires (nodejs/node#64274). It relies on the iroh binding ending HomeRelayWatcher.next() when the endpoint closes (openclaw#193995). * fix(openclaw-id): require the iroh relay watcher so the tunnel child can exit A binding without HomeRelayWatcher made the child fall back to endpoint.online(), which iroh leaves pending after the endpoint closes. That pending native call kept a stopped child alive, so after the Gateway died it could hold its endpoint key indefinitely. The loader now refuses such a binding as unavailable. * fix(openclaw-id): zero the endpoint key when binding the endpoint fails * test(openclaw-id): mock node:module without spreading its class export * chore(test): allocate the OpenClaw ID tunnel test lines CI measures * fix(openclaw-id): keep the inactivity window helper private to the owner lifecycle service.ts no longer imports inactivityWindows after the owner-expiry timer moved into owner-lifecycle.ts, so the export had no consumer and failed the unused-export scan.
What Problem This Solves
A linked claw must be reachable from an owner's or member's browser through the OpenClaw ID relay, and the Gateway must authenticate those relayed devices by their membership, not by headers or other credentials. This PR adds the tunnel transport, OpenClaw ID sign-in for the Control UI, and the Gateway auth changes that admit relayed devices.
User Impact
No user-visible change while the
gateway.openclawId.enabledLabs switch is off (the default): no tunnel child, no ingress listener and no tunnel principal resolver exist, and every auth path behaves as onmain.With the switch on and the services configured, the Gateway runs a supervised tunnel child, the local operator can sign in with OpenClaw ID and link the claw, and admitted devices reach the Gateway through the relay with their owner, operator or viewer role. Automations, condition scripts, shell commands and stream watchers that a relayed device creates keep running across restarts under that device's authority, and stop when the device is removed or its role changes.
Security-relevant: this PR changes Gateway authentication, ingress attribution, the browser-origin check, the plugin cookie handoff and how scheduled work restores its creator's authority. Those changes are listed separately below.
Why This Change Was Made
Builds on #192335 (Gateway membership authority), now merged to
mainas428ca7d. It also needs the iroh Node binding, #191470, and its watcher fix, #193995: the tunnel child loads@openclaw/iroh-nodeat runtime and reports the transport unavailable (and keeps the Gateway running) when it cannot. With #193995, the binding's relay watcher ends when the endpoint closes, so the child exits on its own.Tunnel transport (
src/gateway/openclaw-id/):tunnel-child/**: a separate child process that owns the iroh endpoint. It authenticates each device key W in the QUIC handshake, refuses keys that are not admitted before any stream, and proxies HTTP and WebSocket streams to the Gateway over a private Unix socket with a per-boot proxy token. Client-supplied ingress and identity headers are replaced with authenticated facts.tunnel-supervisor.ts,tunnel-ipc.ts,tunnel-runtime.ts: start, health-ping, RSS-limit, backoff and stop the child (SIGTERM, then SIGKILL); push membership changes to it; reportrunning,unavailable,relay deniedorcrash looping. The child never forces its exit: it closes its server and endpoint and releases the IPC channel, as the repository's forced-exit guard requires (Hang at shutdown nodejs/node#64274).ingress-listener.ts,tunnel-api.ts: the private listener marks each request asopenclaw-id-tunnelwith W and a synthetic per-device address, and serves the small tunnel API that owner devices use behind the loader.remote-signout.ts: signs out one relayed browser (closes its connections and revokes its tokens) without removing the device.service.ts: starts the tunnel runtime when the switch is on, publishes the tunnel principal, device-token binding and claw-origin resolvers, and requires the running endpoint key for linking.OpenClaw ID sign-in (
account-sign-in.ts,openclawId.authorityaccount_*actions): an OIDC authorization-code flow with PKCE for the Control UI's account menu, direct loopback only. The Gateway holds the verifier and redeems the code; it keeps only display claims (sub, name, email) in the claw record.Gateway auth changes (security boundary):
auth.ts: a request the tunnel listener attributed to W authenticates as atrusted-proxyprincipal in every auth mode: owner devices act as the Gateway owner, members carryopenclaw-id:<account_id>as the user. A key the authority no longer admits is refused (openclaw_id_not_admitted), and a tunnel request never falls back to the Gateway's other credentials.ingress-attribution.ts: adds theopenclaw-id-tunneltransport (never direct loopback, rate-limited per device key). While the switch is on, identity headers (Cloudflare Access,Remote-User,X-Remote-User, the configureduserHeader/requiredHeaders) also disqualify loopback locality, so a proxy that omits client-address headers cannot reach the local-only link ceremony. With the switch off this rule does not apply and attribution is unchanged.ws-connection/*,operator-role-policy.ts,http-auth-user-profile.ts: members are capped by their role's operator policy (operator: read, write, approvals, questions, talk; viewer: read only) on WebSocket and HTTP. Pairing within that ceiling is approved automatically for relayed browsers; owner devices pair with what they request.device-token-binding.tsusers (connect-auth.ts,connect-device-pairing.ts,http-auth-utils.ts): a device token issued over the tunnel is bound to the W that obtained it; presenting it from another W, or from ordinary ingress, is refused and logged.origin-check.ts: a relayed WebSocket may also use the linked claw's own origin (https://<claw hostname>), read from the current owner-signed binding.http-auth-plugin-cookie.ts,control-ui-plugin-auth-cookie.ts: a signed plugin cookie cannot replace a relayed device's current membership, and none is issued to a tunnel request (it could be replayed on ordinary ingress).gateway-owner-profile.ts,connect-device-pairing.ts: an owner device acts as the Gateway owner when namedgateway.rolesare configured, like a token or password client.Docs:
docs/gateway/remote.md(OpenClaw ID alongside Tailscale, Cloudflare Access and Gateway credentials) anddocs/gateway/trusted-proxy-auth.md(identity headers deny loopback locality).Review
An independent review (GPT-6 Astra) of this PR found four issues; three are fixed here with tests, one is narrowed:
gateway.roleswere configured, because they carry no user. They now take the owner path.connect-auth.ts,http-operator-device-token.ts) await that read.http-auth-utils.paired-device.test.tssaves a binding in the real claw store, starts a fresh service with the switch off, and shows the token refused on HTTP, including for a request that arrives before the read finishes. The test fails without the Gateway-start read.ClawSweeper's review of
9049570: a removed owner could still invoke tools (P1), fixed here. An HTTP request kept only the role it was admitted with. APOST /tools/invokewaiting in a before-tool-call hook therefore still ran its tool after its device was removed: closing the tunnel connection does not stop a request the Gateway already holds. Every authority check on a relayed HTTP request now also asks the membership authority whether the device is still admitted with the same kind, account and role (isOpenClawIdTunnelPrincipalCurrent, read from the claw record already loaded, inhttp-auth-user-profile.ts). If the device is removed, its role changes, or OpenClaw ID turns off, the request's next check fails. That includes the last check before the tool runs, which answers 403 "Gateway requester authority changed".http-auth-utils.openclaw-id-tunnel.test.tsdrives the real HTTP authorization path and fails without the fix. The same review's P2, four test fixtures missinggetGatewayServer, was fixed earlier.Work that outlives a request keeps the device that authorized it (maintainer decision, 2026-11-05). Rather than refusing these features for tunnel devices, they keep working under the original device's authority. Independent reviews of each step found the gaps fixed below, each with a regression test that fails without the fix:
4001at its next request, and its runs stop. An operator member keeps its membership role whengateway.rolesnames a reader default. An explicit tunnel request is attributed before the ambient Tailscale checks.operator.admin./tools/invokeand HTTP session creation carry the admitted device's principal.The stored source format adds a standalone variant beside the existing parent-bound one; jobs created before this PR load unchanged. An ownership transfer still retires the previous person's authority, as on
main.ClawSweeper's review of
e164242raised the same restart gap (now fixed, see above) and one doc finding, fixed here:docs/gateway/trusted-proxy-auth.mdnow says the Cloudflare Access,Remote-User,X-Remote-Userand configured-header locality rule applies only while OpenClaw ID is on, and the Tailscale rule always applies.Rebased onto #192335 at
9269511andmainat06acff14158.service.publication-refresh.test.tsnow waits for startup publication, which #192335 moved beside the lifecycle queue.Rebased with #192335 onto
mainat0809cf31e69(#193146 merged), without conflicts.Rebased onto
mainat49f8a60f227(after #192859). Two files this PR touches had gone over the 700-line lint cap, so two self-contained pieces moved out, unchanged:verifyHttpOperatorDeviceToken, the HTTP device-token fallback that holds the tunnel-binding check, moved fromhttp-auth-utils.tstohttp-operator-device-token.ts.openclaw-id/service.tstoopenclaw-id/service-settings.ts.Rebased with #192335 onto
mainat0afeaad457c. Main's person-ingress recovery (#193098) changed the same recovery owners; its person sources and this PR's device sources are separate kinds in the same recovery codec, and both restore paths run.Security review and CI on the rebased head (
1038de0). A security review and hosted CI found the issues below. Each fix is in its own commit with a regression test, and each test was shown to fail with its fix reverted:cron-operator-source.ts,tunnel-principal.ts).service.ts,device-token-binding.ts).server/plugins-http.ts).fd00::/8) would have approved it automatically. Tunnel connections now report no client-address source, so neither path considers them, and tunnel nodes need manual pairing (ws-connection/message-handler.ts). The synthetic address is still used for display and rate limiting.process.exit. Without the binding fix fix(iroh-node): end the home relay watcher when the endpoint closes #193995 it stays alive after stopping, because the endpoint's relay watcher never ends.stream-operator-source.tsis now a leaf codec,remote-signout.tsuses a local effects type); the stream scope key export is renamedjobScopeKey; the cron context replay script narrows operator-source variants; a deferred-profile test fixture gets a real auth result; and the SSH-probe test mock keeps the module's real exports.An independent security review (GPT-6 Astra) of
cb9d750, which includes the first four fixes, found no P0–P2 issues. It checked exact OCID identity, durable-source revalidation, control-only edits, peer-bound tokens, tunnel network location, Labs-off behavior, private-ingress authentication and untrusted transport input.Rebased onto
mainat36e52993c9fafter #192335 merged. The only conflict was the database-worker list intest/vitest/vitest.gateway-server-paths.mjs: #192335's final head had already sorted its two persistence tests there, so this PR now adds only its own tests, in sorted order. The changed lines are otherwise identical to the previous head.Rebased onto
mainat2394bff0c01, which includes the protocol revocation repair #193990 (merged asc6480f78289). This resolves ClawSweeper's P1 ("Include the protocol revocation repair before exposing tunnel statements") and the related high finding ("Surviving delegated membership grants Gateway owner authority"): the tunnel statements route now calls the repaired authority. The rebase had no conflicts. 21 of the 22 commits are unchanged; the first differs only in context lines, becausemain's #193924 made two types indevice-token-binding.tsandmember-profiles.tsmodule-private. One new commit makesinactivityWindowsprivate toowner-lifecycle.ts: this PR moved its last outside caller there, somain's unused-export scan flagged it.The live Gateway trace from #193990 (comment) ran again on this head (
c546781), on a macOS arm64 host through Crabbox, and matched its "This PR + #193990" column step for step:approved_byon its approver.403 target_mismatch.403 wrong_signer.1008, its peer key leaves the tunnel child's membership, its reconnects (with and without its old device token) are refused, and the token store reportstoken-revoked.Remaining proof (maintainer decision, 2026-11-06). This PR lands with the trace above as its real-Gateway proof. ClawSweeper also asked for real-Gateway traces of four more scenarios. These are covered by tests, not traces:
http-auth-utils.openclaw-id-tunnel.test.tsdrives the real HTTP authorization path: an admitted request loses authority when its device is removed, its role changes or OpenClaw ID turns off.http-auth-utils.paired-device.test.tssaves a binding in the real claw store and keeps the token refused on HTTP after a Gateway start with the switch off.scheduled-source.persistence.test.tsrecovers serialized device sources and covers sibling and re-approved editors.cron-command-source.test.tsruns real shell commands and cancels one whose device is removed mid-run.The residual risk is behavior that appears only in a running Gateway, or only after an upgrade from a stable release, that these tests do not exercise.
Evidence
58e3c05(this PR rebased onto2394bff0c01), on a macOS arm64 host through Crabbox with fix(iroh-node): end the home relay watcher when the endpoint closes #193995's binding: the PR's changed test files,src/gateway/openclaw-idand the related cron and plugin-route suites (4 Vitest shards), the protocol package (25 files),pnpm tsgo:core,tsgo:core:test, root-script types, the chained-assertion lint, oxlint on the 159 changed code files,pnpm format:check, and the temp-path, import-cycle, Madge, export-name and mock-export guards all pass. Onc546781, which only makes one function private, the unused-export scan,pnpm tsgo:coreand the owner-lifecycle tests pass. The env-var count (461 of 461) and the test-line ratchet pass against the new base.305b6cd(after the rebase), on a macOS arm64 host through Crabbox:pnpm install --frozen-lockfile,pnpm tsgo:core,pnpm tsgo:core:test, oxlint on the 181 changed files, andpnpm testover the 40 test files this PR adds or changes,src/gateway/openclaw-idandtest/vitest-cli-ownership.test.tsall passed.609efde7166: the OpenClaw ID, auth, operator-run, cron-stream, cron-source, HTTP execution, session-sharing and cron-method Gateway suites, 90 files, 1,098 tests passed; the cron suites (operator sources, condition scripts, execution context, store, command runner, stream schedules, isolated runs), 77 files, 726 tests passed, 1 skipped. Both include the tests added by fix(agents): preserve bounded operator authority across restart continuations #193098.cron-command-source.test.tsruns real shell commands: a command whose device is removed mid-run is cancelled, and later runs are refused.a66ec81), the tunnel child and supervisor suites pass end to end: 5 files, 28 tests, including admission refusal before any stream, HTTP and WebSocket proxying, header replacement, the 64-stream limit, malformed HEAD reset and closing a live connection when membership drops its key. Without the binding the tunnel-child tests skip, as they do in CI, which does not build the binding.e8b2ef9, with the darwin-arm64 binding built by fix(iroh-node): end the home relay watcher when the endpoint closes #193995's CI (run 42174068153), on a macOS arm64 host through Crabbox: the tunnel child and supervisor suites pass, including the child exiting 0 by itself after an IPC disconnect and after SIGTERM. With feat(openclaw-id): add iroh Node binding crate #191470's binding, those two tests time out because the child stays alive. The forced-exit boundary lint, oxlint, oxfmt andpnpm tsgo:corealso pass.1038de0, on the same host: the PR's changed test files and the OpenClaw ID suites pass. Six revert-the-fix checks each fail on the expected assertion (sibling timing edit, writer order, unreadable bindings, plugin-route principal, tunnel node auto-approval, child exit).pnpm tsgo:core,tsgo:core:test, root-script types, changed-file oxlint, formatting, mock exports, the temp-path, import-cycle, Madge and export-name guards, and the test-line ratchet all pass.coexistence.test.tsshows Access, Serve and tailnet users are admitted with their existing permissions but get no People, link ceremony or sign-in.pnpm tsgo:core, allsrctest typecheck shards, changed-file lint,pnpm config:docs:checkandpnpm buildpass on this head.config/test-lines-allocations/openclaw-id-tunnel-signin.txtallocates 5,167 of the test lines this PR adds, and the base-aware ratchet passes on this head. Existing tests change only where this PR changes their contract: two publication-refresh tests restart with a new service, becausestop()is now final as it is for the Gateway, and an unrestored operator-source run reports basisoperator-source.1bc84010c2e). The gates recorded in feat(openclaw-id): add protocol contracts package #191469 went through this tunnel: removed browsers reconnecting through the relay were refused at connection setup with no HTTP or WebSocket line logged; the removed owner device's open Control UI session was closed with1008 removed from this claw, and its operator tokens were revoked.