@aide-family/dsh-remote 0.0.0-stage → 0.6.2
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/LICENSE +21 -0
- package/README.md +793 -2
- package/bin/dsh-remote-terminal +82 -0
- package/cordis.patch.yml +3 -0
- package/docs/TERMINAL_ACTIONS.md +39 -0
- package/docs/assets/host-audit.png +0 -0
- package/docs/assets/host-manager.png +0 -0
- package/docs/assets/live-terminal.png +0 -0
- package/docs/assets/remote-ops.png +0 -0
- package/docs/assets/remote-terminal.png +0 -0
- package/docs/icon.svg +11 -0
- package/lib/api-helpers.js +325 -0
- package/lib/api.js +715 -0
- package/lib/approval.js +238 -0
- package/lib/audit.js +224 -0
- package/lib/client.js +4919 -0
- package/lib/config.js +762 -0
- package/lib/connection-profile.js +65 -0
- package/lib/host-registry.js +703 -0
- package/lib/host-store.js +139 -0
- package/lib/hosts.js +442 -0
- package/lib/index.js +419 -0
- package/lib/live-stream.js +121 -0
- package/lib/live.js +245 -0
- package/lib/policy/argv.js +77 -0
- package/lib/policy/command-guard.js +404 -0
- package/lib/policy/docker.js +140 -0
- package/lib/policy/index.js +21 -0
- package/lib/policy/inspection.js +111 -0
- package/lib/policy/kubectl.js +128 -0
- package/lib/policy/shell-command.js +525 -0
- package/lib/policy/shell-wrappers.js +143 -0
- package/lib/policy/ssh.js +53 -0
- package/lib/policy/sudo.js +38 -0
- package/lib/policy/systemctl.js +22 -0
- package/lib/policy/types.js +12 -0
- package/lib/prompt.js +29 -0
- package/lib/render.js +442 -0
- package/lib/runtime-deps.js +50 -0
- package/lib/ssh/auth.js +256 -0
- package/lib/ssh/connection.js +504 -0
- package/lib/ssh/errors.js +209 -0
- package/lib/ssh/exec.js +394 -0
- package/lib/ssh/known-hosts.js +313 -0
- package/lib/ssh/pty.js +472 -0
- package/lib/ssh/sftp.js +589 -0
- package/lib/ssh/transport.js +801 -0
- package/lib/ssh-config.js +395 -0
- package/lib/terminal/bridge.cjs +305 -0
- package/lib/terminal/connection-login.js +188 -0
- package/lib/terminal/manager.js +656 -0
- package/lib/terminal/node-launcher.js +211 -0
- package/lib/terminal/pty-session.js +673 -0
- package/lib/terminal/relay-socket.js +605 -0
- package/lib/terminal/relay.js +905 -0
- package/lib/terminal/scrollback.js +588 -0
- package/lib/terminal/tools.js +532 -0
- package/lib/tools.js +751 -0
- package/package.json +90 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Pure validation for terminal-only connection action profiles. */
|
|
2
|
+
const LOOKUP_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u;
|
|
3
|
+
const LOGIN_RE = /^ *sww +-r +-u +([A-Za-z0-9][A-Za-z0-9._-]{0,63}) +([A-Za-z0-9][A-Za-z0-9._-]{0,63}) *$/u;
|
|
4
|
+
export const TERMINAL_ACTION_KEYS = Object.freeze({
|
|
5
|
+
Enter: "\r", Tab: "\t", Escape: "\x1b", "Ctrl-C": "\x03", "Ctrl-D": "\x04",
|
|
6
|
+
ArrowUp: "\x1b[A", ArrowDown: "\x1b[B", ArrowLeft: "\x1b[D", ArrowRight: "\x1b[C", Backspace: "\x7f",
|
|
7
|
+
});
|
|
8
|
+
const FIELDS = {
|
|
9
|
+
command: ["type", "label", "value", "expect", "expectCluster", "timeoutMs"],
|
|
10
|
+
text: ["type", "label", "value", "expect", "timeoutMs"],
|
|
11
|
+
key: ["type", "label", "value", "expect", "timeoutMs"],
|
|
12
|
+
wait: ["type", "label", "value", "timeoutMs"],
|
|
13
|
+
delay: ["type", "label", "durationMs"],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Normalize and deep-copy actions. Never interpret user-supplied regular expressions. */
|
|
17
|
+
export function normalizeTerminalActions(actions) {
|
|
18
|
+
if (!Array.isArray(actions) || actions.length < 1 || actions.length > 32) throw invalid("actions must contain 1-32 items");
|
|
19
|
+
return Array.from(actions).map((action, index) => {
|
|
20
|
+
if (!action || typeof action !== "object" || Array.isArray(action) || !Object.hasOwn(FIELDS, action.type)) throw invalid(`actions[${index}] has an invalid type`);
|
|
21
|
+
const allowed = FIELDS[action.type];
|
|
22
|
+
for (const field of Object.keys(action)) if (!allowed.includes(field)) throw invalid(`actions[${index}] has an unsupported field`);
|
|
23
|
+
const result = { type: action.type };
|
|
24
|
+
if (action.label !== undefined) result.label = boundedText(action.label, 80, /[\x00-\x1f\x7f]/u, "action label");
|
|
25
|
+
if (action.type === "delay") {
|
|
26
|
+
result.durationMs = boundedInteger(action.durationMs, 0, 120_000, "durationMs");
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (action.type === "key") {
|
|
30
|
+
if (typeof action.value !== "string" || !Object.hasOwn(TERMINAL_ACTION_KEYS, action.value)) throw invalid("unsupported action key");
|
|
31
|
+
result.value = action.value;
|
|
32
|
+
} else result.value = boundedText(action.value, action.type === "wait" ? 2048 : 4096, action.type === "wait" ? /[\x00\x1b]/u : /[\x00-\x1f\x7f]/u, "action value");
|
|
33
|
+
if (action.expect !== undefined) result.expect = boundedText(action.expect, 2048, /[\x00\x1b]/u, "action expect");
|
|
34
|
+
if (action.expectCluster !== undefined) {
|
|
35
|
+
if (action.expect !== undefined || typeof action.expectCluster !== "string" || !LOOKUP_NAME_RE.test(action.expectCluster) || /\s/u.test(action.expectCluster)) throw invalid("expectCluster must be a safe cluster name and cannot be combined with expect");
|
|
36
|
+
result.expectCluster = action.expectCluster;
|
|
37
|
+
}
|
|
38
|
+
if (action.timeoutMs !== undefined) result.timeoutMs = boundedInteger(action.timeoutMs, 100, 120_000, "timeoutMs");
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Host metadata may accompany the profile; only connection fields are returned. */
|
|
44
|
+
export function normalizeConnectionProfile(input) {
|
|
45
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) throw invalid("connection profile must be an object");
|
|
46
|
+
const { viaHost, loginCommand, actions } = input;
|
|
47
|
+
if (viaHost === undefined && loginCommand === undefined && actions === undefined) return {};
|
|
48
|
+
if (typeof viaHost !== "string" || /\s/u.test(viaHost) || !LOOKUP_NAME_RE.test(viaHost)) throw invalid("viaHost must be a safe host lookup name (1-64 ASCII characters)");
|
|
49
|
+
if (actions !== undefined) return { viaHost, actions: normalizeTerminalActions(actions) };
|
|
50
|
+
if (typeof loginCommand !== "string" || /[\x00-\x1f\x7f]/u.test(loginCommand)) throw invalid("loginCommand must be a single-line sww -r -u <user> <cluster> command");
|
|
51
|
+
const match = LOGIN_RE.exec(loginCommand);
|
|
52
|
+
if (!match) throw invalid("loginCommand only supports sww -r -u <safe-user> <safe-cluster>");
|
|
53
|
+
return { viaHost, actions: [{ type: "command", value: `sww -r -u ${match[1]} ${match[2]}`, expectCluster: match[2] }] };
|
|
54
|
+
}
|
|
55
|
+
function boundedText(value, max, controls, name) {
|
|
56
|
+
if (typeof value !== "string" || value.length < 1 || value.length > max || controls.test(value)) throw invalid(`${name} must contain 1-${max} valid characters`);
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function boundedInteger(value, min, max, name) {
|
|
60
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) throw invalid(`${name} must be an integer from ${min} to ${max}`);
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
function invalid(message) {
|
|
64
|
+
return Object.assign(new Error(`dsh-remote: ${message}`), { code: "HOST_INVALID" });
|
|
65
|
+
}
|