Skip to content

Commit 58b0ec9

Browse files
authored
feat(gateway): auto-approve node pairing via SSH device-key verification (#104180)
1 parent dc42c89 commit 58b0ec9

30 files changed

Lines changed: 1515 additions & 157 deletions

‎docs/cli/devices.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Approval behavior:
5656
- If the device is already paired and requests broader scopes or role, OpenClaw keeps the existing approval and creates a new pending upgrade request. Compare `Requested` vs `Approved` in `openclaw devices list`, or preview with `--latest`, before approving.
5757
- Approving a `node` role or other non-operator role requires `operator.admin`. `operator.pairing` is enough for operator-device approvals, but only when the requested operator scopes stay within the caller's own scopes. See [Operator scopes](/gateway/operator-scopes).
5858
- If `gateway.nodes.pairing.autoApproveCidrs` is configured, first-time `role: node` requests from matching client IPs can be auto-approved before they appear in this list. Disabled by default; never applies to operator/browser clients or upgrade requests.
59+
- `gateway.nodes.pairing.sshVerify` (on by default) auto-approves first-time `role: node` requests when the gateway verifies the device key over SSH to the node host. Requests may therefore resolve to approved shortly after appearing. Set `sshVerify: false` to disable SSH verification; this is independent of `autoApproveCidrs`, so unset that too for manual-only pairing.
5960

6061
### `openclaw devices reject <requestId>`
6162

‎docs/cli/node.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,30 @@ the foreground flow so the pending request can be approved.
129129
## Pairing
130130

131131
The first connection creates a pending device pairing request (`role: node`) on the Gateway.
132-
Approve it via:
132+
133+
When the Gateway host can SSH to the node host non-interactively (same user,
134+
trusted host key), the pending request is approved automatically: the Gateway
135+
runs `openclaw node identity --json` on the node host over SSH and approves on
136+
an exact device-key match. This is on by default; see
137+
[SSH-verified device auto-approval](/gateway/pairing#ssh-verified-device-auto-approval-default)
138+
for requirements and how to disable it (`gateway.nodes.pairing.sshVerify: false`).
139+
140+
Otherwise approve manually via:
133141

134142
```bash
135143
openclaw devices list
136144
openclaw devices approve <requestId>
137145
```
138146

147+
Inspect the local node identity the Gateway verifies against:
148+
149+
```bash
150+
openclaw node identity --json
151+
```
152+
153+
It prints the device ID and public key from `identity/device.json` and never
154+
creates or modifies identity files.
155+
139156
On tightly controlled node networks, the Gateway operator can explicitly opt in
140157
to auto-approving first-time node pairing from trusted CIDRs:
141158

‎docs/cli/nodes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ These commands drive the gateway-owned `node.pair.*` store, separate from device
4141
- `remove` revokes the node's paired-role entry. For a device-backed node this revokes the `node` role in the device pairing store and disconnects its node-role sessions: a mixed-role device keeps its row and only loses the `node` role, a node-only device row is deleted. It also clears any matching legacy gateway-owned node pairing record.
4242
- `pending` only needs `operator.pairing` scope.
4343
- `gateway.nodes.pairing.autoApproveCidrs` can skip the pending step for explicitly trusted, first-time `role: node` device pairing. Off by default; does not approve role upgrades.
44+
- `gateway.nodes.pairing.sshVerify` (on by default) auto-approves first-time `role: node` device pairing when the gateway can verify the device key over SSH to the node host; the first capability surface is approved in the same step. See [Node pairing](/gateway/pairing#ssh-verified-device-auto-approval-default).
4445
- `approve` scope requirements follow the pending request's declared commands:
4546
- commandless request: `operator.pairing`
4647
- non-exec node commands: `operator.pairing` + `operator.write`

‎docs/docs_map.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,6 +3589,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
35893589
- H2: API surface (gateway protocol)
35903590
- H2: Node command gating (2026.3.31+)
35913591
- H2: Node event trust boundaries (2026.3.31+)
3592+
- H2: SSH-verified device auto-approval (default)
35923593
- H2: Auto-approval (macOS app)
35933594
- H2: Trusted-CIDR device auto-approval
35943595
- H2: Silent pairing supersede cleanup

‎docs/gateway/configuration-reference.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ See [Inferred commitments](/concepts/commitments).
564564
pairing: {
565565
// Optional. Default unset/disabled.
566566
autoApproveCidrs: ["192.168.1.0/24", "fd00:1234:5678::/64"],
567+
// SSH-verified auto-approval. Default: enabled (true).
568+
// Set false to disable SSH verification only; this does not affect
569+
// autoApproveCidrs above. For manual-only node pairing, set false AND
570+
// unset autoApproveCidrs. Pass an object to tune: { user, identity,
571+
// timeoutMs, cidrs }.
572+
sshVerify: true,
567573
},
568574
allowCommands: ["canvas.navigate"],
569575
denyCommands: ["system.run"],
@@ -642,6 +648,7 @@ See [Inferred commitments](/concepts/commitments).
642648
- `trustedProxies`: reverse proxy IPs that terminate TLS or inject forwarded-client headers. Only list proxies you control. Loopback entries are still valid for same-host proxy/local-detection setups (for example Tailscale Serve or a local reverse proxy), but they do **not** make loopback requests eligible for `gateway.auth.mode: "trusted-proxy"`.
643649
- `allowRealIpFallback`: when `true`, the gateway accepts `X-Real-IP` if `X-Forwarded-For` is missing. Default `false` for fail-closed behavior.
644650
- `gateway.nodes.pairing.autoApproveCidrs`: optional CIDR/IP allowlist for auto-approving first-time node device pairing with no requested scopes. It is disabled when unset. This does not auto-approve operator/browser/Control UI/WebChat pairing, and it does not auto-approve role, scope, metadata, or public-key upgrades.
651+
- `gateway.nodes.pairing.sshVerify`: SSH-verified auto-approval for first-time node device pairing (default: enabled). The gateway SSHes back to the pairing host (BatchMode, strict host keys) and approves only on an exact `openclaw node identity` device-key match. Same eligibility floor as `autoApproveCidrs`; probes are limited to private/CGNAT source addresses unless `cidrs` overrides them. Set `false` to disable, or `{ user, identity, timeoutMs, cidrs }` to tune. See [Node pairing](/gateway/pairing#ssh-verified-device-auto-approval-default).
645652
- `gateway.nodes.allowCommands` / `gateway.nodes.denyCommands`: global allow/deny shaping for declared node commands after pairing and platform allowlist evaluation. Use `allowCommands` to opt into dangerous node commands such as `camera.snap`, `camera.clip`, `screen.record`, `sms.search`, and `sms.send`; `denyCommands` removes a command even if a platform default or explicit allow would otherwise include it. Android SMS permission and Gateway command authorization are independent. After a node changes its declared command list, reject and re-approve that device pairing so the gateway stores the updated command snapshot.
646653
- `gateway.tools.deny`: extra tool names blocked for HTTP `POST /tools/invoke` (extends default deny list).
647654
- `gateway.tools.allow`: remove tool names from the default HTTP deny list for

‎docs/gateway/pairing.md‎

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,63 @@ sessions, and updates pairing metadata only when the device/node identity is
139139
already paired. A self-declared `client.id` value is not enough to write
140140
last-seen state.
141141

142+
## SSH-verified device auto-approval (default)
143+
144+
First-time `role: node` device pairing from a private/CGNAT address is
145+
auto-approved when the gateway can **prove machine ownership over SSH**: it
146+
connects back to the pairing host (`BatchMode`, `StrictHostKeyChecking=yes`),
147+
runs `openclaw node identity --json` there, and approves only when the remote
148+
device id and public key match the pending request exactly. The key match is
149+
what makes this safe: reachability alone never approves, so NAT co-tenants,
150+
other users on a shared host, and LAN spoofing all fall through to the normal
151+
prompt.
152+
153+
Enabled by default. Requirements for it to fire:
154+
155+
- The gateway process user (or `sshVerify.user`) can SSH to the node host
156+
non-interactively (keys/agent; Tailscale SSH works too), and the host key is
157+
already trusted.
158+
- `openclaw` resolves on the remote `PATH` for non-interactive `sh -lc`.
159+
- The connecting IP is a direct (non-proxied, non-loopback) private, ULA,
160+
link-local, or CGNAT address, or matches `sshVerify.cidrs` when set.
161+
- Same eligibility floor as trusted-CIDR approval: fresh scopeless node
162+
pairing only; upgrades, browsers, Control UI, and WebChat always prompt.
163+
164+
While a probe is running, the node client is told to keep retrying
165+
(`wait_then_retry`) instead of pausing for manual approval; if the probe
166+
fails, the next attempt falls back to the normal prompt flow. Failed targets
167+
get a short cooldown (5 minutes after a key mismatch).
168+
169+
Approved devices record `approvedVia: "ssh-verified"` and their first declared
170+
capability surface is approved in the same step — the key match already proves
171+
the node runs under the operator's account on a machine they own, which is the
172+
same claim a manual capability approval asserts. Later surface upgrades still
173+
prompt.
174+
175+
Harden or disable:
176+
177+
```json5
178+
{
179+
gateway: {
180+
nodes: {
181+
pairing: {
182+
// Disable entirely:
183+
sshVerify: false,
184+
// ...or scope/tune the probe:
185+
// sshVerify: { user: "me", identity: "~/.ssh/probe", timeoutMs: 7000, cidrs: ["10.0.0.0/8"] },
186+
},
187+
},
188+
},
189+
}
190+
```
191+
142192
## Auto-approval (macOS app)
143193

144-
The macOS app can attempt a **silent approval** when:
194+
The macOS app can attempt a **silent approval** of node capability requests
195+
when:
145196

146-
- the request is marked `silent`, and
197+
- the request is marked `silent` (the gateway marks the first capability
198+
surface silent when device pairing was approved non-interactively), and
147199
- the app can verify an SSH connection to the gateway host using the same
148200
user.
149201

@@ -170,7 +222,9 @@ in with explicit CIDRs or exact IPs:
170222
Security boundary:
171223

172224
- Disabled when `gateway.nodes.pairing.autoApproveCidrs` is unset.
173-
- No blanket LAN or private-network auto-approve mode exists.
225+
- No blanket LAN or private-network auto-approve mode exists; SSH-verified
226+
auto-approval (above) requires a cryptographic device-key match, never
227+
network locality alone.
174228
- Only a fresh `role: node` device pairing request with no requested scopes is
175229
eligible.
176230
- Operator, browser, Control UI, and WebChat clients stay manual.
@@ -182,7 +236,7 @@ Security boundary:
182236

183237
Non-interactive approvals record their provenance on the paired-device row:
184238
same-host local policy approvals as `silent`, trusted-CIDR node approvals as
185-
`trusted-cidr`. Clients whose state directory is ephemeral (temporary homes,
239+
`trusted-cidr`, SSH-verified node approvals as `ssh-verified`. Clients whose state directory is ephemeral (temporary homes,
186240
containers, per-run sandboxes) mint a fresh device keypair per run, and every
187241
run silently re-pairs as a brand-new device — without cleanup the paired list
188242
grows one stale row per run.
@@ -198,10 +252,10 @@ removal event is broadcast.
198252
Boundaries:
199253

200254
- Only records whose latest approval was same-host local (`silent`) are
201-
eligible, as trigger and as target. Trusted-CIDR pairings cross hosts where
202-
display metadata is not a machine identity, so they are never removed
203-
automatically — use the Control UI cleanup or `openclaw nodes remove` for
204-
those.
255+
eligible, as trigger and as target. Trusted-CIDR and SSH-verified pairings
256+
cross hosts where display metadata is not a machine identity, so they are
257+
never removed automatically — use the Control UI cleanup or
258+
`openclaw nodes remove` for those.
205259
- Owner-approved and QR/setup-code (bootstrap) pairings are never removed
206260
automatically. Records approved before provenance existed stay protected,
207261
even after a later silent re-approval of the same device id.

‎docs/gateway/security/index.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Quick model for triaging risk reports:
106106
| Local TUI `!` shell | Explicit operator-triggered local execution | "Local shell convenience command is remote injection" |
107107
| Node pairing and node commands | Operator-level remote execution on paired devices | "Remote device control should be treated as untrusted user access by default" |
108108
| `gateway.nodes.pairing.autoApproveCidrs` | Opt-in trusted-network node enrollment policy | "A disabled-by-default allowlist is an automatic pairing vulnerability" |
109+
| `gateway.nodes.pairing.sshVerify` | Key-verified node enrollment over operator SSH | "Default-on auto-approval is an automatic pairing vulnerability" |
109110

110111
## Not vulnerabilities by design
111112

@@ -117,6 +118,7 @@ Quick model for triaging risk reports:
117118
- Localhost-only deployment findings (for example missing HSTS on a loopback-only gateway).
118119
- Discord inbound webhook signature findings for inbound paths that do not exist in this repo.
119120
- Node pairing metadata treated as a hidden second per-command approval layer for `system.run`; the real execution boundary is the gateway's global node command policy plus the node's own exec approvals.
121+
- `gateway.nodes.pairing.sshVerify` treated as a vulnerability because it is enabled by default. It never approves on network locality or SSH reachability alone: the gateway reads the device identity back over SSH (BatchMode, strict host keys) and approves only on an exact device-key match with the pending request, which requires the connecting keypair to already live under the operator's account on a host the operator controls. Probes are bounded to private/CGNAT source addresses, share the trusted-CIDR eligibility floor (fresh scopeless `role: node` only), and `sshVerify: false` turns the feature off.
120122
- `gateway.nodes.pairing.autoApproveCidrs` treated as a vulnerability by itself. It is disabled by default, requires explicit CIDR/IP entries, only applies to first-time `role: node` pairing with no requested scopes, and never auto-approves operator/browser/Control UI, WebChat, role/scope upgrades, metadata or public-key changes, or same-host loopback trusted-proxy header paths (even when loopback trusted-proxy auth is enabled).
121123
- "Missing per-user authorization" findings that treat `sessionKey` as an auth token.
122124

‎docs/nodes/index.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ Node-related settings live under `gateway.nodes` and `tools.exec`:
261261
// with no requested scopes; does not auto-approve upgrades.
262262
pairing: {
263263
autoApproveCidrs: ["192.168.1.0/24"],
264+
// SSH-verified auto-approval (default: enabled). Approves first-time
265+
// node pairing on an exact device-key match read back over SSH.
266+
sshVerify: true,
264267
},
265268
// Opt into dangerous/privacy-heavy node commands (camera.snap, etc.).
266269
allowCommands: ["camera.snap", "screen.record"],

‎src/cli/node-cli/identity.test.ts‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Node identity CLI tests: read-only output of the node host device identity.
2+
import fs from "node:fs";
3+
import os from "node:os";
4+
import path from "node:path";
5+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6+
import {
7+
loadOrCreateDeviceIdentity,
8+
publicKeyRawBase64UrlFromPem,
9+
} from "../../infra/device-identity.js";
10+
import { defaultRuntime } from "../../runtime.js";
11+
import { runNodeIdentityShow } from "./identity.js";
12+
13+
describe("runNodeIdentityShow", () => {
14+
let stateDir: string;
15+
let prevStateDir: string | undefined;
16+
let logSpy: ReturnType<typeof vi.spyOn>;
17+
let errorSpy: ReturnType<typeof vi.spyOn>;
18+
let exitSpy: ReturnType<typeof vi.spyOn>;
19+
20+
beforeEach(() => {
21+
stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-node-identity-"));
22+
prevStateDir = process.env.OPENCLAW_STATE_DIR;
23+
process.env.OPENCLAW_STATE_DIR = stateDir;
24+
logSpy = vi.spyOn(defaultRuntime, "log").mockImplementation(() => {});
25+
errorSpy = vi.spyOn(defaultRuntime, "error").mockImplementation(() => {});
26+
exitSpy = vi.spyOn(defaultRuntime, "exit").mockImplementation(() => {});
27+
});
28+
29+
afterEach(() => {
30+
if (prevStateDir === undefined) {
31+
delete process.env.OPENCLAW_STATE_DIR;
32+
} else {
33+
process.env.OPENCLAW_STATE_DIR = prevStateDir;
34+
}
35+
logSpy.mockRestore();
36+
errorSpy.mockRestore();
37+
exitSpy.mockRestore();
38+
fs.rmSync(stateDir, { recursive: true, force: true });
39+
});
40+
41+
it("fails closed when no identity exists (never mints one)", () => {
42+
runNodeIdentityShow({});
43+
expect(errorSpy).toHaveBeenCalledOnce();
44+
expect(exitSpy).toHaveBeenCalledWith(1);
45+
expect(fs.existsSync(path.join(stateDir, "identity", "device.json"))).toBe(false);
46+
});
47+
48+
it("prints deviceId and raw public key as JSON", () => {
49+
const identity = loadOrCreateDeviceIdentity(path.join(stateDir, "identity", "device.json"));
50+
runNodeIdentityShow({ json: true });
51+
expect(exitSpy).not.toHaveBeenCalled();
52+
expect(logSpy).toHaveBeenCalledOnce();
53+
const parsed = JSON.parse(String(logSpy.mock.calls[0]?.[0])) as {
54+
deviceId: string;
55+
publicKey: string;
56+
};
57+
expect(parsed).toEqual({
58+
deviceId: identity.deviceId,
59+
publicKey: publicKeyRawBase64UrlFromPem(identity.publicKeyPem),
60+
});
61+
});
62+
63+
it("prints human-readable lines without --json", () => {
64+
const identity = loadOrCreateDeviceIdentity(path.join(stateDir, "identity", "device.json"));
65+
runNodeIdentityShow({});
66+
expect(exitSpy).not.toHaveBeenCalled();
67+
const output = logSpy.mock.calls.map((call: unknown[]) => String(call[0])).join("\n");
68+
expect(output).toContain(identity.deviceId);
69+
expect(output).toContain(publicKeyRawBase64UrlFromPem(identity.publicKeyPem));
70+
});
71+
});

‎src/cli/node-cli/identity.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Prints the local node host device identity for pairing verification.
2+
import {
3+
loadDeviceIdentityIfPresent,
4+
publicKeyRawBase64UrlFromPem,
5+
} from "../../infra/device-identity.js";
6+
import { defaultRuntime } from "../../runtime.js";
7+
8+
/**
9+
* Read-only by design: the SSH-verified pairing probe calls this remotely and
10+
* must never mint a fresh identity on a host that has not run the node host.
11+
*/
12+
export function runNodeIdentityShow(opts: { json?: boolean }) {
13+
const identity = loadDeviceIdentityIfPresent();
14+
if (!identity) {
15+
defaultRuntime.error(
16+
"no node device identity found (start the node host once with `openclaw node run` or `openclaw node install`)",
17+
);
18+
defaultRuntime.exit(1);
19+
return;
20+
}
21+
const payload = {
22+
deviceId: identity.deviceId,
23+
publicKey: publicKeyRawBase64UrlFromPem(identity.publicKeyPem),
24+
};
25+
if (opts.json) {
26+
defaultRuntime.log(JSON.stringify(payload));
27+
return;
28+
}
29+
defaultRuntime.log(`deviceId: ${payload.deviceId}`);
30+
defaultRuntime.log(`publicKey: ${payload.publicKey}`);
31+
}

0 commit comments

Comments
 (0)