Repository navigation
fix(cli): request scopes a session-only device grant covers - #199698
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. |
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
|
Codex review: blocked before merge. What this changesThis PR fits CLI and TUI connections to approved session-only device grants and resolves guest identity before the Gateway greeting. Example: A device approved only for operator.sessions.write runs openclaw gateway call sessions.list --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open: it addresses a current session-only guest workflow failure, and no introduced correctness defect was found; the enforced security approval remains pending. Priority: P2 Before merge
FindingsNone. Agent review detailsHow this fits togetherCLI and TUI clients select connection scopes from device credentials or structured Gateway refusals; Gateway admission then enforces the grant, resolves the caller profile, and serves authorized session RPCs. flowchart LR
A[CLI or TUI] --> B[Stored device grant]
B --> C[Existing scope projection]
C --> D[Gateway client]
D --> E[Gateway admission]
E --> F[Profile and session RPCs]
E --> G[Scope refusal]
G --> D
Technical reviewBest possible solution: Land the client-side grant fitting after security approval, leaving first-contact trusted-proxy narrowing to the separately scoped follow-up. Do we have a high-confidence way to reproduce the issue? Current-main source confirms the overbroad scope requests, and the linked report and supplied terminal traces demonstrate the resulting refusal; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch uses the existing scope projection and admission owners, preserves genuine upgrade requests, and includes the profile-ordering repair needed for a stable session-only connection. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1a60c2dc6c56. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +221, Tests +322, Docs +10, Other 0. Total +553 across 19 files. Added test files: 2. View PR surface stats
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. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
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 (6 earlier review cycles)
Reviewed November 20, 2026, 5:23 PM ET / 22:23 UTC (Revision 7). |
88cbcd5 to
48d8e52
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
A device paired with only operator.sessions.write, as the multiplayer guide recommends for guests, could not use `openclaw gateway call` or `openclaw tui`: the CLI asked for operator.read (and the TUI for admin, read, write and approvals), so every connect became a scope-upgrade request for the administrator. `gateway call` now projects its least-privilege scopes through the stored device grant with projectOperatorScopesForMethod, but only when the method's session-scoped alternative still authorizes the call. The TUI connects within a stored grant that holds operator.sessions.* and none of its default scopes, unless a shared token or password is given. A device approved before it ever connected has no stored grant, so its first request can still exceed it. The Gateway's scope-upgrade refusal reports the approved scopes: the gateway client gains an opt-in fitScopesToApprovedGrant hook that reconnects once within them, which the TUI uses, and `gateway call` retries once with the session grant. Both retries store the device token they receive, so later CLI and TUI connections fit the grant without another upgrade request. Any other gap keeps the current request, so real upgrades still reach the administrator. Session-only devices see the session methods; the TUI's command list and pending approvals stay unavailable. The CLI scope selection, including the sessions.create cwd escalation retry it already owned, moves to call-scopes.ts; the gateway client's host dependency defaults move to client-host-deps.ts.
A caller without operator.read has its own profile published as the activity viewer in hello. With Cloudflare Access identity deferred until after hello, hello published null and the later attach changed the viewer, closing the connection with 4001 "gateway policy changed" when no named role was configured. Resolve that identity before hello so the published viewer is already correct.
74994fa to
d61ac15
Compare
…lient.ts The two type assertions in resolveHostDeps moved from client.ts, where the assertion-safety baseline grandfathered them, into client-host-deps.ts. Give each a SAFETY note and lower client.ts's baseline to its remaining one.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
TUI smoke test at I built the runtime on RooBook and ran the shipped The TUI retried within the approved scope. The Gateway resolved the guest's profile before sending hello, and |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
/allow-security-sensitive-change |
Resolve conflicts from openclaw#199698 and openclaw#202616 landing on main: keep this branch's trustedProxy.narrowToDeviceGrant docs and, in the session-only Access guest test, keep main's hardened close/waitFor structure with this branch's sessions.list admission check.
…#199698) * fix(cli): connect through gateway.remote.edgeAuth without a Gateway token A CLI behind an identity-aware proxy (Cloudflare Access) has no Gateway token or password: the proxy authenticates the WebSocket upgrade and the Gateway uses trusted-proxy auth. `openclaw tui`, `openclaw tui --url` and `openclaw gateway call` refused to dial in that setup, so the device could never send the pairing request the Cloudflare Access guide describes. When edge-auth headers are configured for the target's origin, skip the local shared-credential prechecks and let the Gateway's device pairing decide. Targets without edgeAuth, and other origins, keep requiring credentials as before. * docs(cli): limit tokenless edgeAuth pairing to trusted-proxy Gateways * fix(cli): tell an unpaired edgeAuth device to pair through the TUI * fix(cli): keep an explicit --url in the edgeAuth pairing hint * fix(cli): request scopes a session-only device grant covers A device paired with only operator.sessions.write, as the multiplayer guide recommends for guests, could not use `openclaw gateway call` or `openclaw tui`: the CLI asked for operator.read (and the TUI for admin, read, write and approvals), so every connect became a scope-upgrade request for the administrator. `gateway call` now projects its least-privilege scopes through the stored device grant with projectOperatorScopesForMethod, but only when the method's session-scoped alternative still authorizes the call. The TUI connects within a stored grant that holds operator.sessions.* and none of its default scopes, unless a shared token or password is given. A device approved before it ever connected has no stored grant, so its first request can still exceed it. The Gateway's scope-upgrade refusal reports the approved scopes: the gateway client gains an opt-in fitScopesToApprovedGrant hook that reconnects once within them, which the TUI uses, and `gateway call` retries once with the session grant. Both retries store the device token they receive, so later CLI and TUI connections fit the grant without another upgrade request. Any other gap keeps the current request, so real upgrades still reach the administrator. Session-only devices see the session methods; the TUI's command list and pending approvals stay unavailable. The CLI scope selection, including the sessions.create cwd escalation retry it already owned, moves to call-scopes.ts; the gateway client's host dependency defaults move to client-host-deps.ts. * fix(cli): keep read-only storage on the session-grant retry * fix(gateway): resolve a session-only caller's identity before hello A caller without operator.read has its own profile published as the activity viewer in hello. With Cloudflare Access identity deferred until after hello, hello published null and the later attach changed the viewer, closing the connection with 4001 "gateway policy changed" when no named role was configured. Resolve that identity before hello so the published viewer is already correct. * fix(gateway-client): document the host-deps assertions moved out of client.ts The two type assertions in resolveHostDeps moved from client.ts, where the assertion-safety baseline grandfathered them, into client-host-deps.ts. Give each a SAFETY note and lower client.ts's baseline to its remaining one.
Release adaptation: preserve stable OpenClaw ID membership role cap and documentation; move only the existing pre-cap connection scope projection before profile preparation. The projected scopes do not decide authority, and stable role resolution and capping remain after profile preparation. Pinned companion audit: no follow-up cites #199698 or the source SHA; later identity/admission changes are not dependencies. (cherry picked from commit 95e9afc) Co-authored-by: RomneyDa <[email protected]>
Related: #199692
Depends on #199693. This branch is stacked on it, so until #199693 merges the diff also shows its commits.
What Problem This Solves
Fixes: a device paired with only
operator.sessions.write, as the multiplayer guide recommends for guests, can't useopenclaw gateway calloropenclaw tui. The CLI asks foroperator.readand the TUI for admin, read, write and approvals, so every connect becomes a scope-upgrade request for the admin.User Impact
User impact: a session-only guest can list, read and create its sessions from the CLI and use the TUI within its grant. Once the TUI has stored the grant with a device token, its connections and
gateway callfile no upgrade request. Behind trusted-proxy auth the Gateway issues the TUI no device token andgateway callstores none, so there each connection is refused once with a scope-upgrade request and then works within the grant. #199699 removes that refusal as a Gateway opt-in.Devices whose grant holds the general scope are unchanged, and a device that needs a real upgrade (for example
operator.readtooperator.admin) still files one.In the TUI, a session-only device gets no command list or pending approvals, because those need
operator.readandoperator.approvals.Why This Change Was Made
Where the client learns its grant:
gateway callprojects its least-privilege scopes through the stored device grant with the existingprojectOperatorScopesForMethod. It narrows only when the method's session-scoped alternative still authorizes the call.operator.sessions.*and none of its default scopes, unless--tokenor--passwordis given.A device approved before it ever connected: it has no stored grant, so its first request can exceed it. The Gateway's scope-upgrade refusal already reports
approvedScopes, and the client uses that:fitScopesToApprovedGranthook that reconnects once within the reported grant, which the TUI uses.gateway callretries once with the session grant.gateway callreading that stored grant, fit it.gateway callkeeps its read-only storage mode on the retry and stores nothing.Until a grant is stored, each connection still files that request first, because nothing tells the client its grant before it asks. Behind trusted-proxy auth nothing is stored, so that holds for every connection. The opt-in Gateway change in #199699 removes it.
Moves: two moves keep the touched files within the line-cap ratchet without changing behaviour:
sessions.createcwd escalation retry, moves tosrc/gateway/call-scopes.ts.packages/gateway-client/src/client-host-deps.ts.client.tsre-exports their types, so the package API is unchanged.Docs:
docs/start/multiplayer.mdanddocs/cli/tui.mddescribe the guest behaviour and when the first-connect request remains.Evidence
New tests:
src/gateway/call.stored-grant-scopes.test.ts5/5. A session-only grant reads withoperator.sessions.read; a read grant and a method without a session scope keep their request; a refused request retries with the reported grant and keeps read-only storage on both attempts (this case fails without the read-only fix); a grant that can't serve the method does not retry.packages/gateway-client/src/client.approved-grant.test.ts3/3, against a real WebSocket server that refuses with a scope upgrade: reconnects once within the reported grant; pauses without the hook, or when the hook keeps the request.src/tui/gateway-chat.connection.test.ts16/16, adding session-only, read,operator.pairingand--tokengrants.operator.pairingand--tokencases fail; the keep-behaviour cases pass on both.Existing tests:
call.test.ts91/91,client.test.ts95/95,client.handshake.test.ts22/22,client.device-auth.test.ts25/25,reconnect-policy.test.ts19/19,tui.test.ts51/51.Static checks: typecheck, lint and format are clean.
Restack onto fix(cli): connect through gateway.remote.edgeAuth without a Gateway token #199693's pairing hint: this branch now sits on
a675d1b23b7, which adds theopenclaw gateway callhint for an unpaired edgeAuth device and keeps an explicit--urlin it.git range-diff 3411a94ae50..48d8e528f08 a675d1b23b7..74994fa1a99shows this branch's two commits unchanged, and the runs below were made at48d8e528f08, before the restack. On74994fa1a99:call.edge-auth.test.ts6/6,call.stored-grant-scopes.test.ts5/5,call.test.ts91/91,gateway-chat.connection.test.ts16/16,client.approved-grant.test.ts3/3, typecheck clean, line-cap ratchet OK. On71857425b24, the same two commits on fix(cli): connect through gateway.remote.edgeAuth without a Gateway token #199693's first hint commit:client-bootstrap.auth.test.ts6/6,client.test.ts95/95,tui.test.ts51/51.Live run at
48d8e528f08(built withpnpm build:runtime): a loopback Gateway withgateway.auth.mode: "trusted-proxy", behind a small TLS proxy standing in for Cloudflare Access (it answers 302 unless the request carriesCf-Access-Token, then injects the identity headers). The guest config has onlygateway.remote.urlandgateway.remote.edgeAuth: no token, no password, no stored device token.--tls-fingerprintis there only because the test proxy uses a self-signed certificate. The output is trimmed, and IDs and ports are from throwaway test state. The admin approves onlyoperator.sessions.write. The Gateway hasnarrowToDeviceGrantoff, as it is by default and as it is without feat(gateway): connect approved trusted-proxy CLI and TUI devices within their grant #199699.Guest and admin terminal output, proxy connect frames, Gateway audit count
Upgrade run: terminal output, proxy connect frames, Gateway audit counts