Skip to content

feat(gateway): role definitions no longer turn on named-role enforcement without a default - #197712

Merged
jalehman merged 3 commits into
mainfrom
ocf-516-roles-enforcement-split
Nov 13, 2026
Merged

jalehman merged 3 commits into
mainfrom
ocf-516-roles-enforcement-split

Conversation

@jalehman

@jalehman jalehman commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A Gateway cannot hold role definitions without also switching on named-role enforcement for every operator sign-in. The presence of gateway.roles refuses device-token and setup-code sign-ins that have no verified identity, turns off browser-code pairing and owner ingress, and caps Tailscale and trusted-proxy users at the default role. OpenClaw ID needs role definitions on a personal claw without changing how its other sign-ins behave.

User Impact

User impact: none for existing Gateways. Every valid config already has gateway.roles.default, so it keeps enforcement exactly as before.

gateway.roles.default is now optional. A config with definitions and no default defines roles as data and otherwise behaves like a Gateway with no gateway.roles.

Required action to be aware of: removing default from a team Gateway's config now turns named-role enforcement off, where it used to fail validation. assignments.byGithubLogin without a default is a validation error.

Why This Change Was Made

  • Named-role enforcement applies only when gateway.roles.default is set. One helper, src/gateway/operator-role-enforcement.ts, answers that question, and every enforcement gate that tested for gateway.roles now uses it: sign-in and pairing, owner and person ingress, HTTP profile requirements, session sharing, cron, web push, send, questions, tool invocation, and the bundled mcp-relay and visitor-access plugins.
  • Code that reads definitions as data (model catalogs, role-name validation) still reads gateway.roles.definitions.
  • Change detection still compares the whole gateway.roles object, so adding or removing a default reloads and re-checks connections.
  • With no default, a profile resolves to no named role. users.setRole with a role name is refused and names gateway.roles.default; clearing with null works in every state.
  • OpenClaw ID member policy is unchanged in all three states.

Evidence

  • New tests with definitions and no default: setup-code and device-token-only operator connects succeed; browser-code start and approval work; owner ingress is allowed; Tailscale identity scopes are not capped; users.setRole is refused and users.list shows no effective role; config validation accepts definitions alone and rejects an unknown default and assignments without a default.
  • Focused run: 13 files, 387 tests pass. A broader 22-file run passed except one fixture that relied on definitions alone enabling enforcement; it now sets a default and its refusal assertion is unchanged.
  • Four existing expectations changed, each only because default is no longer required: the schema rejection of definitions alone, role resolution with no default (denied to none), and two fixtures that gained an explicit default.
  • Targeted typechecks, lint, format, config schema and docs checks, SDK boundary checks and line ratchets pass.
  • An independent review listed 162 non-test references to gateway.roles across 66 files and found no missed or wrongly switched enforcement gate, and no P0 or P1.

Known gap, found by that review (P2): two Doctor checks in src/commands/doctor/cron/execution-context-check.ts and the replay script scripts/dev/cron-context-replay.mts still test for the presence of gateway.roles. With definitions and no default, Doctor can wrongly report that an automation will lose owner access. It only reports; it repairs nothing. #197785, later in this stack, fixes it.

Follow-up after first CI run:

  • 17 more test fixtures relied on definitions alone enabling enforcement. Each now sets an explicit default; no assertion changed.
  • The role-assignment eligibility check moved from users.ts to users-profile-access.ts to stay under the line cap, with unchanged behavior.
  • The CI test-capacity planner keeps the Gateway core and client role tests in one compact group; without that its own floor test fails on this branch.

Live proof: 12 of 12 checks passed on head 433d3c32c5f6 in an isolated Gateway against the staging testnet (see the proof comment below).

Inherited CI failure: checks-node-compact-small-9-1 fails in test/scripts/ci-workflow-guards.test.ts (5 cases, UI end-to-end ownership counts). The CI merge base 97611bd5fb39 had two duplicate Home registrations in test/vitest/vitest.ui-paths.mjs, fixed on main by #198391. The test passes on this head alone (220), on current main (225) and on this head merged with current main (225); the CI base alone reproduces the same 5 failures. This PR touches neither file.

Not run: the full repository suite.

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts commands Command implementations plugin: visitor-access plugin: mcp-relay size: L labels Nov 12, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR makes gateway.roles.default the switch for named-role enforcement, allowing role definitions to exist without enabling it.

Example: Configure a guest role with sessions.others set to none, agents set to [], and scopes set to [], without gateway.roles.default.

  • Before: Configuration validation rejects the missing default.
  • After: The catalog is accepted, and ordinary device-token sign-in retains role-free authorization.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The feature is useful and mostly coherent, but the diagnostic cutover is incomplete and required behavior and upgrade proof are absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: A personal Gateway cannot retain role definitions for OpenClaw ID without also enabling team-wide named-role enforcement.
Reason: The supplied maintainer-authorship fact establishes direction, and the change reuses the existing role owner without adding another configuration switch.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: the maintainer-directed feature has a clear purpose, but the enforcement cutover leaves Doctor and cron replay inconsistent with runtime admission.

Priority: P2
Reviewed head: 0aa7acdd102ec783458786c924b39d4af8c64d3a

Before merge

  • Use the enforcement switch in Doctor and cron replay (P2) - With definitions but no default, a scheduled job attributed to an existing non-owner profile now passes runtime checkRequesterOwner, but Doctor still evaluates the presence of gateway.roles as enforcement and reports lost owner-only access. The channel linkability check also becomes spuriously unverified, and scripts/dev/cron-context-replay.mts retains the old profile predicate. Update these consumers in this cutover so operators receive the same decision that actual execution uses; deferring them leaves the newly accepted configuration incorrectly diagnosed.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Use the enforcement switch in Doctor and cron replay — src/commands/doctor/cron/execution-context-check.ts:121-123

Tests

  • Low-value test src/gateway/operator-role-policy.test.ts: The added membership-policy loop derives its expected result from the same helper directly returned by the production branch; remove this implementation-coupled comparison and retain independently specified membership contracts.
  • Missing end-to-end proof: Provide redacted live Gateway evidence for definitions-only pairing and authorization, plus a latest-stable upgrade retaining the existing default, assignments, settings, and data; baseline-red regression execution is also unshown.
Agent review details

How this fits together

Gateway configuration feeds authentication, profile admission, session authorization, scheduled execution, and bundled plugins; these owners turn authenticated requests into permitted operations.

flowchart TD
  A[Gateway configuration] --> B[Named role enforcement switch]
  B --> C[Sign in and pairing]
  B --> D[Profile and role policy]
  D --> E[Session and tool authorization]
  B --> F[Scheduled execution]
  B --> G[Bundled plugins]
Loading

Technical review

Best possible solution:

Use the same enforcement predicate across runtime admission, Doctor, and replay while preserving default-enabled authorization and independent OpenClaw ID membership policy.

Do we have a high-confidence way to reproduce the issue?

Source establishes that main rejects definitions without default and that the patch makes runtime owner admission disagree with Doctor for an existing non-owner profile; no execution was performed.

Is this the best way to solve the issue?

A shared enforcement predicate is a reasonable minimal design, but its consumers must include diagnostics and replay so they describe the same authorization behavior.

Full review comments:

  • [P2] Use the enforcement switch in Doctor and cron replay — src/commands/doctor/cron/execution-context-check.ts:121-123
    With definitions but no default, a scheduled job attributed to an existing non-owner profile now passes runtime checkRequesterOwner, but Doctor still evaluates the presence of gateway.roles as enforcement and reports lost owner-only access. The channel linkability check also becomes spuriously unverified, and scripts/dev/cron-context-replay.mts retains the old profile predicate. Update these consumers in this cutover so operators receive the same decision that actual execution uses; deferring them leaves the newly accepted configuration incorrectly diagnosed.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b48d16bf6e98.

Provenance checked

  • Named-role configuration and policy selection changes intended behavior with a stated reason (53dcaae: Named roles established a person-bound, deny-by-default capability ceiling, with unchanged solo behavior when roles were absent.)
  • Explicit and GitHub-login assignment precedence keeps the original intent (9fe692d: One selector applies explicit assignments, then verified GitHub-login mappings, then default; the patch retains that order when enforcement is enabled.)
  • Browser-code pairing refusal changes intended behavior with a stated reason (d85ebfe: Code pairing lacks verified person identity and was therefore refused under configured roles; this PR narrows the refusal to active named-role enforcement.)
  • Identity-less owner-equivalent session access keeps the original intent (57e6760: Current host-branded CLI-owner authority may read managed sessions without fabricated person identity, while foreign mutation stays restricted; the patch retains this distinction.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +109, Tests +296, Docs +10, Generated 0, Other +1. Total +416 across 59 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 41 217 108 +109
Tests 13 304 8 +296
Docs 3 22 12 +10
Config 0 0 0 0
Generated 1 2 2 0
Other 1 1 0 +1
Total 59 546 130 +416

Preflight source

Source 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

Metric Value Why it matters
Configuration semantics 1 existing field becomes optional; 0 new configuration keys Omitting gateway.roles.default now disables named-role enforcement instead of failing validation.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a scoped authorization feature with a reproducible diagnostic inconsistency, without evidence of an urgent regression for existing valid configurations.
  • merge-risk: 🚨 compatibility: The accepted configuration contract changes: removing default now selects a valid role-free mode; existing configurations retaining default preserve enforcement.
  • merge-risk: 🚨 security-boundary: The maintainer-directed change deliberately enables identity-less pairing and removes named-role ceilings when default is absent; that authorization change is explicitly documented.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 12, 2026, 7:10 AM ET / 12:10 UTC.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 433d3c32c5f69054989c51a7fc4062a9ec770cbf
  • Maintainer: @jalehman
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/auth.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/channel-operator-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/http-auth-user-profile.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/http-request-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/operator-role-enforcement.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/operator-role-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/request-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/send-role-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server/ws-connection/connect-device-pairing.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server/ws-connection/connect-session.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server/ws-connection/connect-user-profile.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-sharing-authorization-async.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/web-push-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

Use gateway.roles.default as the named-role enforcement switch, keeping definitions-only catalogs from changing other sign-ins. Preserve OpenClaw ID membership policy and existing default-enabled authorization.
Give enforcement fixtures explicit valid defaults so definitions-only config continues to test its separate unrestricted contract without weakening any assertion.
Recognize the exact qualified Gateway core/client selection when inventory packing combines them. Move role assignment validation to its profile-access owner without changing lazy config reads, keeping users.ts within the line-growth ratchet.
@jalehman
jalehman force-pushed the ocf-516-roles-enforcement-split branch from effd75b to 433d3c3 Compare November 13, 2026 18:19
@jalehman

Copy link
Copy Markdown
Contributor Author

Live proof on the staging testnet — 433d3c32c5f6

Built this exact PR head in a fresh, isolated Mac Studio checkout, with its own state and port. Real Chromium browsers used the real staging identity service, Discovery, loader and relay. All 12 requested live checks passed, in one run.

Configuration and check Result
No role configuration: shared-token owner receives a device token; device-only reconnect works pass
No role configuration: another browser pairs by code and connects pass
Role definitions without a default: config validates; original browser reconnects pass
Definitions without a default: new browser code pairing works pass
Definitions without a default: setup-code operator connect works pass
Definitions without a default: named role assignment is refused, null clearing works, no effective role is listed pass; refusal explicitly names gateway.roles.default
Assignment map without a default correctly rejected by CLI validation
Definitions without a default: new throwaway claw, owner/operator/viewer connect over the real tunnel pass; owner has admin, operator does not, viewer has only operator.read
Add a restrictive default: original device-only connect is refused, shared-token owner still works pass; AUTH_VERIFIED_USER_REQUIRED
Restrictive default: browser-code pairing start correctly refused with HTTP 409 identity_required
Restrictive default: identity-linked owner/operator/viewer pass; scopes unchanged
Remove the default again original browser reconnects using device-token auth, without re-pairing

The throwaway claw was roleproof516b-h23m1.crabd.xyz. Immediately after the run, it was retired: no claw, member, relay-key or live-hostname rows remain. All three test-account issuer sessions were revoked and sign-out verified. Browsers closed; the isolated Gateway process tree, state, checkout and recovery kit were removed. No shared claw or Gateway was changed.

This was a model-free authentication proof, not a chat or full-CI run. The empty fixture's owner model-setup page shows a Codex-detection error; that is separate from the successful connection and scope receipts. Evidence includes all 12 structured results and 13 inspected screenshots. No deployment or merge was performed.

@jalehman
jalehman merged commit 9fc96c4 into main Nov 13, 2026
165 of 168 checks passed
@jalehman
jalehman deleted the ocf-516-roles-enforcement-split branch November 13, 2026 19:11
@jalehman

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…ent without a default (openclaw#197712)

* feat(gateway): separate role definitions from enforcement

Use gateway.roles.default as the named-role enforcement switch, keeping definitions-only catalogs from changing other sign-ins. Preserve OpenClaw ID membership policy and existing default-enabled authorization.

* test: enable named-role enforcement in policy fixtures

Give enforcement fixtures explicit valid defaults so definitions-only config continues to test its separate unrestricted contract without weakening any assertion.

* fix: preserve compact test capacity and bound role handler size

Recognize the exact qualified Gateway core/client selection when inventory packing combines them. Move role assignment validation to its profile-access owner without changing lazy config reads, keeping users.ts within the line-growth ratchet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. plugin: mcp-relay plugin: visitor-access rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts security-sensitive-changed size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant