@johnhenry/wsh 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -2
- package/bin/wsh-mcp.mjs +92 -0
- package/package.json +9 -1
- package/src/host.d.ts +3 -1
- package/src/key-options.mjs +508 -0
- package/src/mcp-stdio.d.ts +54 -0
- package/src/mcp-stdio.mjs +310 -0
- package/src/memory-host.d.ts +1 -1
- package/src/memory-host.mjs +1 -1
- package/src/refusal.mjs +7 -1
- package/src/server/auth.mjs +67 -29
- package/src/server/connection.mjs +115 -6
- package/src/server/index.d.ts +51 -4
- package/src/server/index.mjs +3 -3
package/README.md
CHANGED
|
@@ -250,6 +250,102 @@ ends every authenticated connection `n` ms after login and advertises it
|
|
|
250
250
|
limit and sends `ttl: 0`. Before 0.36 it sent an unenforced 3600. The Rust
|
|
251
251
|
`wsh-server` still sends its `session_ttl` setting unenforced.
|
|
252
252
|
|
|
253
|
+
### Authorized-key options (#122)
|
|
254
|
+
|
|
255
|
+
`auth.authorizedKeys` takes `authorized_keys` lines with options, and reads them the way the Rust `wsh-server` does: **the same
|
|
256
|
+
key file gives the same answer on both hosts.** The two parsers share one set of test vectors
|
|
257
|
+
(`spec/key-options.vectors.json`: a key line gives these permissions, a request is allowed or refused with this code), run by the
|
|
258
|
+
JS suite and by a Rust test, so they cannot drift.
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
restrict,permit-exec,max-sessions=2 ssh-ed25519 AAAA... ci@build
|
|
262
|
+
command="/usr/bin/uptime" ssh-ed25519 AAAA... monitor
|
|
263
|
+
no-pty ssh-ed25519 AAAA... alice
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
A line is `[options] ssh-ed25519 <base64> [comment]`. The options are one token (spaces only inside double quotes) of
|
|
267
|
+
comma-separated items, each `name` or `name=value`; a value is `"..."` (`\"` is a quote, any other backslash is literal) or, for
|
|
268
|
+
values without spaces, a bare word. Single quotes are not quotes. Names are case-sensitive.
|
|
269
|
+
|
|
270
|
+
| Option | Meaning | Node host (`@johnhenry/wsh/server`) | Rust `wsh-server` |
|
|
271
|
+
|---|---|---|---|
|
|
272
|
+
| *(none)* | full access: everything the host is configured to offer | as before | as before |
|
|
273
|
+
| `restrict` | grant nothing; add back with `permit-*` | all entries below | all entries below |
|
|
274
|
+
| `permit-pty` | a pty shell, and commands (a shell can run them) | `Open` kind `pty`, `exec` | `Open` kind `pty`, `exec` |
|
|
275
|
+
| `permit-exec` | `exec` channels | `Open` kind `exec` | `Open` kind `exec` |
|
|
276
|
+
| `permit-file-transfer` | file channels, `FileOp`, `wsh-fs` | `Open` kind `file` (upload, download), `FileOp`, rpc `wsh-fs` | the same |
|
|
277
|
+
| `permit-mcp` | MCP discovery and calls | `McpDiscover` (an empty list otherwise), `McpCall`, rpc `mcp` | `McpDiscover`, `McpCall` (no rpc `mcp`) |
|
|
278
|
+
| `permit-relay` | relay registration, listing and connecting | `ReverseRegister`, `ReverseList`, `ReverseConnect` (`relay`) | the same (`--enable-relay`) |
|
|
279
|
+
| *(any restriction)* | a key that is not wholly unrestricted may not install another key | no `AuthorizedKeyAdd` handler | `AuthorizedKeyAdd` (the installed line has no options, so it would otherwise mint an unrestricted key) |
|
|
280
|
+
| `no-pty` | no pty, even when otherwise permitted | `Open` kind `pty` | `Open` kind `pty` |
|
|
281
|
+
| `command="..."` | the only command the key may run; it replaces what the client asks for, and the key gets no pty, files, MCP, relay or rpc | `Open` (exec only), `FileOp`, rpc | the same |
|
|
282
|
+
| `max-sessions=N` (N >= 1) | at most N live pty/exec sessions for the key, over all its connections | counted on this host (detached hosted sessions too) | counted by the session manager |
|
|
283
|
+
| `no-agent-forwarding`, `no-port-forwarding`, `no-X11-forwarding`, `no-user-rc` | accepted, **no effect** (see below) | ignored | ignored |
|
|
284
|
+
|
|
285
|
+
Without `restrict`, the `permit-*` options change nothing. Another rpc protocol (one the embedder added) is open only to a key
|
|
286
|
+
that is not restricted at all; `wsh-host` is open to every key but a forced-command one.
|
|
287
|
+
|
|
288
|
+
**An option this host does not understand refuses the key**: it is not on the allowlist, and the reason is logged (the Node
|
|
289
|
+
host's `onLog`, the Rust server's log: `key refused ... code=unknown-option`). It is never skipped and then granted. The same
|
|
290
|
+
for a malformed value: `max-sessions=0` (it used to mean "no limit" on the Rust server), an empty `command=""`, an option given
|
|
291
|
+
twice, a stray comma. Refusal codes: `unknown-option`, `bad-syntax`, `bad-value`, `duplicate-option`. A line whose options
|
|
292
|
+
cannot be separated from the key (an unterminated quote) or whose key is not `ssh-ed25519` is skipped. If a key appears on
|
|
293
|
+
several lines the first decides.
|
|
294
|
+
|
|
295
|
+
`parseAuthorizedKeys(text)` still returns bare keys, and now only for lines **without** options (it never hands out a key with
|
|
296
|
+
its restrictions dropped); `parseAuthorizedKeyEntries(text)` returns `{ entries, refused }` with each key's permissions.
|
|
297
|
+
|
|
298
|
+
Not covered by `restrict` and the `permit-*` options (see [Security model](#security-model)): the **gateway** (TCP, DNS, unix,
|
|
299
|
+
endpoints, reverse listeners) and the **targets**, so `restrict` and `no-port-forwarding` do not stop a key from using a gateway
|
|
300
|
+
the host has turned on; scope them with `capabilities` below. `no-port-forwarding` is accepted for ssh compatibility and does nothing.
|
|
301
|
+
|
|
302
|
+
#### Capabilities and expiry (#122, step two)
|
|
303
|
+
|
|
304
|
+
Two more options give a key a finer, **default-deny** licence. Nothing changes for a key line that has neither.
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
capabilities="exec,fs:read,gateway:tcp:db.internal:5432,mcp:search" ssh-ed25519 AAAA... ci@build
|
|
308
|
+
expires="2030-01-01T00:00:00Z" ssh-ed25519 AAAA... contractor
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
`capabilities="a,b,c"` (comma-separated, no spaces) lists what the key may do; **once the option is present the key may do only
|
|
312
|
+
that**, on top of what its other options allow (the two are ANDed: `restrict,permit-exec,capabilities="exec,pty"` still has no
|
|
313
|
+
pty). `capabilities=""` is a key that may do nothing. `expires="<RFC 3339>"` (`2030-01-01T00:00:00Z` or with an offset; whole
|
|
314
|
+
seconds; upper-case `T`/`Z`) refuses the key from that second: at login, and for every request after it. An unknown capability, a
|
|
315
|
+
malformed argument or a bad timestamp refuses the key (logged with the code `unknown-capability`, `bad-capability` or
|
|
316
|
+
`bad-value`), as unknown options do.
|
|
317
|
+
|
|
318
|
+
| Capability | What it allows | Entry points (Node host / Rust `wsh-server`) |
|
|
319
|
+
|---|---|---|
|
|
320
|
+
| `exec` | `exec` channels | `Open` kind `exec` / the same |
|
|
321
|
+
| `pty` | a pty shell (does **not** imply `exec`) | `Open` kind `pty` / the same |
|
|
322
|
+
| `fs:read` | stat, list, read, download | `FileOp` `stat` `list` `read`, `Open` kind `file` download / the same |
|
|
323
|
+
| `fs:write` | write, mkdir, remove, rename, upload (does not read) | `FileOp` `write` `mkdir` `remove` `rename` (an op nobody knows is a write), `Open` kind `file` upload / the same |
|
|
324
|
+
| `gateway:tcp:<host>:<port>` | `OpenTcp` to that destination; also `ResolveDns` for a host that matches | the Node gateway / the Rust gateway |
|
|
325
|
+
| `gateway:udp:<host>:<port>` | `OpenUdp` to that destination | the same |
|
|
326
|
+
| `gateway:listen:tcp:<port>` | a reverse TCP listener (`ListenRequest`) on that port | `gateway.reverse` / `enable_reverse_tunnels` |
|
|
327
|
+
| `unix:<path>` , `unix:listen:<path>` | connect to, or listen on, that unix socket | `OpenUnix` / `ListenUnix` |
|
|
328
|
+
| `endpoint:<name>` | a named endpoint | Node host only: the Rust server has none and refuses every `OpenEndpoint`, whatever a key holds |
|
|
329
|
+
| `mcp:<tool>` | list and call that tool (`mcp:*`: every tool, and the `mcp` rpc channel) | `McpDiscover` lists only these, `McpCall` / the same |
|
|
330
|
+
| `target:<name>` | name that target in `Open`, `FileOp`, `OpenEndpoint`; `ListTargets` shows only these | Node host only: the Rust server has no targets and refuses a request that names one |
|
|
331
|
+
| `rpc:<protocol>` | open that rpc protocol (`wsh-host`, or an embedder's own) | `Open` kind `rpc` / the same |
|
|
332
|
+
| `relay` | register, list and connect through the relay | `ReverseRegister` `ReverseList` `ReverseConnect` / the same |
|
|
333
|
+
|
|
334
|
+
`<host>` is a name, an IP literal (IPv6 in brackets), `*`, or `*.suffix` (any subdomain, not the apex; the name is compared
|
|
335
|
+
case-insensitively as the client sent it, so resolution is the gateway's `allow` policy's business). `<port>` is a number or `*`.
|
|
336
|
+
`<path>` is absolute with no `.` or `..`, exact or ending in `/*` (anything below that directory). `<name>`/`<tool>` are exact or `*`.
|
|
337
|
+
The `wsh-fs` rpc channel puts read and write methods on one channel, so it needs **both** `fs:read` and `fs:write`; a client without
|
|
338
|
+
both falls back to `FileOp` and the file channels, which are checked per operation. A request with no target runs on the host's own
|
|
339
|
+
backends and needs no `target:` capability (use `requireTarget` to confine keys to targets). Installing a key (`AuthorizedKeyAdd`) is never
|
|
340
|
+
allowed for a key with a capability list. A custom `authorize` on `createWshServer` / `createMemoryHost` may return `{ capabilities,
|
|
341
|
+
expires }` instead of `true`: the same grammar, narrowing the key's own options (it never widens them).
|
|
342
|
+
|
|
343
|
+
Refusals name the missing capability (`missing capability fs:write`, `missing capability gateway:tcp:db.internal:22`) in the answer
|
|
344
|
+
the client already gets (`OpenFail`, a failed `FileResult`, `GatewayFail`, `ListenFail`, an MCP result, a relay `Error` /
|
|
345
|
+
`ReverseReject`, `AuthFail` for an expired key), and the Node host reports each one to `onRefused` with the stable reason
|
|
346
|
+
`not-permitted` (`detail`: `capability-missing: missing capability exec (open exec)`), or `key-expired`. The Rust server logs them.
|
|
347
|
+
`capabilities` and `expires` apply to **key logins**: a password login has no key and is not narrowed by them.
|
|
348
|
+
|
|
253
349
|
### Gateway (TCP and DNS egress from the host)
|
|
254
350
|
|
|
255
351
|
`gateway: { allow: ['broker.lan:1883'], allowPrivate: ['10.0.0.0/8'], socks: '127.0.0.1:9050' }` makes the Node server
|
|
@@ -1106,6 +1202,40 @@ const server = createWshServer({
|
|
|
1106
1202
|
- Without `mcp`, `McpDiscover` answers an empty list and `McpCall` an
|
|
1107
1203
|
`{ success: false, error: 'mcp is not enabled on this server' }` result.
|
|
1108
1204
|
|
|
1205
|
+
### `wsh-mcp`: a stdio bridge for MCP clients (#127)
|
|
1206
|
+
|
|
1207
|
+
An MCP client (Claude Desktop, Cursor, an SDK `StdioClientTransport`, ...) launches a command and speaks MCP over its stdio. The package
|
|
1208
|
+
ships one, `wsh-mcp`, that connects to a wsh host, opens its `mcp` [rpc channel](#rpc-channels-object-mode) and passes the messages
|
|
1209
|
+
both ways, verbatim (ids, notifications, progress, cancellation). The host serves it with
|
|
1210
|
+
`createWshServer({ rpc: { mcp: mcpServerAdapter(server) } })` or, in a page, `createMemoryHost({ rpc: { mcp } })` (reach a memory host
|
|
1211
|
+
through whatever carries its WebSocket or a [pipe relay](#a-pipe-relay-johnhenrywshpipe-relay-118)); give each channel its own server with a factory
|
|
1212
|
+
(`mcpServerAdapter(() => makeServer())`) so a reconnect is served.
|
|
1213
|
+
|
|
1214
|
+
```
|
|
1215
|
+
npx -p @johnhenry/wsh wsh-mcp [options] [user@]<url> # or install the package and run `wsh-mcp`
|
|
1216
|
+
|
|
1217
|
+
-l, --user NAME login name (default: the user@ in the URL, $WSH_USER, $USER, the OS user)
|
|
1218
|
+
-i, --identity FILE Ed25519 private key (default ~/.wsh/keys/default.pem, what `wsh keygen` writes; a PKCS#8 PEM works too)
|
|
1219
|
+
--channel NAME the rpc channel to open (default mcp)
|
|
1220
|
+
--host-key KEY pin the host (hex fingerprint or ssh-ed25519 line); unpinned, it warns on stderr
|
|
1221
|
+
--no-reconnect, --reconnect-attempts N, --timeout MS
|
|
1222
|
+
```
|
|
1223
|
+
|
|
1224
|
+
An MCP client configuration:
|
|
1225
|
+
|
|
1226
|
+
```json
|
|
1227
|
+
{ "mcpServers": { "remote": { "command": "wsh-mcp", "args": ["--identity", "/home/me/.wsh/keys/default.pem", "--host-key", "<fingerprint>", "wss://host.example:4422"] } } }
|
|
1228
|
+
```
|
|
1229
|
+
|
|
1230
|
+
stdout carries MCP messages only (one JSON-RPC message per line); every diagnostic goes to stderr. Exit status: `0` the client closed
|
|
1231
|
+
its side, `1` the host was lost for good, `2` it could not start -- no connection, a refused login or host key, or **a host that offers
|
|
1232
|
+
no such channel** (the error lists the channels it does offer and how to serve one). After a dropped connection it reconnects (5
|
|
1233
|
+
attempts from 500 ms, doubling), re-sends the client's `initialize` to the new channel without telling the client, answers a request
|
|
1234
|
+
that was in flight with a JSON-RPC error (`-32603`, the client may retry) and delivers what the client sent meanwhile (at most 200
|
|
1235
|
+
messages). `--target` is not offered: rpc channels are not per target on any host (#121). The same bridge is a function,
|
|
1236
|
+
`runMcpStdioBridge()` from `@johnhenry/wsh/mcp-stdio`. **Rust: not built** -- the `wsh` CLI has no `wsh mcp`, because `wsh-client` has no
|
|
1237
|
+
rpc channel yet; `wsh-mcp` needs Node.
|
|
1238
|
+
|
|
1109
1239
|
### Host key (fingerprint / TOFU)
|
|
1110
1240
|
|
|
1111
1241
|
Give the server an identity and the stock client can pin it:
|
|
@@ -1573,7 +1703,7 @@ instead of dragging its own toolchain and CI job into an unrelated
|
|
|
1573
1703
|
browser-app repo. It was previously deleted from clawser by accident
|
|
1574
1704
|
(2026-03-14) and restored (2026-07-05) before this move.
|
|
1575
1705
|
|
|
1576
|
-
Four crates, workspace-versioned (currently `0.
|
|
1706
|
+
Four crates, workspace-versioned (currently `0.15.0`):
|
|
1577
1707
|
|
|
1578
1708
|
| Crate | Kind | Description |
|
|
1579
1709
|
|-------|------|--------------|
|
|
@@ -1723,6 +1853,7 @@ than left to be found.
|
|
|
1723
1853
|
| Install an authorized key | `WshClient.addAuthorizedKey()` | `wsh_client::WshClient::add_authorized_key()`, `wsh copy-id` | **Wire-unified** (wsh #59): `AuthorizedKeyAdd`/`AuthorizedKeyResult`, replacing a Rust-CLI-only shell command with a message every implementation can send |
|
|
1724
1854
|
| Host identity / TOFU | `WshKnownHosts` (localStorage-backed) | `KnownHosts`/`HostStatus` (`~/.wsh/known_hosts`-backed); the client sends `host-key-nonce`, verifies `host-key`/`host-key-sig`, pins only a proven key, and a first use needs `--accept-new-host-key` or a yes at a terminal (`--require-host-key` refuses a host with no proof); `wsh-server` has an opt-in host key (`[server] host_key`) | **Unified** (wsh #59, #145): both pin a PROVEN `ServerHello.host_fingerprint`. A Rust server with no `host_key` configured (the default, so released clients keep working) proves nothing |
|
|
1725
1855
|
| Typed RPC channels (`openRpc`, `rpc` sessions; `wsh-host`, `wsh-fs`, `mcp`) | `WshClient.openRpc()`, `RpcChannel` | Rust `wsh-server` (`rust-v0.4.0`+): `wsh-host`, and `wsh-fs` when `[rpc] fs_root` is set; no client yet in `wsh-client` | **No wire change**: `Open { kind: 'rpc', command: <protocol> }` plus `rpc*` `ServerHello` features, negotiated so it fails fast elsewhere; the Rust server serves it on WebSocket/QMux only |
|
|
1856
|
+
| MCP over stdio for MCP clients that launch a command (#127) | `wsh-mcp` (the package's `bin`) and `runMcpStdioBridge()` from `@johnhenry/wsh/mcp-stdio`: opens the host's `mcp` rpc channel, reconnects, a clear error when the host offers none | **not built**: no `wsh mcp`, because `wsh-client` has no rpc channel; the Rust `wsh-server` also serves no `mcp` rpc channel (it answers `McpDiscover`/`McpCall`, which `WshMcpBridge` uses) | **JS-only for now** -- no wire change (the channel is #85's) |
|
|
1726
1857
|
| Exec stdin + EOF, separate stderr | `exec({ stdin })`, `session.closeStdin()`, `session.onStderr` | `SessionOpts { stdio: Some("pipes") }`, `WshSession::read_stderr()` / `close_stdin()`; `wsh host command` uses them whenever its stdin is a pipe or a file and the host offers `exec-pipes` | **Wire-unified, negotiated** (#105): `Open.stdio = "pipes"` + `OpenOk.stderr_channel_id` + zero-length `SessionData` as EOF, offered by the `exec-pipes` `ServerHello` feature. `@johnhenry/wsh/server` needs none of it (stream-mode EOF); the Rust `wsh-server` (`rust-v0.5.0`+) runs such an exec on pipes, everything else on the PTY. Against a host without `exec-pipes` the CLI still forwards stdin, but cannot tell the command it ended |
|
|
1727
1858
|
| Signals and resize for a one-off command | `session.signal()`, `session.resize()` | `wsh host command` forwards SIGINT/SIGTERM/SIGHUP (the same signal twice disconnects); `wsh --tty host command` also forwards terminal resizes | **Wire-unified** (`Signal`, `Resize`). The Rust `wsh-server` delivers `Signal` (#145) to a pty session's foreground process group (what ^C reaches) and to an exec-on-pipes command's own process group, for `HUP INT QUIT TERM KILL USR1 USR2 WINCH CONT STOP TSTP ALRM` (with or without `SIG`); another name is ignored, and only the control attachment of the connection that owns the channel can send one. Not delivered on Windows |
|
|
1728
1859
|
| Dial target | a URL | `wsh [user@]host` (dials `https://` then `wss://` on `--port`), or a full URL: `wsh wss://host:8443/rendezvous/ab12 command`, `ws://127.0.0.1:PORT/` | **CLI-only convenience**: a URL is dialled exactly as given (no transport fallback; `--port` and `--transport` do not apply). Plain `ws://` is accepted only to a loopback host |
|
|
@@ -1745,6 +1876,8 @@ than left to be found.
|
|
|
1745
1876
|
| Refusal event with stable reason codes (`onRefused`, #163) | `onRefused({ reason, who, detail })` on `createMemoryHost` / `createWshServer` / `createReverseHost`; `REFUSAL_REASONS` from `@johnhenry/wsh/host` | none: `wsh-server` and `wsh reverse` log a refusal, they have no callback (an embedding process has none) | **JS-only** -- a host-side callback of the embedding API, no wire change |
|
|
1746
1877
|
| `AuthOk.ttl` enforced, `token` opaque (#125) | `connectionTtlMs`; `client.authTtl` | `wsh-server` sends `ttl: 0` (no lifetime promised; `session_ttl` is the lifetime of a *detached* session) and an HMAC token that nothing accepts back | **Wire-compatible**: both fields are still sent (released peers require them). **Changed in the Rust server after `rust-v0.6.0`**: it used to send `session_ttl` (86400), which nothing enforced. The Rust client ignores `ttl` |
|
|
1747
1878
|
| `clientEnv` allow-list (#126) | default `TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*` | `wsh-server`: the same default; `[server] client_env = true` (everything, the old behaviour), `false` (nothing) or a list of names / `PREFIX*` (replaces the default) | **Both hosts**; wire unchanged. **Breaking default in the Rust server**, see the CHANGELOG |
|
|
1879
|
+
| `authorized_keys` options (#122): `restrict`, `permit-*`, `no-pty`, `command=`, `max-sessions=` | `auth.authorizedKeys` lines with options on `createWshServer` / `createMemoryHost`; `parseAuthorizedKeyEntries()` | `wsh-server` reads `~/.wsh/authorized_keys` (then `~/.ssh/authorized_keys`) | **Same rules and the same vectors on both hosts** (`spec/key-options.vectors.json`, run by the JS suite and a Rust test); an option that is not understood keeps the key out, on both. See [Authorized-key options](#authorized-key-options-122) for the per-host column |
|
|
1880
|
+
| Per-key capabilities and expiry (#122): `capabilities="..."`, `expires="..."`; `authorize()` may return a set | every entry the host has: `Open` kinds, `FileOp` read vs write, gateway TCP/UDP/unix/endpoint open and listen, MCP discovery and calls, targets, rpc channels, relay; refusals through `onRefused` (`not-permitted`, `key-expired`) | the same, except **no endpoints and no targets** (`endpoint:` / `target:` parse and grant nothing; such requests are refused); refusals are logged, there is no callback; no `authorize` | **Same grammar, same vectors, same refusal codes on both hosts**; default-deny only for a key whose line has `capabilities`. Neither covers sessions already open, see [Security model](#security-model) |
|
|
1748
1881
|
| Session recording/replay | `SessionRecorder`/`SessionPlayer` (asciicast-v2-shaped JSON) | none | **JS-only** -- no current Rust consumer needs playback; the vocabulary is asciicast v2's, so a Rust port could share it |
|
|
1749
1882
|
| Self-signed cert pinning | `serverCertificateHashes` (WebTransport option) | N/A -- Rust dials a cert its own TLS stack already trusts, or `--generate-cert`'s self-signed cert out of band | **Deliberately not unified** -- this is a browser-specific WebTransport API shape, not a wire-protocol concept |
|
|
1750
1883
|
|
|
@@ -1801,7 +1934,7 @@ plus one `SHA256SUMS` file covering every archive in the release. These
|
|
|
1801
1934
|
names are a stable contract other repos (clawser) pin and download by --
|
|
1802
1935
|
do not change them without coordinating downstream.
|
|
1803
1936
|
|
|
1804
|
-
`wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.
|
|
1937
|
+
`wsh --version` and `wsh-server --version` print the workspace version the binary was built from (`wsh 0.15.0`), which is the
|
|
1805
1938
|
number in the `rust-vX.Y.Z` tag. Binaries of `rust-v0.9.0` to `rust-v0.10.0` printed a fixed `0.1.0`, so against one of those the
|
|
1806
1939
|
version cannot be read from the binary (look for a flag in `wsh --help` instead).
|
|
1807
1940
|
|
|
@@ -1858,6 +1991,29 @@ out explicitly below rather than left to be discovered.
|
|
|
1858
1991
|
isolation a target gives is your backends'. `requireTarget` does not cover the gateway, MCP or `Attach`; without it a request with no
|
|
1859
1992
|
target runs on the host's own backends, which any authenticated key can use, so a deployment that confines a key to one target must set
|
|
1860
1993
|
`requireTarget` (or leave the host with no backends of its own). The Rust `wsh-server` has no targets and refuses any request that names one.
|
|
1994
|
+
- **A key's `authorized_keys` options mean the same on both hosts, and a line that is not understood never grants anything (#122).**
|
|
1995
|
+
`restrict`, `permit-*`, `no-pty`, `command=` and `max-sessions=` are enforced at every entry the table in
|
|
1996
|
+
[Authorized-key options](#authorized-key-options-122) lists (`Open`, `FileOp`, the rpc channels, MCP, the relay entry
|
|
1997
|
+
points, installing a key), with the shared vectors run by both test suites. An option that is not understood -- or a value
|
|
1998
|
+
that is malformed, such as `max-sessions=0` -- keeps the key out altogether and is logged. They do NOT scope the gateway
|
|
1999
|
+
(TCP, DNS, unix, endpoints, reverse listeners) or the targets: a key that may not run commands can still use a gateway the host
|
|
2000
|
+
turned on, and `no-port-forwarding` is accepted and ignored. A key's permissions are read when the host starts (the Rust
|
|
2001
|
+
server) or when `createWshServer` is built (the Node host): editing the file does not change a running host. They limit what a
|
|
2002
|
+
key can ask for, not what a command it may run can do: `permit-exec` runs any command the client names (use `command=` to fix
|
|
2003
|
+
it), as the host's user.
|
|
2004
|
+
- **Per-key capabilities and expiry narrow what a key may ask for; they are not a sandbox (#122).** `capabilities="..."` (and what
|
|
2005
|
+
`authorize` returns) is default-deny at the entry points in the [capability table](#capabilities-and-expiry-122-step-two), on both
|
|
2006
|
+
hosts, with the same vectors. What they do NOT protect against: (1) **what a granted capability can reach.** `exec` runs any
|
|
2007
|
+
command as the host's user, `fs:write` writes anywhere the `fs` root allows, `gateway:tcp:*:*` is an open proxy -- a capability is
|
|
2008
|
+
as strong as the backend behind it; the gateway's own policy (`allow`, resolved-address checks, unix paths) and the `fs` root still
|
|
2009
|
+
apply on top, and the capability only narrows. (2) **Things already open.** `expires` is checked at login and at every request; it
|
|
2010
|
+
does not close a connection, a running command, a forwarded stream or a reverse listener that was open when the key expired
|
|
2011
|
+
(use `connectionTtlMs` for that), and an `Attach` / `Resume` / `Signal` / `Resize` of a session the key already owns, session
|
|
2012
|
+
sharing, recordings and `Detach` are not gated by capabilities. (3) **Host names are compared as the client wrote them**:
|
|
2013
|
+
`gateway:tcp:db.internal:5432` constrains the name a client sends, not where a granted name resolves (the gateway's address
|
|
2014
|
+
policy does that). (4) **Password logins** are not narrowed (no key). (5) **Clock:** `expires` trusts the host's clock. (6) A key
|
|
2015
|
+
file is read when the host starts (Rust) or is built (Node): editing it does not change a running host. (7) The Rust server has no
|
|
2016
|
+
endpoints or targets: `endpoint:` and `target:` are accepted in a key line (so one file serves both hosts) and grant nothing there.
|
|
1861
2017
|
- **Several operators per peer share one peer, and the relay decides who is who (#93).** Off unless both the relay
|
|
1862
2018
|
(`maxOperatorsPerPeer`, `[relay] max_operators_per_peer`) and the peer (`maxOperators`, `--max-operators`) are
|
|
1863
2019
|
set above 1. The relay stamps each message with its own record of the sender's authenticated key and removes
|
|
@@ -1888,6 +2044,13 @@ out explicitly below rather than left to be discovered.
|
|
|
1888
2044
|
|
|
1889
2045
|
**What is still yours:**
|
|
1890
2046
|
|
|
2047
|
+
- **`wsh-mcp` runs as a client with your key (#127).** It reads a private key file you point it at (no passphrase support: protect the
|
|
2048
|
+
file, `0600`), logs in as you and hands the MCP client everything the host's `mcp` channel serves; whatever the MCP client (or the
|
|
2049
|
+
model behind it) asks of those tools is done as you. It does not pin the host unless you pass `--host-key` (it warns once on stderr),
|
|
2050
|
+
so a first connection to an unpinned host trusts whoever answers. After a reconnect it re-sends the client's `initialize` to a new
|
|
2051
|
+
server-side session: server state from the old session (subscriptions, per-session data) is not carried over. It does not filter
|
|
2052
|
+
or inspect MCP messages; a tool's own authorization is the host's (`mcp.authorize`).
|
|
2053
|
+
|
|
1891
2054
|
- **What a reverse listener exposes.** Whoever can reach the bound port can talk to whatever the client behind it serves,
|
|
1892
2055
|
as the client, with no authentication of their own: wsh authenticates the operator that asks for the listener, not the
|
|
1893
2056
|
peers that connect to it. `bindAddr: '0.0.0.0'` (or an `allowBindAddrs` entry that does the same) puts that on every
|
package/bin/wsh-mcp.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// wsh-mcp (wsh #127): a stdio bridge so an MCP client can reach an MCP server behind a wsh host. See src/mcp-stdio.mjs and the README.
|
|
3
|
+
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { userInfo } from 'node:os';
|
|
7
|
+
import { runMcpStdioBridge, loadIdentity, defaultIdentityPath, McpBridgeError } from '../src/mcp-stdio.mjs';
|
|
8
|
+
|
|
9
|
+
const { version } = createRequire(import.meta.url)('../package.json');
|
|
10
|
+
|
|
11
|
+
const HELP = `wsh-mcp ${version} -- reach an MCP server behind a wsh host from an MCP client that launches a command
|
|
12
|
+
|
|
13
|
+
Usage: wsh-mcp [options] [user@]<url>
|
|
14
|
+
|
|
15
|
+
<url> ws://, wss:// or https:// URL of the wsh host (a host serving an rpc channel "mcp")
|
|
16
|
+
-l, --user NAME login name (default: the user@ part of the URL, else $WSH_USER, $USER, or the OS user)
|
|
17
|
+
-i, --identity FILE Ed25519 private key (default: ~/.wsh/keys/default.pem, the key \`wsh keygen\` makes)
|
|
18
|
+
--channel NAME the rpc channel to open (default: mcp)
|
|
19
|
+
--host-key KEY pin the host: a hex fingerprint, or an ssh-ed25519 line (default: not pinned, with a warning)
|
|
20
|
+
--no-reconnect exit when the connection is lost instead of reconnecting
|
|
21
|
+
--reconnect-attempts N attempts before giving up (default: 5, from 500 ms, doubling)
|
|
22
|
+
--timeout MS to log in and to open the channel (default: 15000)
|
|
23
|
+
-h, --help this text
|
|
24
|
+
-V, --version
|
|
25
|
+
|
|
26
|
+
stdout carries MCP messages only (one JSON-RPC message per line); everything else goes to stderr.
|
|
27
|
+
Exit status: 0 the client closed the connection, 1 the host was lost for good, 2 it could not start.
|
|
28
|
+
|
|
29
|
+
An MCP client configuration (Claude Desktop, Cursor, ...):
|
|
30
|
+
|
|
31
|
+
{ "mcpServers": { "remote": { "command": "wsh-mcp", "args": ["--identity", "/home/me/.wsh/keys/default.pem", "wss://host.example:4422"] } } }
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
function usage(message) {
|
|
35
|
+
process.stderr.write(`wsh-mcp: ${message}\nTry \`wsh-mcp --help\`.\n`);
|
|
36
|
+
process.exit(2);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = parseArgs({
|
|
42
|
+
allowPositionals: true,
|
|
43
|
+
options: {
|
|
44
|
+
user: { type: 'string', short: 'l' },
|
|
45
|
+
identity: { type: 'string', short: 'i' },
|
|
46
|
+
channel: { type: 'string' },
|
|
47
|
+
'host-key': { type: 'string' },
|
|
48
|
+
'no-reconnect': { type: 'boolean' },
|
|
49
|
+
'reconnect-attempts': { type: 'string' },
|
|
50
|
+
timeout: { type: 'string' },
|
|
51
|
+
target: { type: 'string' },
|
|
52
|
+
help: { type: 'boolean', short: 'h' },
|
|
53
|
+
version: { type: 'boolean', short: 'V' },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
} catch (e) { usage(e.message); }
|
|
57
|
+
const { values, positionals } = parsed;
|
|
58
|
+
if (values.help) { process.stdout.write(HELP); process.exit(0); }
|
|
59
|
+
if (values.version) { process.stdout.write(`${version}\n`); process.exit(0); }
|
|
60
|
+
if (values.target !== undefined) usage('--target: rpc channels are not per target (#121), so there is nothing to select; the host serves one "mcp" channel');
|
|
61
|
+
if (positionals.length !== 1) usage('exactly one host URL is required');
|
|
62
|
+
|
|
63
|
+
let url = positionals[0];
|
|
64
|
+
let userFromUrl;
|
|
65
|
+
const at = url.indexOf('@');
|
|
66
|
+
if (at > 0 && !url.slice(0, at).includes('/') && !url.slice(0, at).includes(':')) { userFromUrl = url.slice(0, at); url = url.slice(at + 1); }
|
|
67
|
+
if (!/^(wss?|https?):\/\//.test(url)) usage(`${url}: expected a ws://, wss:// or https:// URL`);
|
|
68
|
+
const number = (name, v, min) => {
|
|
69
|
+
if (v === undefined) return undefined;
|
|
70
|
+
const n = Number(v);
|
|
71
|
+
if (!Number.isInteger(n) || n < min) usage(`--${name} must be a whole number of at least ${min}`);
|
|
72
|
+
return n;
|
|
73
|
+
};
|
|
74
|
+
const attempts = number('reconnect-attempts', values['reconnect-attempts'], 0);
|
|
75
|
+
const timeoutMs = number('timeout', values.timeout, 1);
|
|
76
|
+
const username = values.user ?? userFromUrl ?? process.env.WSH_USER ?? process.env.USER ?? userInfo().username;
|
|
77
|
+
|
|
78
|
+
const handle = { close: null };
|
|
79
|
+
let exitCode;
|
|
80
|
+
try {
|
|
81
|
+
const signer = await loadIdentity(values.identity ?? defaultIdentityPath());
|
|
82
|
+
for (const sig of ['SIGINT', 'SIGTERM']) process.once(sig, () => { void handle.close?.(); });
|
|
83
|
+
exitCode = await runMcpStdioBridge({
|
|
84
|
+
url, username, signer, channel: values.channel, expectHostKey: values['host-key'], timeoutMs,
|
|
85
|
+
reconnect: values['no-reconnect'] ? false : (attempts === undefined ? undefined : { attempts }),
|
|
86
|
+
signalHandle: handle,
|
|
87
|
+
});
|
|
88
|
+
} catch (e) {
|
|
89
|
+
process.stderr.write(`wsh-mcp: ${e?.message ?? e}\n`);
|
|
90
|
+
exitCode = e instanceof McpBridgeError ? e.exitCode : 2;
|
|
91
|
+
}
|
|
92
|
+
process.exit(exitCode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/wsh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "Web Shell \u2014 browser-native remote command execution over WebTransport and WebSocket with Ed25519 authentication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -28,12 +28,20 @@
|
|
|
28
28
|
"./reverse": {
|
|
29
29
|
"types": "./src/reverse-host.d.ts",
|
|
30
30
|
"import": "./src/reverse-host.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./mcp-stdio": {
|
|
33
|
+
"types": "./src/mcp-stdio.d.ts",
|
|
34
|
+
"import": "./src/mcp-stdio.mjs"
|
|
31
35
|
}
|
|
32
36
|
},
|
|
37
|
+
"bin": {
|
|
38
|
+
"wsh-mcp": "./bin/wsh-mcp.mjs"
|
|
39
|
+
},
|
|
33
40
|
"sideEffects": false,
|
|
34
41
|
"types": "./src/index.d.ts",
|
|
35
42
|
"files": [
|
|
36
43
|
"src",
|
|
44
|
+
"bin",
|
|
37
45
|
"LICENSE",
|
|
38
46
|
"README.md"
|
|
39
47
|
],
|
package/src/host.d.ts
CHANGED
|
@@ -261,10 +261,12 @@ export type WshOnShare = (name: string, fs: WshShareFs, who: { username: string
|
|
|
261
261
|
export const REFUSAL_REASONS: readonly WshRefusalReason[];
|
|
262
262
|
export type WshRefusalReason =
|
|
263
263
|
| 'not-sealed' | 'unauthorized' | 'binding-required' | 'bad-signature' | 'method-disabled' | 'rate-limited' | 'bad-request'
|
|
264
|
-
| 'seal-failed' | 'busy' | 'proof-required' | 'proof-failed';
|
|
264
|
+
| 'seal-failed' | 'busy' | 'proof-required' | 'proof-failed' | 'key-expired' | 'not-permitted';
|
|
265
265
|
/**
|
|
266
266
|
* Called once per connection a host turned away (#163): `reason` is a stable code, `who` what is known of the peer (a
|
|
267
267
|
* refusal before the login names no one), `detail` human text that is not stable. Not for parsing `onLog`.
|
|
268
268
|
* Reverse hosts also use `busy`, `proof-required`, `proof-failed`; a sealed session that fails mid-way reports `seal-failed`.
|
|
269
|
+
* `key-expired` (a key past its `expires`, at login or later) and `not-permitted` (a request the key's options or capabilities do not
|
|
270
|
+
* allow; `detail` names the missing capability) are not per connection: `not-permitted` can come any number of times on one (#122).
|
|
269
271
|
*/
|
|
270
272
|
export type WshOnRefused = (refusal: { reason: WshRefusalReason; who: { username?: string; fingerprint?: string; address?: string }; detail: string }) => void;
|