Skip to content

fix(gateway): keep auth-none local clients connected after pairing - #124545

Merged
steipete merged 1 commit into
mainfrom
steipete/gateway-pairing-exemption-both-branches
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/gateway-pairing-exemption-both-branches

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where local Gateway backend calls and TUI sessions on a loopback gateway.auth.mode: "none" Gateway could connect until any narrower pairing row existed for the same device identity. After that row appeared, the identical connection was rejected as an unapprovable scope upgrade even though locality plus the configured auth mode—not the pairing record—was the authority for that session class.

This PR is AI-assisted; the implementation and evidence were reviewed against the complete Gateway connect path and its durable device-token boundary.

Why This Change Was Made

The Control UI pairing policy now returns a closed reason (auth-none, tailscale-device, or no exemption) instead of collapsing two different trust boundaries into one boolean. Local backend self-calls and auth-none operator UIs bypass stored pairing access checks both before and after a row exists, while paired reconnects still refresh last-seen metadata and retain the row as the durable token baseline. ensureDeviceToken remains unchanged and continues to reject token scopes beyond that approved baseline.

The Tailscale Control UI path is intentionally not hoisted: an existing pairing row remains its access cap. The device-approval recovery path also requests only operator.pairing when reading the pairing list.

Production LOC: +35/-16 (net +19) | Tests: +189/-61. The production growth encodes the closed auth-boundary reason and the explicit separation between session admission, metadata refresh, and durable grant issuance; the obsolete paired-backend rejection test was removed rather than preserved as compatibility.

User Impact

Operators running an auth-none loopback Gateway can keep using local gateway-client backend calls and the TUI after another command has created a narrower pairing row for the shared device identity. Existing durable device tokens are not widened, remote/non-loopback clients are unchanged, and paired Tailscale Control UI sessions remain capped by their approved scopes.

Evidence

Pre-fix owner-boundary proof (new regression test retained, production changes stashed):

  • both auth-none paired reconnects failed with PAIRING_REQUIRED, reason: scope-upgrade
  • the same clients passed while unpaired
  • the Tailscale narrow-row guard passed unchanged

Focused and boundary suites:

  • node scripts/run-vitest.mjs src/gateway/server/ws-connection/ — 58 files, 584 tests passed
  • node scripts/run-vitest.mjs src/gateway/server.auth*.test.ts — 7 files, 135 tests passed
  • node scripts/run-vitest.mjs src/gateway/server.device-scope-upgrade.test.ts — 10 tests passed
  • node scripts/run-vitest.mjs src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts — 7 tests passed
  • focused owner/policy/CLI run — 66 tests passed
  • pnpm format <changed paths> — passed
  • pnpm check:changed — passed on trusted remote Linux
  • pnpm build — passed on trusted remote Linux
  • Codex autoreview — clean, no accepted/actionable findings

Live isolated Gateway proof used a fresh state directory, port 19435, and config:

{"gateway":{"mode":"local","port":19435,"auth":{"mode":"none"}}}

After seeding the shared device identity with an approved operator.pairing row, the patched built Gateway was started with:

OPENCLAW_STATE_DIR=<isolated> pnpm openclaw gateway run --port 19435

The real gateway-client / backend connection requested operator.write and returned:

{"verdict":"admitted","pairedBaseline":["operator.pairing"],"requestedScopes":["operator.write"],"healthOk":true,"storedTokenScopes":["operator.pairing"],"lastSeenReason":"connect"}

Gateway log excerpt:

Gateway auth mode=none explicitly configured; all gateway connections are unauthenticated.
← connect client=gateway-client clientDisplayName=gateway:health version=2026.8.1 mode=backend clientId=gateway-client platform=node auth=none
→ hello-ok methods=382 events=50 presence=1 stateVersion=1
⇄ res ✓ health 8ms cached=true

The isolated Gateway was stopped cleanly and port 19435 was verified free afterward.

Known gap / follow-up

Plain cli / cli clients remain non-exempt by design. On an auth-none install, the first CLI command can still pair the shared identity at a narrow scope and a later differently scoped command can become an unapprovable scope upgrade. That is a separate client-identity ownership issue: src/gateway/call.ts:445 (shouldOmitDeviceIdentityForGatewayCall) requires shared-secret auth for isLocalCliSharedAuth, so auth-none CLI calls attach an identity while token-authenticated local CLI calls omit it. This PR does not change that policy, shouldAllowSilentLocalPairing, scope-upgrade silence, browser origins, browser-copilot checks, or remote behavior.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 16, 2026 11:55
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes labels Aug 16, 2026
@steipete
steipete requested a review from a team as a code owner August 16, 2026 11:55
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 8:01 AM ET / 12:01 UTC.

ClawSweeper review

What this changes

The PR names Control UI pairing exemptions so auth-none local backend and TUI sessions remain connected after a narrower paired-device record exists, without widening durable device tokens.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review: the patch cleanly separates local auth-none session admission from durable paired-token scope limits, with focused regression coverage and isolated Gateway proof. Its deliberate authorization-boundary change needs explicit maintainer acceptance before merge.

Priority: P2
Reviewed head: 490a96899f1a8be4086704aa104c53a42e6a10c2
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong focused and real-Gateway evidence supports a clean owner-boundary repair; the remaining gate is maintainer acceptance of the authorization policy.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body includes an after-fix isolated built-Gateway run with a real backend client, admission result, health response, and confirmation that the stored token remained narrow.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes an after-fix isolated built-Gateway run with a real backend client, admission result, health response, and confirmation that the stored token remained narrow.
Evidence reviewed 6 items Current-main failure path: Current main bypasses pairing only while a device is unpaired; a matching paired record always enters existing-device authorization, which rejects a requested scope outside the paired baseline.
Scoped session exception: The PR limits its paired-session bypass to the existing local-backend exemption or the explicit auth-none Control UI reason; the Tailscale reason stays on the paired scope-cap path.
Durable token boundary: Device-token issuance and reuse independently reject requested scopes beyond the paired approval baseline, so admitting the session does not mint a widened token.
Findings None None.
Security None None.

How this fits together

Gateway WebSocket admission evaluates authentication, locality, role, and device pairing before a client can use operator methods. Device-pairing records also retain metadata and constrain reusable device-token scopes.

flowchart LR
  A[Local client] --> B[Gateway handshake]
  B --> C[Authentication and locality]
  C --> D[Pairing exemption reason]
  D --> E[Session admission]
  E --> F[Paired-device metadata]
  F --> G[Durable token scope bound]
Loading

Decision needed

Question Recommendation
Should explicit loopback auth-none operator sessions and first-party local backend sessions remain authorized by locality/auth policy after a narrower paired-device row exists? Accept the bounded session exemption: Merge the separation because paired records continue to cap durable tokens and Tailscale paired sessions remain scope-capped.

Why: This is a deliberate Gateway authorization-policy decision; source confirms durable tokens remain scoped, but automation should not choose the intended session trust boundary.

Before merge

  • Resolve merge risk (P1) - Merging deliberately changes a Gateway authorization boundary for local backend and auth-none operator sessions; maintainer acceptance should confirm that locality/auth-none, rather than a pre-existing pairing row, is the intended session authority.
  • Complete next step (P2) - The active maintainer-authored PR changes an intentional Gateway trust boundary and requires owner acceptance, not automated repair.
Agent review details

Security

None.

PR surface

Source +19, Tests +128. Total +147 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 5 35 16 +19
Tests 4 189 61 +128
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 224 77 +147

Review metrics

Metric Value Why it matters
Production versus regression coverage production +35/-16 (net +19); tests +189/-61 The production growth introduces a closed exemption reason and metadata refresh while tests cover both exempt reconnects and the retained Tailscale cap.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept the explicit local-session boundary (recommended)
    Approve the PR’s distinction between session admission and durable token scope after confirming that auth-none and first-party local backend locality are intended authorities.
  2. Pause for a narrower policy decision
    Keep current paired-session scope enforcement if maintainers want every paired reconnect to remain constrained by its stored scope record.

Technical review

Best possible solution:

Keep the closed exemption reason and separate session admission from durable-token issuance; merge only after the owner accepts this bounded trust-policy change and exact-head checks complete.

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

Yes: current-main source shows a paired record always reaches the scope-cap authorization path, and the PR supplies focused before/after tests plus an isolated real Gateway trace.

Is this the best way to solve the issue?

Yes, subject to maintainer policy acceptance: the patch fixes the owner boundary and preserves the independent durable-token cap rather than widening paired scopes or adding a fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against bba57301d9c5.

Labels

Label changes:

  • add P2: This is a bounded Gateway reconnect defect affecting explicitly configured local auth-none workflows.
  • add merge-risk: 🚨 security-boundary: The PR changes when paired-device scope records participate in Gateway session authorization.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an after-fix isolated built-Gateway run with a real backend client, admission result, health response, and confirmation that the stored token remained narrow.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes an after-fix isolated built-Gateway run with a real backend client, admission result, health response, and confirmation that the stored token remained narrow.

Label justifications:

  • P2: This is a bounded Gateway reconnect defect affecting explicitly configured local auth-none workflows.
  • merge-risk: 🚨 security-boundary: The PR changes when paired-device scope records participate in Gateway session authorization.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes an after-fix isolated built-Gateway run with a real backend client, admission result, health response, and confirmation that the stored token remained narrow.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes an after-fix isolated built-Gateway run with a real backend client, admission result, health response, and confirmation that the stored token remained narrow.

Evidence

What I checked:

Likely related people:

  • steipete: Current paired-device authorization is blamed to Peter Steinberger, and the same author has recent merged work on verified identity and loopback locality. (role: recent Gateway pairing and locality contributor; confidence: high; commits: 7563682c3fc3, c6edd3e80f6c, ea967be0df6b; files: src/gateway/server/ws-connection/connect-device-pairing.ts, src/gateway/server/ws-connection/handshake-auth-helpers.ts, src/gateway/server/ws-connection/connect-policy.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain explicit maintainer acceptance of the local session-authority policy and complete exact-head CI before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper rank-up move resolved:

  • Maintainer decision accepted: loopback auth-none operator sessions and first-party local backend sessions remain authorized by locality/auth policy after a narrower pairing row exists; the row continues to cap durable tokens.
  • Exact-head CI is green at 490a96899f1a8be4086704aa104c53a42e6a10c2 (CI run 31945654179).
  • The stored-data-model note is a classifier false positive from deleting an obsolete test in server.silent-scope-upgrade-reconnect.poc.test.ts; this PR has no schema, migration, backfill, or persistent-data format change.

No ClawSweeper findings remain, and its Tailscale/durable-token boundary checks match the local review and live proof.

@steipete
steipete merged commit 6e7b1e2 into main Aug 16, 2026
253 checks passed
@steipete
steipete deleted the steipete/gateway-pairing-exemption-both-branches branch August 16, 2026 12:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant