@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
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
MSG, serverHello, challenge, authOk, authFail, openOk, openFail, sessionData,
|
|
20
20
|
exit as exitMsg, close as closeMsg, encryptedFrame as encryptedFrameMsg, pong, fileResult, fileChunk, mcpTools, mcpResult,
|
|
21
21
|
presence as presenceMsg, error as errorMsg, sessionList, detachOk, detachFail, reversePeers, reverseReject,
|
|
22
|
-
targetList as targetListMsg,
|
|
22
|
+
targetList as targetListMsg, gatewayFail, listenFail,
|
|
23
23
|
} from '../messages.gen.mjs';
|
|
24
24
|
import {
|
|
25
25
|
generateNonce, verifyChallenge, fingerprint, importPublicKeyRaw,
|
|
@@ -31,7 +31,7 @@ import { RpcChannel, RPC_FEATURE, RPC_MAX_MESSAGE_PREFIX, rpcProtocolFeature } f
|
|
|
31
31
|
import { sealFrame, openFrame, ROLE_TAGS } from '../e2e-frame.mjs';
|
|
32
32
|
import { E2EResponder, E2E_FEATURE, E2E_SIGN_FEATURE } from '../e2e-exchange.mjs';
|
|
33
33
|
import { MULTI_OPERATOR_FEATURE } from './relay.mjs';
|
|
34
|
-
import { gatewayFeatures } from './gateway-core.mjs';
|
|
34
|
+
import { gatewayFeatures, GATEWAY_FAIL } from './gateway-core.mjs';
|
|
35
35
|
import { GATEWAY_DATAGRAM_FEATURE } from '../gateway-datagram.mjs';
|
|
36
36
|
import { OPERATOR_PROOF_FEATURE } from '../operator-proof.mjs';
|
|
37
37
|
import { clientEnvFilter } from './client-env.mjs';
|
|
@@ -39,6 +39,7 @@ import { acceptableBindings, bindingFeatures } from '../channel-binding.mjs';
|
|
|
39
39
|
import { SealedBridge } from '../bridge-seal.mjs';
|
|
40
40
|
import { refusalNotifier, validateOnRefused } from '../refusal.mjs';
|
|
41
41
|
import { HOST_KEY_PREFIX, HOST_KEY_SIG_PREFIX, findClientNonce, hostKeyProofMessage, toHex } from '../host-key.mjs';
|
|
42
|
+
import { checkKeyRequest } from '../key-options.mjs';
|
|
42
43
|
import { SHARES_FEATURE, createShareSession } from '../shares.mjs';
|
|
43
44
|
|
|
44
45
|
export const STREAM_ANNOUNCE = 'stream-announce';
|
|
@@ -146,7 +147,9 @@ export function createConnectionFactory(cfg) {
|
|
|
146
147
|
const ownBackends = { execRunner: cfg.execRunner, execOptions: cfg.execOptions, execEnv, pty: cfg.pty, ptyEnv, files: cfg.files, ownHost: true };
|
|
147
148
|
/** One answer for a target that does not exist and for one the caller may not use: the reply does not say which targets exist. */
|
|
148
149
|
const NO_SUCH_TARGET = 'no such target';
|
|
149
|
-
|
|
150
|
+
/** Every attached connection, for counting what a key holds open (`max-sessions`, #122). */
|
|
151
|
+
const liveConnections = new Set();
|
|
152
|
+
const targetCapabilities = (spec) =>[...(spec.execRunner ? ['exec'] : []), ...(spec.pty ? ['pty'] : []), ...(spec.files ? ['file'] : []), ...(spec.endpoints ? ['endpoint'] : [])];
|
|
150
153
|
|
|
151
154
|
/**
|
|
152
155
|
* Attach one connection. Two shapes:
|
|
@@ -163,9 +166,70 @@ export function createConnectionFactory(cfg) {
|
|
|
163
166
|
const state = {
|
|
164
167
|
sessionId: randomUUID(), nonce: null, username: authenticated?.username ?? null, authed: !!authenticated,
|
|
165
168
|
closed: false, nextChannel: 0, fingerprint: authenticated?.fingerprint ?? null,
|
|
169
|
+
/** What `authorize()` granted, when it returned a capability set instead of `true` (#122). */
|
|
170
|
+
grant: null,
|
|
166
171
|
};
|
|
167
172
|
/** @type {Map<number, any>} */
|
|
168
173
|
const channels = new Map();
|
|
174
|
+
const live = { channels, fingerprint: () => state.fingerprint };
|
|
175
|
+
liveConnections.add(live);
|
|
176
|
+
|
|
177
|
+
// ── What the key's authorized_keys options allow (#122) ──────────
|
|
178
|
+
// Looked up per request from the key this connection authenticated as (a bridged peer included); `null` = no options.
|
|
179
|
+
const keyPermissions = () => (state.fingerprint ? cfg.authorize.permissionsFor?.(state.fingerprint) ?? null : null);
|
|
180
|
+
/** pty/exec sessions this key holds open on this host: live unhosted channels of every connection, and hosted sessions. */
|
|
181
|
+
function activeSessionsFor(fingerprint) {
|
|
182
|
+
let n = 0;
|
|
183
|
+
for (const c of liveConnections) {
|
|
184
|
+
if (c.fingerprint() !== fingerprint) continue;
|
|
185
|
+
for (const ch of c.channels.values()) if (ch.keyed) n++;
|
|
186
|
+
}
|
|
187
|
+
if (cfg.sessions) n += cfg.sessions.listFor(fingerprint).filter((s) => s.state !== 'exited').length;
|
|
188
|
+
return n;
|
|
189
|
+
}
|
|
190
|
+
/** What this connection may do: its key's options, and what `authorize()` granted (#122, step two); each narrows the other. */
|
|
191
|
+
const permissionSets = () => [keyPermissions(), state.grant].filter(Boolean);
|
|
192
|
+
/** First refusal of `req` by any of the sets, or null; `silent` skips the log and `onRefused` (discovery filters). */
|
|
193
|
+
function refusalOf(req, silent) {
|
|
194
|
+
for (const perms of permissionSets()) {
|
|
195
|
+
const counts = req.kind === 'open' && (req.channel === 'pty' || req.channel === 'exec') && perms.maxSessions !== null;
|
|
196
|
+
const refusal = checkKeyRequest(perms, req, { activeSessions: counts ? activeSessionsFor(state.fingerprint) : 0 });
|
|
197
|
+
if (!refusal) continue;
|
|
198
|
+
if (!silent) {
|
|
199
|
+
const what = `${req.kind}${req.channel ? ` ${req.channel}` : ''}${req.protocol ? ` ${req.protocol}` : ''}`;
|
|
200
|
+
log(`key permissions refused ${what} for ${state.username ?? '?'} (${refusal.code}${refusal.capability ? `: ${refusal.capability}` : ''})`);
|
|
201
|
+
// #122: the embedder hears of it with a stable reason (`not-permitted`; `key-expired` for a key past its `expires`).
|
|
202
|
+
notifyRefused(refusal.code === 'key-expired' ? 'key-expired' : 'not-permitted', { username: state.username, fingerprint: state.fingerprint, address: remote.address }, `${refusal.code}: ${refusal.reason} (${what})`);
|
|
203
|
+
}
|
|
204
|
+
return refusal;
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* `null` when the key's options and capabilities allow this request, else `{ code, reason, capability? }` (logged, and
|
|
210
|
+
* reported through `onRefused`). Requests are described in `checkKeyRequest`.
|
|
211
|
+
* @param {object} req
|
|
212
|
+
*/
|
|
213
|
+
const keyRefusal = (req) => refusalOf(req, false);
|
|
214
|
+
/** Whether this request would be allowed, without saying anything about it (what a discovery answer lists). */
|
|
215
|
+
const keyAllows = (req) => refusalOf(req, true) === null;
|
|
216
|
+
/** The reply that refuses a gateway message the key's capabilities do not cover (`GatewayFail` / `ListenFail`), or null. */
|
|
217
|
+
function gatewayRefusal(m) {
|
|
218
|
+
let req; let listener = false;
|
|
219
|
+
switch (m.type) {
|
|
220
|
+
case MSG.OPEN_TCP: req = { kind: 'tcp', host: m.host, port: m.port }; break;
|
|
221
|
+
case MSG.OPEN_UDP: req = { kind: 'udp', host: m.host, port: m.port }; break;
|
|
222
|
+
case MSG.RESOLVE_DNS: req = { kind: 'dns', name: m.name }; break;
|
|
223
|
+
case MSG.OPEN_UNIX: req = { kind: 'unix', path: m.path }; break;
|
|
224
|
+
case MSG.OPEN_ENDPOINT: req = { kind: 'endpoint', name: m.name, target: m.target ?? undefined }; break;
|
|
225
|
+
case MSG.LISTEN_REQUEST: req = { kind: 'listen-tcp', port: m.port }; listener = true; break;
|
|
226
|
+
case MSG.LISTEN_UNIX: req = { kind: 'listen-unix', path: m.path }; listener = true; break;
|
|
227
|
+
default: return null;
|
|
228
|
+
}
|
|
229
|
+
const refusal = keyRefusal(req);
|
|
230
|
+
if (!refusal) return null;
|
|
231
|
+
return listener ? listenFail({ listenerId: m.listener_id, reason: refusal.reason }) : gatewayFail({ gatewayId: m.gateway_id, code: GATEWAY_FAIL.POLICY_DENIED, message: refusal.reason });
|
|
232
|
+
}
|
|
169
233
|
/** FileOp `write`/`rename`s awaiting their FileChunk frames, by client-chosen channel id. */
|
|
170
234
|
const fileWrites = new Map();
|
|
171
235
|
/** AbortControllers of in-flight MCP calls: aborted on disconnect, counted for the cap. */
|
|
@@ -265,6 +329,7 @@ export function createConnectionFactory(cfg) {
|
|
|
265
329
|
function shutdown(why) {
|
|
266
330
|
if (state.closed) return;
|
|
267
331
|
state.closed = true;
|
|
332
|
+
liveConnections.delete(live);
|
|
268
333
|
clearTimeout(ttlTimer);
|
|
269
334
|
// A hosted session survives its connection (it is detached, then expires or is resumed);
|
|
270
335
|
// everything else dies with it.
|
|
@@ -327,7 +392,12 @@ export function createConnectionFactory(cfg) {
|
|
|
327
392
|
m = inner;
|
|
328
393
|
}
|
|
329
394
|
if (await handleRelay(m)) return;
|
|
330
|
-
if (gateway
|
|
395
|
+
if (gateway) {
|
|
396
|
+
// What the key's capabilities allow of the gateway (#122), before the gateway's own policy is asked.
|
|
397
|
+
const refusal = gatewayRefusal(m);
|
|
398
|
+
if (refusal) return send(refusal);
|
|
399
|
+
if (await gateway.handle(m)) return;
|
|
400
|
+
}
|
|
331
401
|
if (shares && shares.handle(m)) return;
|
|
332
402
|
switch (m.type) {
|
|
333
403
|
case MSG.PING: return send(pong({ id: m.id }));
|
|
@@ -509,6 +579,13 @@ export function createConnectionFactory(cfg) {
|
|
|
509
579
|
allowed = await cfg.authorize({ username: state.username, fingerprint: fp, publicKey: m.public_key });
|
|
510
580
|
} catch (e) { log(`authorize threw: ${e.message}`); }
|
|
511
581
|
if (!allowed) return refuse('key not authorized', 'unauthorized', claimed);
|
|
582
|
+
// `authorize` may answer with a capability set (`{ permissions }` from `buildAuthorizer`): it narrows what the key's own options allow.
|
|
583
|
+
const grant = typeof allowed === 'object' ? allowed.permissions ?? null : null;
|
|
584
|
+
// A key past its `expires` does not log in (#122).
|
|
585
|
+
for (const perms of [cfg.authorize.permissionsFor?.(fp) ?? null, grant]) {
|
|
586
|
+
if (perms && checkKeyRequest(perms, { kind: 'login' })) return refuse('key has expired', 'key-expired', claimed);
|
|
587
|
+
}
|
|
588
|
+
state.grant = grant;
|
|
512
589
|
state.authed = true;
|
|
513
590
|
state.fingerprint = fp;
|
|
514
591
|
state.publicKey = m.public_key;
|
|
@@ -616,6 +693,15 @@ export function createConnectionFactory(cfg) {
|
|
|
616
693
|
await send(errorMsg({ code: 2, message: 'relay operations need a key login' }));
|
|
617
694
|
return true;
|
|
618
695
|
}
|
|
696
|
+
// The entry points to the relay (#122): a key without `permit-relay` cannot register, list or connect.
|
|
697
|
+
if (m.type === MSG.REVERSE_REGISTER || m.type === MSG.REVERSE_LIST || m.type === MSG.REVERSE_CONNECT) {
|
|
698
|
+
const refusal = keyRefusal({ kind: 'relay' });
|
|
699
|
+
if (refusal) {
|
|
700
|
+
if (m.type === MSG.REVERSE_CONNECT) await send(reverseReject({ targetFingerprint: String(m.target_fingerprint ?? ''), username: '', reason: refusal.reason }));
|
|
701
|
+
else await send(errorMsg({ code: 2, message: refusal.reason }));
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
619
705
|
const h = hubHandle();
|
|
620
706
|
switch (m.type) {
|
|
621
707
|
case MSG.REVERSE_REGISTER: {
|
|
@@ -641,8 +727,11 @@ export function createConnectionFactory(cfg) {
|
|
|
641
727
|
|
|
642
728
|
async function handleMcpDiscover() {
|
|
643
729
|
let tools = [];
|
|
644
|
-
|
|
730
|
+
// A key without MCP (#122) sees no tools, as it would on a host that has none.
|
|
731
|
+
if (cfg.mcp && keyAllows({ kind: 'mcp' })) {
|
|
645
732
|
try { tools = await cfg.mcp.list(state.username, principal()); } catch (e) { log(`mcp discover failed: ${e.message}`); }
|
|
733
|
+
// A key with `mcp:<tool>` capabilities is told only of those tools.
|
|
734
|
+
tools = tools.filter((t) => keyAllows({ kind: 'mcp-tool', tool: t.name }));
|
|
646
735
|
}
|
|
647
736
|
return send(mcpTools({ tools }));
|
|
648
737
|
}
|
|
@@ -657,6 +746,7 @@ export function createConnectionFactory(cfg) {
|
|
|
657
746
|
};
|
|
658
747
|
const fail = (error) => reply({ success: false, error });
|
|
659
748
|
if (!cfg.mcp) { fail('mcp is not enabled on this server'); return; }
|
|
749
|
+
{ const refusal = keyRefusal({ kind: 'mcp-call', tool: typeof m.tool === 'string' ? m.tool : '' }); if (refusal) { fail(refusal.reason); return; } }
|
|
660
750
|
if (mcpCalls.size >= cfg.mcp.maxConcurrent) { fail('too many concurrent MCP calls'); return; }
|
|
661
751
|
|
|
662
752
|
const abort = new AbortController();
|
|
@@ -722,6 +812,8 @@ export function createConnectionFactory(cfg) {
|
|
|
722
812
|
if (!targetTable) return send(errorMsg({ code: 3, message: 'this host has no targets' }));
|
|
723
813
|
const out = [];
|
|
724
814
|
for (const [name, spec] of targetTable) {
|
|
815
|
+
// A key with capabilities is told only of the targets it holds (`target:NAME`).
|
|
816
|
+
if (!keyAllows({ kind: 'target', name })) continue;
|
|
725
817
|
const r = await resolveTarget(name, 'list');
|
|
726
818
|
if (r.refuse) continue;
|
|
727
819
|
out.push({ name, ...(spec.description !== undefined ? { description: spec.description } : {}), capabilities: targetCapabilities(spec) });
|
|
@@ -734,8 +826,16 @@ export function createConnectionFactory(cfg) {
|
|
|
734
826
|
const target = m.target ?? undefined;
|
|
735
827
|
switch (m.kind) {
|
|
736
828
|
case 'exec': case 'pty': case 'file': {
|
|
829
|
+
// The key's options and capabilities (#122): asked before the target is looked up (a key without `target:NAME` learns
|
|
830
|
+
// nothing about whether it exists), and again once it is, because no await may separate the `max-sessions` check from
|
|
831
|
+
// the channel being registered (two opens must not both pass when one slot is left).
|
|
832
|
+
const req = { kind: 'open', channel: m.kind, target, direction: m.kind === 'file' ? (String(m.command ?? '').startsWith('download:') ? 'download' : 'upload') : undefined };
|
|
833
|
+
const early = keyRefusal(req);
|
|
834
|
+
if (early) return send(openFail({ reason: early.reason }));
|
|
737
835
|
const r = await resolveTarget(target, m.kind);
|
|
738
836
|
if (r.refuse) return send(openFail({ reason: r.refuse }));
|
|
837
|
+
const refusal = keyAllows(req) ? null : keyRefusal(req);
|
|
838
|
+
if (refusal) return send(openFail({ reason: refusal.reason }));
|
|
739
839
|
if (m.kind === 'exec') return openExec(m, r.b, target);
|
|
740
840
|
return m.kind === 'pty' ? openPty(m, r.b, target) : openFile(m, r.b);
|
|
741
841
|
}
|
|
@@ -743,6 +843,10 @@ export function createConnectionFactory(cfg) {
|
|
|
743
843
|
// rpc channels (`wsh-fs`, `wsh-host`, `mcp`) are the host's own, not per target.
|
|
744
844
|
if (target !== undefined) return send(openFail({ reason: 'rpc channels do not take a target' }));
|
|
745
845
|
if (requireTarget) return send(openFail({ reason: 'a target is required' }));
|
|
846
|
+
{
|
|
847
|
+
const refusal = keyRefusal({ kind: 'open', channel: 'rpc', protocol: typeof m.command === 'string' ? m.command : '' });
|
|
848
|
+
if (refusal) return send(openFail({ reason: refusal.reason }));
|
|
849
|
+
}
|
|
746
850
|
return openRpc(m);
|
|
747
851
|
default: return send(openFail({ reason: `kind "${m.kind}" is not supported by this server` }));
|
|
748
852
|
}
|
|
@@ -868,7 +972,8 @@ export function createConnectionFactory(cfg) {
|
|
|
868
972
|
|
|
869
973
|
async function openExec(m, b, target) {
|
|
870
974
|
if (!b.execRunner) return send(openFail({ reason: `exec is not enabled ${b.ownHost ? 'on this server' : 'for this target'}` }));
|
|
871
|
-
|
|
975
|
+
// A key tied to one command (`command="..."`, #122) runs that, whatever the client asked for.
|
|
976
|
+
const command = keyPermissions()?.forcedCommand ?? String(m.command ?? '').trim();
|
|
872
977
|
if (!command) return send(openFail({ reason: 'command is required for kind "exec"' }));
|
|
873
978
|
|
|
874
979
|
const channelId = ++state.nextChannel;
|
|
@@ -889,6 +994,7 @@ export function createConnectionFactory(cfg) {
|
|
|
889
994
|
if (/^(INT|TERM|KILL|HUP)$/.test(n) && signalCbs.length === 0) abort.abort();
|
|
890
995
|
};
|
|
891
996
|
const ch = {
|
|
997
|
+
keyed: !hosted, // counts toward the key's `max-sessions` (a hosted session is counted by the registry)
|
|
892
998
|
kill: () => abort.abort(),
|
|
893
999
|
signal: signalTo,
|
|
894
1000
|
bind(s) {
|
|
@@ -1079,6 +1185,7 @@ export function createConnectionFactory(cfg) {
|
|
|
1079
1185
|
return send(openFail({ reason: `pty spawn failed: ${e.message}` }));
|
|
1080
1186
|
}
|
|
1081
1187
|
const ctl = {
|
|
1188
|
+
keyed: !cfg.sessions, // counts toward the key's `max-sessions` (a hosted session is counted by the registry)
|
|
1082
1189
|
// Bytes, not a `Buffer`: there is none in a browser (#133), and node-pty's streams take a Uint8Array as is.
|
|
1083
1190
|
// A write to a process that has exited throws; that is expected and dropped, anything else is logged.
|
|
1084
1191
|
input: (data) => {
|
|
@@ -1170,6 +1277,8 @@ export function createConnectionFactory(cfg) {
|
|
|
1170
1277
|
async function handleFileOp(m) {
|
|
1171
1278
|
const channelId = m.channel_id;
|
|
1172
1279
|
const target = m.target ?? undefined;
|
|
1280
|
+
const refusal = keyRefusal({ kind: 'file-op', op: m.op, target });
|
|
1281
|
+
if (refusal) return send(fileResult({ channelId, success: false, errorMessage: refusal.reason }));
|
|
1173
1282
|
const r0 = await resolveTarget(target, 'file');
|
|
1174
1283
|
if (r0.refuse) return send(fileResult({ channelId, success: false, errorMessage: r0.refuse }));
|
|
1175
1284
|
const files = r0.b.files;
|
package/src/server/index.d.ts
CHANGED
|
@@ -14,14 +14,26 @@ export interface WshServerPrincipal {
|
|
|
14
14
|
publicKey: Uint8Array;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/** What `authorize()` may return instead of `true` (#122): a capability list, and/or an expiry. */
|
|
18
|
+
export interface WshCapabilityGrant {
|
|
19
|
+
/** `exec`, `pty`, `relay`, `fs:read`, `fs:write`, `gateway:tcp:<host>:<port>`, `gateway:udp:<host>:<port>`, `gateway:listen:tcp:<port>`, `unix:<path>`, `unix:listen:<path>`, `endpoint:<name>`, `mcp:<tool>`, `target:<name>`, `rpc:<protocol>`; an array, or a comma-separated string. */
|
|
20
|
+
capabilities?: string | string[];
|
|
21
|
+
expires?: string | Date | number;
|
|
22
|
+
}
|
|
23
|
+
|
|
17
24
|
export interface WshServerAuthOptions {
|
|
18
25
|
/**
|
|
19
26
|
* Keys allowed to connect: `ssh-ed25519 AAAA... [comment]` lines (an
|
|
20
27
|
* `authorized_keys` file's text works), raw 32-byte keys, or an array of either.
|
|
21
28
|
*/
|
|
22
29
|
authorizedKeys?: string | Uint8Array | Array<string | Uint8Array>;
|
|
23
|
-
/**
|
|
24
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Extra policy, run after the signature verifies (and after the allowlist, when given). Return `true` to admit, or a
|
|
32
|
+
* capability set (#122) to admit with less: the key may do only what it names, on top of what its `authorized_keys` options
|
|
33
|
+
* allow (it never widens them). Same grammar as `capabilities="..."` in a key line; `expires` is an RFC 3339 string, a
|
|
34
|
+
* `Date` or epoch milliseconds (whole seconds are used). A set that is not understood refuses the login (logged).
|
|
35
|
+
*/
|
|
36
|
+
authorize?: (who: WshServerPrincipal) => boolean | WshCapabilityGrant | Promise<boolean | WshCapabilityGrant>;
|
|
25
37
|
/**
|
|
26
38
|
* Enable password login: return `true` to admit. Sent in the clear inside the
|
|
27
39
|
* connection -- serve over `wss://` / a trusted link. Use a constant-time
|
|
@@ -406,7 +418,7 @@ export interface WshServerOptions {
|
|
|
406
418
|
/** Port (default `0` = pick a free one; read it back from `address()`). */
|
|
407
419
|
port?: number;
|
|
408
420
|
/** Who may connect. Omitted = every connection is refused. A function is shorthand for `{ authorize }`. */
|
|
409
|
-
auth?: WshServerAuthOptions | ((who: WshServerPrincipal) => boolean | Promise<boolean>);
|
|
421
|
+
auth?: WshServerAuthOptions | ((who: WshServerPrincipal) => boolean | WshCapabilityGrant | Promise<boolean | WshCapabilityGrant>);
|
|
410
422
|
/** Enable `exec` sessions. `true`, options, or a custom runner. Off by default. */
|
|
411
423
|
exec?: true | WshServerExecOptions | WshExecRunner;
|
|
412
424
|
/** Enable `pty` sessions by injecting a pty implementation. Off by default. */
|
|
@@ -591,9 +603,44 @@ export interface WshServer {
|
|
|
591
603
|
|
|
592
604
|
export function createWshServer(options?: WshServerOptions): WshServer;
|
|
593
605
|
|
|
594
|
-
/**
|
|
606
|
+
/**
|
|
607
|
+
* Parse `authorized_keys`-style text into the raw 32-byte Ed25519 keys of the lines that carry NO options (malformed lines
|
|
608
|
+
* skipped). A line with options is not returned, because its restrictions would be lost: use `auth.authorizedKeys` (which
|
|
609
|
+
* enforces them) or `parseAuthorizedKeyEntries`.
|
|
610
|
+
*/
|
|
595
611
|
export function parseAuthorizedKeys(text: string): Uint8Array[];
|
|
596
612
|
|
|
613
|
+
/** What an `authorized_keys` line's options allow (wsh #122; the same on the Rust `wsh-server`). */
|
|
614
|
+
export interface KeyPermissions {
|
|
615
|
+
/** A pty shell. */
|
|
616
|
+
pty: boolean;
|
|
617
|
+
/** `exec` channels. */
|
|
618
|
+
exec: boolean;
|
|
619
|
+
/** MCP discovery and calls. */
|
|
620
|
+
mcp: boolean;
|
|
621
|
+
/** File channels, `FileOp` and `wsh-fs`. */
|
|
622
|
+
fileTransfer: boolean;
|
|
623
|
+
/** Relay registration, listing and connecting. */
|
|
624
|
+
relay: boolean;
|
|
625
|
+
/** `command="..."`: the only command the key may run (replaces what the client asks for). */
|
|
626
|
+
forcedCommand: string | null;
|
|
627
|
+
/** `max-sessions=N`: most live pty/exec sessions the key may hold at once. */
|
|
628
|
+
maxSessions: number | null;
|
|
629
|
+
/** `capabilities="..."` (#122, step two): `null` when the line has none; else the list, default-deny (only what it names). */
|
|
630
|
+
capabilities: string[] | null;
|
|
631
|
+
/** `expires="..."`: the epoch second from which the key is refused, or `null`. */
|
|
632
|
+
expires: number | null;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Parse `authorized_keys`-style text, options included. `refused` lists the lines whose options this host does not
|
|
637
|
+
* understand (`code`: `unknown-option`, `bad-syntax`, `bad-value`, `duplicate-option`); those keys are not let in.
|
|
638
|
+
*/
|
|
639
|
+
export function parseAuthorizedKeyEntries(text: string): {
|
|
640
|
+
entries: Array<{ key: Uint8Array; options: string | null; permissions: KeyPermissions; line: number }>;
|
|
641
|
+
refused: Array<{ line: number; code: string; reason: string; key: Uint8Array }>;
|
|
642
|
+
};
|
|
643
|
+
|
|
597
644
|
/** ServerHello feature: the host discovers client-opened exec data streams itself (no primer byte). */
|
|
598
645
|
export const STREAM_ANNOUNCE: 'stream-announce';
|
|
599
646
|
|
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
|
|
|
@@ -158,7 +158,7 @@ export function createWshServer({
|
|
|
158
158
|
|
|
159
159
|
function start() {
|
|
160
160
|
ready ??= (async () => {
|
|
161
|
-
const authorize = await buildAuthorizer(auth);
|
|
161
|
+
const authorize = await buildAuthorizer(auth, { log: onLog });
|
|
162
162
|
host_ = hostKey ? await loadHostKey(hostKey) : null;
|
|
163
163
|
if (sessionOptions) {
|
|
164
164
|
const secret = sessionOptions.sessionSecret ?? sessionSecret;
|