@johnhenry/wsh 0.42.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 +243 -10
- package/bin/wsh-mcp.mjs +92 -0
- package/package.json +9 -1
- package/src/client.mjs +44 -10
- package/src/features.mjs +7 -0
- package/src/gateway-client.mjs +7 -2
- package/src/host-backends.mjs +68 -3
- package/src/host.d.ts +35 -6
- package/src/index.d.ts +48 -1
- package/src/index.mjs +2 -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 +9 -1
- package/src/memory-host.mjs +11 -4
- package/src/messages.gen.mjs +23 -8
- package/src/refusal.mjs +7 -1
- package/src/reverse-host.mjs +1 -0
- package/src/server/auth.mjs +67 -29
- package/src/server/backends.mjs +11 -6
- package/src/server/connection.mjs +219 -33
- package/src/server/gateway-core.mjs +14 -2
- package/src/server/index.d.ts +64 -4
- package/src/server/index.mjs +19 -7
package/src/server/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* refused.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { buildAuthorizer, parseAuthorizedKeys, authMethods, FailureLimiter } from './auth.mjs';
|
|
11
|
+
import { buildAuthorizer, parseAuthorizedKeys, parseAuthorizedKeyEntries, authMethods, FailureLimiter } from './auth.mjs';
|
|
12
12
|
import { loadHostKey } from './host-key.mjs';
|
|
13
13
|
import { buildBackends } from './backends.mjs';
|
|
14
14
|
import { SessionRegistry } from './sessions.mjs';
|
|
@@ -22,7 +22,7 @@ import { createRpcHost, mcpServerAdapter } from './rpc.mjs';
|
|
|
22
22
|
import { bindSocket } from './socket.mjs';
|
|
23
23
|
import { TLS_EXPORTER_LABEL, TLS_EXPORTER_LENGTH, CHANNEL_BINDING_KINDS } from '../channel-binding.mjs';
|
|
24
24
|
|
|
25
|
-
export { parseAuthorizedKeys, STREAM_ANNOUNCE, mcpServerAdapter };
|
|
25
|
+
export { parseAuthorizedKeys, parseAuthorizedKeyEntries, STREAM_ANNOUNCE, mcpServerAdapter };
|
|
26
26
|
export { createReverseHost } from './reverse-host.mjs';
|
|
27
27
|
export { generateSelfSignedCertificate } from './self-signed.mjs';
|
|
28
28
|
|
|
@@ -85,6 +85,15 @@ function tlsChannelBinding(socket) {
|
|
|
85
85
|
* Answer the gateway opcodes (OpenTcp, ResolveDns, GatewayData/Close): the client opens TCP connections and resolves
|
|
86
86
|
* names from this host. Default deny: a destination must match `allow` (`"*"`, `"host"`, `"host:port"`). `socks` dials
|
|
87
87
|
* through a SOCKS5 proxy (Tor) with the name unresolved. UDP (`udp`: bounds, WebTransport datagrams) and TCP reverse tunnels (`reverse`, off unless given) are served. Off unless given. See `gateway.mjs`.
|
|
88
|
+
* @param {Record<string, { description?: string, authorize?: Function, exec?: true | object | Function, pty?: object, fs?: object, endpoints?: object }>} [options.targets]
|
|
89
|
+
* Execution targets (#121): the host fronts several (containers, VMs, workers, sandboxes), each with its own `exec`, `pty`,
|
|
90
|
+
* `fs` and `endpoints` (the same forms as the host's own) and an `authorize(who, { target, kind })` (`kind`: `exec`, `pty`,
|
|
91
|
+
* `file`, `endpoint`, `list`) deciding who may use it; a client names one in `Open`, `FileOp` or `OpenEndpoint` and lists
|
|
92
|
+
* what it may use with `ListTargets`. Off unless given (the host then advertises no `targets` and refuses a request that
|
|
93
|
+
* names one). A refused target and one that does not exist look the same to the client.
|
|
94
|
+
* @param {boolean} [options.requireTarget=false] - With `targets`: an `Open`, `FileOp` or `OpenEndpoint` that names no target is
|
|
95
|
+
* refused, so nothing runs on the host itself (`kind: 'rpc'` channels, which are not per target, are refused too). Does NOT
|
|
96
|
+
* cover the gateway (`OpenTcp`, `OpenUnix`, ...), MCP, or `Attach` to a session already open.
|
|
88
97
|
* @param {number} [options.bindTimeoutMs=3000]
|
|
89
98
|
* @param {number} [options.connectionTtlMs=0] - End every authenticated connection this long after login (0 = never).
|
|
90
99
|
* Advertised as `AuthOk.ttl` in whole seconds, rounded up; the client reads it as `client.authTtl`.
|
|
@@ -106,7 +115,7 @@ function tlsChannelBinding(socket) {
|
|
|
106
115
|
*/
|
|
107
116
|
export function createWshServer({
|
|
108
117
|
host = '127.0.0.1', port = 0, tls, auth, exec, pty, fs, hostKey, mcp, rpc, rpcMaxMessageBytes, rpcMaxInflight, sessions, sessionSecret, relay, extensions, gateway, webTransport, bindTimeoutMs = 3000, connectionTtlMs = 0, requireChannelBinding = false, sealSession = false, onLog = () => {},
|
|
109
|
-
onShare, onRefused,
|
|
118
|
+
onShare, onRefused, targets, requireTarget,
|
|
110
119
|
} = {}) {
|
|
111
120
|
validateOnShare(onShare, 'createWshServer');
|
|
112
121
|
validateOnRefused(onRefused, 'createWshServer');
|
|
@@ -120,7 +129,7 @@ export function createWshServer({
|
|
|
120
129
|
let httpsServer = null;
|
|
121
130
|
let bound = null;
|
|
122
131
|
|
|
123
|
-
const { execRunner, execOptions, pty: ptyConfig, files, mcp: mcpHost } = buildBackends({ exec, pty, fs, mcp });
|
|
132
|
+
const { execRunner, execOptions, pty: ptyConfig, files, mcp: mcpHost, targets: targetTable, requireTarget: mustHaveTarget } = buildBackends({ exec, pty, fs, mcp, targets, requireTarget });
|
|
124
133
|
const methods = authMethods(auth);
|
|
125
134
|
const rl = auth?.rateLimit ?? {};
|
|
126
135
|
const rateLimit = {
|
|
@@ -136,7 +145,10 @@ export function createWshServer({
|
|
|
136
145
|
let registry = null;
|
|
137
146
|
let hub = null;
|
|
138
147
|
let wt = null;
|
|
139
|
-
|
|
148
|
+
let gatewayCfg = gateway === undefined ? null : normalizeGateway(gateway);
|
|
149
|
+
// A target's own named endpoints (#121) are served by the gateway session even when the host has no gateway of its own:
|
|
150
|
+
// an endpoints-only one (no TCP, DNS or unix sockets), which advertises `gateway-endpoints`.
|
|
151
|
+
if (targetTable && [...targetTable.values()].some((t) => t.endpoints)) gatewayCfg = { ...(gatewayCfg ?? normalizeGateway({ tcp: false })), targetEndpoints: true };
|
|
140
152
|
const sessionOptions = sessions ? (sessions === true ? {} : sessions) : null;
|
|
141
153
|
|
|
142
154
|
/** Sockets handed to `accept()` that are still open. */
|
|
@@ -146,7 +158,7 @@ export function createWshServer({
|
|
|
146
158
|
|
|
147
159
|
function start() {
|
|
148
160
|
ready ??= (async () => {
|
|
149
|
-
const authorize = await buildAuthorizer(auth);
|
|
161
|
+
const authorize = await buildAuthorizer(auth, { log: onLog });
|
|
150
162
|
host_ = hostKey ? await loadHostKey(hostKey) : null;
|
|
151
163
|
if (sessionOptions) {
|
|
152
164
|
const secret = sessionOptions.sessionSecret ?? sessionSecret;
|
|
@@ -163,7 +175,7 @@ export function createWshServer({
|
|
|
163
175
|
return createConnectionFactory({
|
|
164
176
|
authorize, execRunner, execOptions, pty: ptyConfig, files, bindTimeoutMs, connectionTtlMs, requireChannelBinding, sealSession, log: onLog,
|
|
165
177
|
methods, hostKey: host_, rateLimit, extensions, mcp: mcpHost, rpc: rpcHost, gateway: gatewayCfg, createGatewaySession, sessions: registry, relay: hub,
|
|
166
|
-
onShare, onRefused,
|
|
178
|
+
onShare, onRefused, targets: targetTable, requireTarget: mustHaveTarget,
|
|
167
179
|
});
|
|
168
180
|
})();
|
|
169
181
|
ready.catch(() => { ready = null; });
|