Repository navigation
fix(cli): connect through gateway.remote.edgeAuth without a Gateway token - #199693
Conversation
…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.
|
🦞👀 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. |
|
Codex review: stale review; fresh review needed. Summary Next step Review history (4 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
✅ 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
/allow-security-sensitive-change |
Closes #199691
What Problem This Solves
Fixes:
openclaw tui,openclaw tui --urlandopenclaw gateway callrefuse to dial a Gateway behind Cloudflare Access (or another identity-aware proxy) when the client hasgateway.remote.edgeAuthbut 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.edgeAuthconnects to a trusted-proxy Gateway without a shared Gateway secret. On first contactopenclaw tuigetsdevice pairing requiredand 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 throughopenclaw tui; itsopenclaw gateway callnow says so instead of answering with a baremissing 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,ensureExplicitGatewayAuthfor--urltargets, 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 existinggatewayEdgeAuthValueForTargetorigin 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 callis 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 withMISSING_SCOPE. When edge-auth headers are set, the call has no device identity and the Gateway answersMISSING_SCOPE, the error now addsFix: 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 bareopenclaw 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.mdanddocs/gateway/remote.mdsay 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 callcan 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 throughopenclaw tuibefore making scoped calls.Evidence
Tests:
src/gateway/call.edge-auth.test.ts(6 cases) and one new case insrc/tui/gateway-chat.connection.test.ts.MISSING_SCOPEnow sees theopenclaw tuihint; without this change that case fails with the baremissing scope: operator.read. Withgateway.mode: "local"and an explicit--url, the hint namesopenclaw tui --url <url>; that case fails ond2fade98ea1with the bareopenclaw tuihint. A device with an identity keeps the bare message on both.call.test.ts91/91.main, the edgeAuth cases fail with the same errors users see:requires credentials before opening a websocket,gateway url override requires explicit credentialsandMissing gateway auth credentials.. With this change they pass.client-bootstrap.auth.test.ts6/6,gateway-chat.connection.test.ts12/12,tui.test.ts51/51.Live run at this head (
3411a94ae50, 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 the TUI's request as it was requested.Guest and admin terminal output, proxy connect frames, Gateway audit count
Guest and admin terminal output, proxy connect frames
Guest and admin terminal output, proxy connect frames