Repository navigation
feat(gateway): generic operator roles for non-maintainer access - #128548
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 24, 2026, 4:08 AM ET / 08:08 UTC. ClawSweeper reviewWhat this changesThis PR adds profile-bound Gateway roles that cap cross-session access, allowed agents, and operator scopes for authenticated team users. Merge readiness⛔ Blocked until stronger real behavior proof is added - 11 items remain Keep open: a role downgrade can retain an old admin scope through an awaited tool hook, and the documented identity-only setup has no safe first-maintainer bootstrap path. Priority: P1 Review scores
Verification
How this fits togetherGateway converts authenticated identity into operator scopes before routing WebSocket, HTTP, and tool requests. This change stores a role on the user profile and applies its ceiling across session and agent operations, including in-process tool calls. flowchart LR
A[Verified user identity] --> B[Gateway authentication]
B --> C[Profile role and scope ceiling]
C --> D[WebSocket HTTP and tool requests]
D --> E[Session and agent authorization]
E --> F[Gateway side effects]
Decision needed
Why: The feature’s least-privilege model cannot be made operable by a warning alone; choosing a bootstrap mechanism determines the public configuration and recovery contract. Before merge
Findings
Agent review detailsSecurityNeeds attention: The diff permits stale administrator authority to cross a role-revocation boundary into an in-process Gateway side effect. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Add a non-escalating first-maintainer bootstrap path and revalidate live role authority immediately before each in-process final effect, with trusted-identity end-to-end proof for both. Do we have a high-confidence way to reproduce the issue? Yes, from source: pause the before-tool hook for an administrator, demote that profile through users.setRole, then resume a tool that dispatches an admin Gateway method; the retained synthetic client still carries the old scope. The bootstrap lockout follows directly from the documented guest ceiling and admin-only assignment method. Is this the best way to solve the issue? No. Closing a WebSocket is not a live authorization check for retained in-process clients, and a Doctor warning cannot bootstrap an administrator; use a current-policy fence plus a deliberate scoped bootstrap authority. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 23df5799fd01. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
Acceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Adds gateway.roles: named role bundles over a closed capability set — sessions.others (none/view/suggest/write), an agents allowlist, and an operator-scope ceiling. Roles are person-level (additive user_profiles.role column, SQLite stays at v9); users.setRole (admin-only) assigns them. With no gateway.roles config, behavior is unchanged for solo deployments. Enforcement is deny-by-default from a host-minted actor identity (system vs operator+profileId on server-only client.internal, never accepted from the wire) and covers every entry point: WS RPCs, OpenAI-compat and Responses HTTP, tools invocation, cron, questions, usage, task suggestions, session catalog/sharing/reads. The agents allowlist gates both session creation and run-start on existing sessions. Subagent completion announce and descendant wake mint explicit system authority so role boundaries never silently drop parent notifications. The enforcement surface is expressed through a narrow policy vocabulary (operatorSessionCap, hasOperatorBoundary, authorizeSessionSharing) rather than per-handler policy internals.
- Break import cycles: extract GatewayOperatorRoleActor leaf contract; merge session-group-mutation-targets into session-sharing-target-input. - Split sessions-suggestions.test.ts (max-lines) into a visibility suite. - Add users.setRole to the 2026.8 train registry test and regenerate the Kotlin protocol client. - Startup UNAVAILABLE gating now precedes session authorization: session stores are not loaded during startup, so authorization reads would deny with a misleading non-retryable error. - sessions.assignOwner keeps its documented visibility-authorized contract when no operator role caps the caller; view/suggest-capped roles still cannot reassign foreign session ownership. - Test stubs updated for main's socket readyState guard (#128144) and the system-authority arg on channel-native resets.
…d session target chat.send requires a non-empty sessionKey at the protocol level; the mutation pipeline now rejects targetless frames before profile-dependent dispatch, so the pending-profile test must send a realistic frame.
3ba58e2 to
6176265
Compare
|
Merged via squash.
|
…claw#128548) * feat(gateway): generic operator roles for non-maintainer access Adds gateway.roles: named role bundles over a closed capability set — sessions.others (none/view/suggest/write), an agents allowlist, and an operator-scope ceiling. Roles are person-level (additive user_profiles.role column, SQLite stays at v9); users.setRole (admin-only) assigns them. With no gateway.roles config, behavior is unchanged for solo deployments. Enforcement is deny-by-default from a host-minted actor identity (system vs operator+profileId on server-only client.internal, never accepted from the wire) and covers every entry point: WS RPCs, OpenAI-compat and Responses HTTP, tools invocation, cron, questions, usage, task suggestions, session catalog/sharing/reads. The agents allowlist gates both session creation and run-start on existing sessions. Subagent completion announce and descendant wake mint explicit system authority so role boundaries never silently drop parent notifications. The enforcement surface is expressed through a narrow policy vocabulary (operatorSessionCap, hasOperatorBoundary, authorizeSessionSharing) rather than per-handler policy internals. * fix(gateway): heal PR CI after rebase onto main - Break import cycles: extract GatewayOperatorRoleActor leaf contract; merge session-group-mutation-targets into session-sharing-target-input. - Split sessions-suggestions.test.ts (max-lines) into a visibility suite. - Add users.setRole to the 2026.8 train registry test and regenerate the Kotlin protocol client. - Startup UNAVAILABLE gating now precedes session authorization: session stores are not loaded during startup, so authorization reads would deny with a misleading non-retryable error. - sessions.assignOwner keeps its documented visibility-authorized contract when no operator role caps the caller; view/suggest-capped roles still cannot reassign foreign session ownership. - Test stubs updated for main's socket readyState guard (openclaw#128144) and the system-authority arg on channel-native resets. * test(gateway): chat.send pending-profile dispatch carries its required session target chat.send requires a non-empty sessionKey at the protocol level; the mutation pipeline now rejects targetless frames before profile-dependent dispatch, so the pending-profile test must send a realistic frame.
…sions (openclaw#128774) The sessions.patch create path skipped createdVia and createdActor, making the creator own session invisible under createSessionListEntryFilter when gateway.roles sets sessions.others=none. Thread resolveOperatorSessionCreation through sessions-patch-engine into projectSessionsPatchEntry and stamp only genuinely new rows, mirroring session-create-service. Preserve existing rows and placeholder aliases without restamping their provenance. Add an owner-boundary regression proving the identified creator can see and update a patch-created session. Follow-up of openclaw#128548.
…6420) Fixes #133955. Reported by @aoclaw-glitch. Thank you for the clear trust-model and reconnect analysis. ## What Problem This Solves Fixes an issue where operator clients rejected by configured Gateway role policies would reconnect forever when their auth method did not provide a verified user identity. The rejection also used broad wording and did not tell the Control UI how to recover. ## Why This Change Was Made The handshake now returns the precise additive `AUTH_VERIFIED_USER_REQUIRED` detail and states which authentication paths work. TypeScript, Android, and Swift clients treat this outcome as terminal without clearing a valid device token. The Control UI shows verified-identity recovery steps instead of network or proxy-header troubleshooting. The existing `AUTH_IDENTITY_HEADER_REQUIRED` code remains specific to missing trusted-proxy headers. ## User Impact Clients stop reconnect churn after this configured-role rejection. Operators can reconnect through the trusted proxy or Tailscale, or use the shared Gateway token or password for trusted local access. ## Evidence - Red on main `e61adf3d2c61cde99f224d590a9f0824e21ccc8e`: the real WebSocket client received the detail-less rejection twice and never paused. - Green on head `655c283aeedeab4064234640e89b07fe5b976aa7`: the real client received `AUTH_VERIFIED_USER_REQUIRED`, made one attempt after waiting past the first reconnect delay, and retained the exact server-valid device token. - `node scripts/run-vitest.mjs src/gateway/server/ws-connection/connect-device-pairing.test.ts packages/gateway-client/src/reconnect-policy.test.ts ui/src/components/login-gate.test.ts` - `pnpm lint:core` - Control UI localization, formatting, max-lines, assertion-safety, coercion-helper, conflict-marker, and native-state schema guards passed. - Local native test processes could not start because this Linux host lacks Swift and Java; pull-request CI owns native compilation and tests. Production LOC: +39/-3 (net +36) | Tests: +127/-12 The production growth is the new cross-client error contract, terminal classifiers, and user recovery card. No configuration, persistence, or protocol version changes are included. Provenance: PR #128548 introduced the detail-less rejection in `53dcaaedec195fdaf5af06357557c706d3c0caf5` on 2026-08-24. The raw parent is `1f1d0e9d8f2b4b05102aeb0f17ee94d06142dcac`; author and merger were @steipete. Co-authored-by: Ayaan Zaidi <[email protected]>
…nclaw#136420) Fixes openclaw#133955. Reported by @aoclaw-glitch. Thank you for the clear trust-model and reconnect analysis. ## What Problem This Solves Fixes an issue where operator clients rejected by configured Gateway role policies would reconnect forever when their auth method did not provide a verified user identity. The rejection also used broad wording and did not tell the Control UI how to recover. ## Why This Change Was Made The handshake now returns the precise additive `AUTH_VERIFIED_USER_REQUIRED` detail and states which authentication paths work. TypeScript, Android, and Swift clients treat this outcome as terminal without clearing a valid device token. The Control UI shows verified-identity recovery steps instead of network or proxy-header troubleshooting. The existing `AUTH_IDENTITY_HEADER_REQUIRED` code remains specific to missing trusted-proxy headers. ## User Impact Clients stop reconnect churn after this configured-role rejection. Operators can reconnect through the trusted proxy or Tailscale, or use the shared Gateway token or password for trusted local access. ## Evidence - Red on main `d71a187ceaf0a353b4871a1542e4e0a0f32e5a54`: the real WebSocket client received the detail-less rejection twice and never paused. - Green on head `655c283aeedeab4064234640e89b07fe5b976aa7`: the real client received `AUTH_VERIFIED_USER_REQUIRED`, made one attempt after waiting past the first reconnect delay, and retained the exact server-valid device token. - `node scripts/run-vitest.mjs src/gateway/server/ws-connection/connect-device-pairing.test.ts packages/gateway-client/src/reconnect-policy.test.ts ui/src/components/login-gate.test.ts` - `pnpm lint:core` - Control UI localization, formatting, max-lines, assertion-safety, coercion-helper, conflict-marker, and native-state schema guards passed. - Local native test processes could not start because this Linux host lacks Swift and Java; pull-request CI owns native compilation and tests. Production LOC: +39/-3 (net +36) | Tests: +127/-12 The production growth is the new cross-client error contract, terminal classifiers, and user recovery card. No configuration, persistence, or protocol version changes are included. Provenance: PR openclaw#128548 introduced the detail-less rejection in `75dfbacbaebb678b43e53606ec9b7c659ffab129` on 2026-08-24. The raw parent is `3f9488a8030427c59dcf4d727eb54a9061775552`; author and merger were @steipete. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Team gateways have no way to give a person less than full operator access. Anyone who can authenticate can see every session, run every agent (with that agent's credentials), and mutate anything their token scopes allow. That blocks the common team shape: a maintainer-owned gateway where guests or teammates should only see their own sessions, use a designated low-privilege agent, and stay inside a scope ceiling.
Why This Change Was Made
Adds
gateway.roles: named role bundles over a closed capability set, assigned per person.sessions.others:none/view/suggest/write— maximum access to another person's sessions without explicit membership.agents: allowlist (or"*") of agents available for session creation and run-start on existing sessions — this is what pins a guest to a dedicated low-privilege agent (e.g. one with its own GitHub identity that can open PRs but not merge).scopes: ceiling applied to the profile's granted operator scopes.Design choices:
user_profiles.rolecolumn; SQLite stays at schema v9 per the additive-surface rules).users.setRole(admin-only) assigns them.systemvsoperator+profileId— minted only by the host on server-onlyclient.internal, never accepted from the wire. Unknown/unidentified actors under an active role boundary resolve to a denied role./tools/invoke, cron, questions, usage aggregation, task suggestions, session catalog/sharing/reads. Internal host dispatch (plugin runs, subagent completion announce, descendant wake) explicitly mints system authority so role boundaries never silently drop host-owned deliveries.operatorSessionCap,hasOperatorBoundary,authorizeSessionSharing) instead of per-handler policy internals; the raw role definition is exported only where scope ceilings genuinely need it.gateway.roles, solo deployments behave exactly as before.User Impact
Operators can define roles in
openclaw.jsonand assign them withusers.setRole. Role-capped users see only their own sessions (plus shared ones up to their cap), can start sessions/runs only on allowlisted agents, and keep their scope ceiling across WS and HTTP. Solo deployments are untouched.Known follow-ups (deliberately out of scope): Control UI for role assignment,
openclaw doctorwarnings for roles-without-default and shared-secret-plus-roles footguns, and docs for the guest-agent GitHub setup.Evidence
pnpm check:changedgreen (typecheck core + tests, lint, ratchets; assertion-safety baseline shrank by one entry).gpt-5.6-sol, high reasoning, chunked over the full bundle): clean, zero findings, "patch is correct" (0.95/0.96 across two runs, before and after the enforcement-surface refactor).Production/test LOC: ~+2.2k production (capability + security boundary across ~15 entry points; compression pass applied — raw policy exposure reduced to one file), ~+4.1k tests (~2:1 test-to-prod, mostly the per-entry-point "capped user cannot X" regression matrix).
Live final-effect trace (rank-up evidence)
Recorded against the reviewed head on an isolated loopback rig (
OPENCLAW_STATE_DIRsandbox, port 19811, trusted-proxy auth withdeviceAutoApprove, roles:maintainer{others: write, agents: "*", admin scopes} / defaultguest{others: none, agents: ["guestbot"]}). Raw WS protocol-v4 clients with signed device identities; redacted to step/actor/outcome:[ {"step":"connect","actor":"maintainer","ok":true,"note":"maintainer role via gateway.roles.definitions"}, {"step":"setup","actor":"maintainer","method":"sessions.patch agent:main:maint-557702","ok":true,"note":"final effect persisted (verified in agents/main session_windows row)"}, {"step":"connect","actor":"guest","ok":true,"note":"default role guest: sessions.others=none, agents=[guestbot]"}, {"step":"deny-hidden-read","actor":"guest","method":"sessions.resolve foreign","ok":false,"error":{"code":"INVALID_REQUEST","message":"Session \"agent:main:maint-557702\" was not found."},"note":"non-disclosing"}, {"step":"deny-hidden-write","actor":"guest","method":"chat.send foreign","ok":false,"error":{"code":"INVALID_REQUEST","message":"Session \"agent:main:maint-557702\" was not found."},"note":"denied before dispatch, non-disclosing"}, {"step":"deny-agent","actor":"guest","method":"sessions.patch agent:main:*","ok":false,"error":{"code":"FORBIDDEN","message":"Your operator role cannot create sessions for agent \"main\"..."}}, {"step":"allow-agent","actor":"guest","method":"sessions.patch agent:guestbot:own-557702","ok":true,"note":"allowlisted agent, own session: final effect persisted (verified in agents/guestbot session_windows row)"}, {"step":"promote","actor":"maintainer","method":"users.setRole guest->maintainer","ok":true}, {"step":"revoke-connection","actor":"gateway","method":"ws.close","ok":true,"note":"role change closed the live guest connection (close code 4001); stale connection authority does not survive reassignment"}, {"step":"post-promote-read","actor":"guest (reconnected)","method":"sessions.resolve foreign","ok":true,"note":"promoted guest now sees the foreign session"}, {"step":"demote","actor":"maintainer","method":"users.setRole guest->guest","ok":true}, {"step":"post-demote-read","actor":"guest (reconnected)","ok":false,"error":{"code":"INVALID_REQUEST","message":"Session ... was not found."},"note":"reassignment revokes authority before further reads"}, {"step":"post-demote-write","actor":"guest (reconnected)","method":"chat.send foreign","ok":false,"error":{"code":"INVALID_REQUEST","message":"Session ... was not found."},"note":"revoked write denied before dispatch"} ]Compat and bootstrap findings from the live rig (review P1s)
gateway.rolesconfigured, shared-secret (token/password) callers keep their existing access (resolveAuthenticatedHttpUserProfilereturns no policy for shared-secret methods); callers with no durable identity on identity-bearing auth paths resolve to the denied role. Role reassignment closes live connections (trace above) — deliberate revocation, not a regression. Solo deployments withoutgateway.rolesare byte-for-byte unaffected.defaultrole lacksoperator.adminlocks everyone out ofusers.setRoleon identity-only auth (trusted-proxy) — there is no shared-secret superuser to bootstrap the first maintainer. Documented here as a known limitation; the plannedopenclaw doctorwarnings follow-up (roles-without-default, shared-secret-superuser, and now default-without-admin-bootstrap) covers it.sessions.patchcreate path are persisted withoutcreatedActor, so any identity-filtered gateway (multi-identity on main today, roles here) hides such a session from its own creator on the next access. Root cause is in the patch engine (missingbuildSessionCreationStampthreading), predates this PR, and is filed as a spawned follow-up task with the live repro.