Skip to content

fix(cli): connect through gateway.remote.edgeAuth without a Gateway token - #199693

Merged
hannesrudolph merged 5 commits into
openclaw:mainfrom
daniel-lxs:cli-edge-auth-first-connect
Nov 20, 2026
Merged

hannesrudolph merged 5 commits into
openclaw:mainfrom
daniel-lxs:cli-edge-auth-first-connect

Conversation

@daniel-lxs

@daniel-lxs daniel-lxs commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Closes #199691

What Problem This Solves

Fixes: openclaw tui, openclaw tui --url and openclaw gateway call refuse to dial a Gateway behind Cloudflare Access (or another identity-aware proxy) when the client has gateway.remote.edgeAuth but no Gateway token or password. A guest's device therefore never files its first pairing request.

User Impact

User impact: a CLI configured with gateway.remote.edgeAuth connects to a trusted-proxy Gateway without a shared Gateway secret. On first contact openclaw tui gets device pairing required and leaves a request for the admin, as the Cloudflare Access guide already describes. Configurations without edgeAuth, and targets on other origins, still require credentials as before. A Gateway on token or password auth still needs its credential: edgeAuth only gets the connection through the proxy, and the Gateway then refuses the missing token. A device that has never connected pairs through openclaw tui; its openclaw gateway call now says so instead of answering with a bare missing scope: operator.read.

Why This Change Was Made

Three local prechecks reject a connection that has no token, password or stored device token: one in callGatewayWithScopes, ensureExplicitGatewayAuth for --url targets, and the TUI's connection resolver. None of them knew that the proxy authenticates the upgrade. Each now skips the shared-credential requirement when edge-auth headers are configured for the target's origin, using the existing gatewayEdgeAuthValueForTarget origin match. The Gateway's device pairing then decides access, so nothing new is trusted on the client.

First pairing stays in openclaw tui. openclaw gateway call is read-only, so on a device that has never connected it has no device identity to pair; the Gateway accepts the connection and refuses the method with MISSING_SCOPE. When edge-auth headers are set, the call has no device identity and the Gateway answers MISSING_SCOPE, the error now adds Fix: this device is not paired with this Gateway yet. Run \openclaw tui` once to pair this device, ... (withEdgeAuthPairingHintinsrc/gateway/call-device-auth.ts). When the call was given --url, the command in the hint keeps it (openclaw tui --url ), as the existing stored-device-auth recovery message does, because a bare openclaw tuican select another Gateway, such as a local one.call.ts` is over its line cap, so its edge-auth header lookup is inlined, as the TUI's already is, to keep the file from growing.

docs/cli/tui.md and docs/gateway/remote.md say that, when the Gateway uses trusted-proxy auth, the first connection through edgeAuth needs no token and sends a pairing request, and that a Gateway on token or password auth still needs its credential.

Security

Based on a source comparison against main, the CLI connects through Cloudflare Access as another interface to the same Gateway, using Access headers instead of the web UI's browser cookie. Both paths use the same server authentication, scope caps and role limits. This change grants no new scopes. Access headers do not replace Gateway token or password authentication.

New TUI devices still need pairing approval under the Gateway's existing policy. A fresh openclaw gateway call can connect without a device identity, but the server clears its claimed scopes. That device-less session receives scoped access only through explicitly configured identity grants, capped by role limits, as with the existing device-less web UI path. Without those grants, pair through openclaw tui before making scoped calls.

Evidence

  • Tests:

    • New src/gateway/call.edge-auth.test.ts (6 cases) and one new case in src/tui/gateway-chat.connection.test.ts.
    • Pairing hint: an edgeAuth device with no identity that gets MISSING_SCOPE now sees the openclaw tui hint; without this change that case fails with the bare missing scope: operator.read. With gateway.mode: "local" and an explicit --url, the hint names openclaw tui --url <url>; that case fails on d2fade98ea1 with the bare openclaw tui hint. A device with an identity keeps the bare message on both. call.test.ts 91/91.
    • On main, the edgeAuth cases fail with the same errors users see: requires credentials before opening a websocket, gateway url override requires explicit credentials and Missing gateway auth credentials.. With this change they pass.
    • The case for a remote without edgeAuth passes on both, showing that it still requires credentials.
    • Neighbouring suites pass: client-bootstrap.auth.test.ts 6/6, gateway-chat.connection.test.ts 12/12, tui.test.ts 51/51.
    • Typecheck and format are clean. Lint reports nothing in the touched files.
  • Live run at this head (3411a94ae50, built with pnpm build:runtime): a loopback Gateway with gateway.auth.mode: "trusted-proxy", behind a small TLS proxy standing in for Cloudflare Access (it answers 302 unless the request carries Cf-Access-Token, then injects the identity headers). The guest config has only gateway.remote.url and gateway.remote.edgeAuth: no token, no password, no stored device token. --tls-fingerprint is 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 the TUI's request as it was requested.

    Guest and admin terminal output, proxy connect frames, Gateway audit count
$ openclaw tui            # configured target: edgeAuth only, no token or password
gateway connect failed: GatewayClientRequestError: device pairing required (requestId: 51f8be07-4e56-416f-9730-90e2f5fe7893)   (x3, the TUI keeps retrying)
$ openclaw devices list   # admin
pending [('51f8be07-4e56-416f-9730-90e2f5fe7893', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
(admin rejects it, to see the explicit-URL path file its own request)
$ openclaw tui --url wss://127.0.0.1:19742 --tls-fingerprint <test cert>   # explicit URL, no token or password
gateway connect failed: GatewayClientRequestError: device pairing required (requestId: 7066e138-a59c-45d1-9cb2-9486248f6b9f)   (x5, the TUI keeps retrying)
pending [('7066e138-a59c-45d1-9cb2-9486248f6b9f', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
$ openclaw devices approve <that request>   # admin approves it as requested
Approved a9d73fadc5f1... (7066e138-a59c-45d1-9cb2-9486248f6b9f)
$ openclaw devices list   # admin
paired [('a9d73fadc5f1', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals']), ('ba0b74af6efe', 'cli', ['operator.pairing', 'operator.admin'])]
$ openclaw tui            # first start after approval
gateway connected
$ openclaw tui            # second start
gateway connected
$ openclaw gateway call sessions.list --json   # call 1
{ "count": 0, "totalCount": 0, ... }   (exit 0)
$ openclaw gateway call sessions.list --json   # call 2
{ "count": 0, "totalCount": 0, ... }   (exit 0)
$ openclaw devices list   # admin, at the end
pending []

# connect frames the proxy forwarded from step 4 on (device id shortened)
20:56:55 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=none
20:57:43 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=<guest> auth=none
20:58:29 client=cli/cli scopes=["operator.read"] device=<guest> auth=none
20:58:33 client=cli/cli scopes=["operator.read"] device=<guest> auth=none

# Gateway log: 'device access upgrade requested' lines for the guest device
upgrade audit lines for the guest device before step 4: 0
upgrade audit lines after step 4: 0
upgrade audit lines after step 5: 0
upgrade audit lines after call 1: 0
upgrade audit lines after call 2: 0
- **Before, on `main`:** the same client fails all three commands locally (`requires credentials before opening a websocket`, `gateway url override requires explicit credentials`, `Missing gateway auth credentials.`) and the proxy sees no request. - **Live run at `a675d1b23b7`** (same setup, built with `pnpm build:runtime`): the hint names the Gateway that refused. - With a configured remote (`gateway.mode: "remote"`), a fresh device's `openclaw gateway call` gets the bare `openclaw tui` hint, as before. - With `gateway.mode: "local"` and the remote only in `gateway.remote`, `openclaw gateway call --url ` gets `Run \`openclaw tui --url \``. A bare `openclaw tui` there selects the local Gateway and stops with `No Gateway is running on this machine.` - Following that hint literally files a pairing request on the remote; after approval the same `openclaw gateway call --url` succeeds.
Guest and admin terminal output, proxy connect frames
# guestA: gateway.mode remote, gateway.remote.url wss://127.0.0.1:19792 with edgeAuth (configured target)
$ openclaw gateway call sessions.list --json        # fresh guestA
message: "missing scope: operator.read\nFix: this device is not paired with this Gateway yet. Run `openclaw tui` once to pair this device, approve the request in that Gateway's Control UI (Settings -> Devices), then retry."   (exit 1)

# guestB: gateway.mode local, the same gateway.remote.url and edgeAuth; test certificate trusted with NODE_EXTRA_CA_CERTS, no TLS pin
$ openclaw gateway call sessions.list --url wss://127.0.0.1:19792 --json        # fresh guestB
message: "missing scope: operator.read\nFix: this device is not paired with this Gateway yet. Run `openclaw tui --url wss://127.0.0.1:19792` once to pair this device, approve the request in that Gateway's Control UI (Settings -> Devices), then retry."   (exit 1)
$ openclaw tui            # what a bare `openclaw tui` does in guestB's config
No Gateway is running on this machine.
Fix: run `openclaw chat` to chat here without a Gateway, or start one with `openclaw gateway`.
$ openclaw tui --url wss://127.0.0.1:19792            # guestB follows the hint literally
gateway connect failed: GatewayClientRequestError: device pairing required (requestId: dc878255-63e8-4376-80be-b00f72af2b74)   (x5, the TUI keeps retrying)
$ openclaw devices list   # admin
pending [('dc878255-63e8-4376-80be-b00f72af2b74', '2b6da3028cd3', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
$ openclaw devices approve <that request>   # admin
Approved 2b6da3028cd3... (dc878255-63e8-4376-80be-b00f72af2b74)
$ openclaw gateway call sessions.list --url wss://127.0.0.1:19792 --json        # guestB retries
{ "count": 0, ... }   (exit 0)
$ openclaw devices list   # admin
pending []

# connect frames the proxy forwarded (guestB is 2b6da3028cd3)
04:06:02 client=cli/cli scopes=["operator.read"] device=none auth=none
04:06:15 client=cli/cli scopes=["operator.read"] device=none auth=none
04:07:02 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=2b6da3028cd3 auth=none
04:07:03 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=2b6da3028cd3 auth=none
04:07:05 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=2b6da3028cd3 auth=none
04:07:10 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=2b6da3028cd3 auth=none
04:07:19 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=2b6da3028cd3 auth=none
04:08:03 client=cli/cli scopes=["operator.read"] device=2b6da3028cd3 auth=none
- **Live run at `d2fade98ea1`** (same setup, built with `pnpm build:runtime`), covering first pairing and reconnect for `openclaw gateway call` and for the explicit-URL TUI: - A fresh device's first `openclaw gateway call` connects with `device=none`, is refused with `MISSING_SCOPE`, and files no pairing request; the error names `openclaw tui`. - After that device runs `openclaw tui` and the admin approves the request it filed, the same `openclaw gateway call` succeeds. - A fresh device's `openclaw tui --url` files a pairing request; after approval, the same command reaches `gateway connected`.
Guest and admin terminal output, proxy connect frames
$ openclaw gateway call sessions.list --json        # fresh guest1: edgeAuth only, no device identity yet
{ "ok": false, "error": { "type": "gateway_request_error", "code": "FORBIDDEN",
  "message": "missing scope: operator.read\nFix: this device is not paired with this Gateway yet. Run `openclaw tui` once to pair this device, approve the request in that Gateway's Control UI (Settings -> Devices), then retry.",
  "details": { "code": "MISSING_SCOPE", "missingScope": "operator.read", "requiredScopes": ["operator.read"] }, "retryable": false } }   (exit 1)
$ openclaw devices list   # admin
pending []
$ openclaw tui            # guest1 follows the hint
$ openclaw devices list   # admin
pending [('6227ddc0-1c75-4237-8aae-c04732bb52ab', '0fa1ad37d74e', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
$ openclaw devices approve <that request>   # admin
Approved 0fa1ad37d74e... (6227ddc0-1c75-4237-8aae-c04732bb52ab)
$ openclaw gateway call sessions.list --json        # guest1 after approval
{ "count": 0, ... }   (exit 0)

$ openclaw tui --url wss://127.0.0.1:19792 --tls-fingerprint <test cert>   # fresh guest2, explicit URL, first contact
gateway connect failed: GatewayClientRequestError: device pairing required (requestId: a44cfc85-a5bb-4296-b6c6-f427778f384c)   (x2, the TUI keeps retrying)
$ openclaw devices list   # admin
pending [('a44cfc85-a5bb-4296-b6c6-f427778f384c', 'b59c574c4b50', 'openclaw-tui', ['operator.admin', 'operator.read', 'operator.write', 'operator.approvals'])]
$ openclaw devices approve <that request>   # admin
Approved b59c574c4b50... (a44cfc85-a5bb-4296-b6c6-f427778f384c)
$ openclaw tui --url wss://127.0.0.1:19792 --tls-fingerprint <test cert>   # guest2 reconnects after approval
gateway connected
$ openclaw devices list   # admin
pending []

# connect frames the proxy forwarded (guest1 is 0fa1ad37d74e, guest2 is b59c574c4b50)
01:58:29 client=cli/cli scopes=["operator.read"] device=none auth=none
01:59:22 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=0fa1ad37d74e auth=none
01:59:23 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=0fa1ad37d74e auth=none
01:59:25 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=0fa1ad37d74e auth=none
02:00:35 client=cli/cli scopes=["operator.read"] device=0fa1ad37d74e auth=none
02:01:20 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=b59c574c4b50 auth=none
02:01:22 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=b59c574c4b50 auth=none
02:01:24 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=b59c574c4b50 auth=none
02:01:29 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=b59c574c4b50 auth=none
02:02:12 client=openclaw-tui/ui scopes=["operator.admin","operator.read","operator.write","operator.approvals"] device=b59c574c4b50 auth=none

…oken

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.
@clawsweeper

clawsweeper Bot commented Nov 15, 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 size: S labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head a675d1b23b7d0183f72a16fa895f432c91c89807, but the PR head is now 006109c678d6bb5389c8f7c4d801649763898d6e. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (4 earlier review cycles)
  • reviewed 2026-11-15T17:20:56.397Z sha 3022bf3 :: needs real behavior proof before merge. :: [P2] [P2] Qualify tokenless pairing guidance by Gateway authentication mode
  • reviewed 2026-11-15T21:13:23.055Z sha 3411a94 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-16T02:13:06.760Z sha d2fade9 :: blocked before merge. :: [P2] Preserve the selected Gateway in the pairing hint
  • reviewed 2026-11-16T04:19:38.670Z sha a675d1b :: blocked before merge. :: none

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Maintainer security changes approved

A maintainer approved this revision with an explicit security approval comment.

A later push requires a fresh approval comment for an external contributor's PR.

@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 16, 2026
@daniel-lxs

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 16, 2026
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 20, 2026
@hannesrudolph

Copy link
Copy Markdown
Member

/allow-security-sensitive-change

@hannesrudolph
hannesrudolph merged commit 39feba6 into openclaw:main Nov 20, 2026
122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. security-sensitive-changed size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI and TUI won't connect through gateway.remote.edgeAuth without a Gateway token, so a Cloudflare Access user can't send the first pairing request

2 participants