@infosupport/huddle-cli 0.0.0-experiment-98.52.1 → 0.0.0-experiment-109.54.1
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 +37 -32
- package/dist/api.js +45 -14
- package/dist/control-address.js +160 -0
- package/dist/control-probe.js +174 -0
- package/dist/experiment.js +6 -0
- package/dist/firewall.js +10 -6
- package/dist/images.js +13 -9
- package/dist/index.js +139 -45
- package/dist/init.js +354 -89
- package/dist/logs.js +213 -0
- package/dist/migrate.js +53 -17
- package/dist/node.js +534 -0
- package/dist/sbx-host-ca.js +237 -0
- package/dist/sbx-host.js +36 -0
- package/dist/sbx.js +211 -0
- package/package.json +11 -3
- package/dist/indexfolder.js +0 -167
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ── Huddle CA → HOST trust store (sbx mode) ───────────────────────────────────
|
|
3
|
+
// WHY THIS EXISTS (measured, not assumed):
|
|
4
|
+
//
|
|
5
|
+
// In sbx mode there are TWO TLS terminators, not one. For most hosts the sbx
|
|
6
|
+
// proxy just tunnels CONNECT to Huddle, so the client *inside* the sandbox sees
|
|
7
|
+
// Huddle's leaf and `sbx.ts:trustCa()` (CA installed in the sandbox) is enough:
|
|
8
|
+
//
|
|
9
|
+
// sandbox curl https://github.com → issuer: CN=Huddle DMZ Proxy Root CA
|
|
10
|
+
//
|
|
11
|
+
// But for at least the Claude/Anthropic hosts sbx terminates TLS ITSELF:
|
|
12
|
+
//
|
|
13
|
+
// sandbox curl https://platform.claude.com → issuer: CN=Docker Sandboxes Proxy CA
|
|
14
|
+
//
|
|
15
|
+
// There the upstream leg to Huddle is dialed by the sbx daemon — a HOST process
|
|
16
|
+
// that validates against the HOST trust store, which does not know Huddle's CA.
|
|
17
|
+
// The handshake with the client succeeds (sbx signs its own leaf immediately),
|
|
18
|
+
// the upstream validation then fails, and the connection is closed without a
|
|
19
|
+
// response: `curl: (52) Empty reply from server`, and `claude` reports
|
|
20
|
+
// "Failed to connect to platform.claude.com: ECONNRESET".
|
|
21
|
+
//
|
|
22
|
+
// So the CA has to be trusted in TWO places: inside the sandbox (trustCa) and on
|
|
23
|
+
// the host (here). Idempotent — safe to call on every `huddle init`.
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.HOST_CA_PATH = void 0;
|
|
29
|
+
exports.certFingerprint = certFingerprint;
|
|
30
|
+
exports.installHostCa = installHostCa;
|
|
31
|
+
exports.printHostCaResult = printHostCaResult;
|
|
32
|
+
const fs_1 = __importDefault(require("fs"));
|
|
33
|
+
const os_1 = __importDefault(require("os"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
35
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
36
|
+
const child_process_1 = require("child_process");
|
|
37
|
+
const config_1 = require("./config");
|
|
38
|
+
const sbx_host_1 = require("./sbx-host");
|
|
39
|
+
const node_1 = require("./node");
|
|
40
|
+
const utils_1 = require("./utils");
|
|
41
|
+
/** Stable host path, so re-running init points at the same file. */
|
|
42
|
+
exports.HOST_CA_PATH = path_1.default.join(config_1.CONFIG_DIR, 'huddle-ca.crt');
|
|
43
|
+
const LINUX_CA_PATH = '/usr/local/share/ca-certificates/huddle-ca.crt';
|
|
44
|
+
/** No console window per child process on Windows (same reason as sbx-host.ts). */
|
|
45
|
+
const NO_WINDOW = { windowsHide: true };
|
|
46
|
+
function run(file, args, timeout = 30_000) {
|
|
47
|
+
try {
|
|
48
|
+
const out = (0, child_process_1.execFileSync)(file, args, { encoding: 'utf8', timeout, stdio: ['ignore', 'pipe', 'pipe'], ...NO_WINDOW });
|
|
49
|
+
return { code: 0, out: out ?? '' };
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
const e = err;
|
|
53
|
+
const out = `${e.stdout ?? ''}${e.stderr ?? ''}` || e.message || '';
|
|
54
|
+
return { code: typeof e.status === 'number' ? e.status : 1, out: String(out) };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Blocking sleep — this runs in the CLI's synchronous init path, not in a loop. */
|
|
58
|
+
function sleepSync(ms) {
|
|
59
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Read the CA off this machine. It used to take a `docker exec` into the gateway
|
|
63
|
+
* container, because that is where the CA lived; Huddle Node owns it now and
|
|
64
|
+
* writes it to ~/.huddle/ca (gateway/src/runtime-env.ts), so this is a file read.
|
|
65
|
+
*
|
|
66
|
+
* Still retried: initCa() runs during Node's boot, and `huddle init` calls this
|
|
67
|
+
* moments after the process reported healthy.
|
|
68
|
+
*/
|
|
69
|
+
function readHostCa(tries = 12) {
|
|
70
|
+
const caPath = path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
|
|
71
|
+
for (let i = 0; i < tries; i++) {
|
|
72
|
+
try {
|
|
73
|
+
const pem = fs_1.default.readFileSync(caPath, 'utf8');
|
|
74
|
+
if (pem.includes('-----BEGIN CERTIFICATE-----'))
|
|
75
|
+
return pem;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Not written yet — that is the race this loop exists for.
|
|
79
|
+
}
|
|
80
|
+
if (i === tries - 1)
|
|
81
|
+
return null;
|
|
82
|
+
sleepSync(500);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
/** SHA-1 over the DER body of the first PEM block — the thumbprint certutil uses. */
|
|
87
|
+
function certFingerprint(pem) {
|
|
88
|
+
const b64 = pem
|
|
89
|
+
.split('-----BEGIN CERTIFICATE-----')[1]
|
|
90
|
+
?.split('-----END CERTIFICATE-----')[0]
|
|
91
|
+
?.replace(/\s+/g, '');
|
|
92
|
+
if (!b64)
|
|
93
|
+
throw new Error('not a PEM certificate');
|
|
94
|
+
return crypto_1.default.createHash('sha1').update(Buffer.from(b64, 'base64')).digest('hex').toUpperCase();
|
|
95
|
+
}
|
|
96
|
+
// ── per-platform install ─────────────────────────────────────────────────────
|
|
97
|
+
/**
|
|
98
|
+
* Is the cert in this Windows root store? Asks the STORE, never the exit code:
|
|
99
|
+
* certutil's status codes are unreliable here (`-addstore` can print its success
|
|
100
|
+
* banner "Signature matches Public Key" and still exit non-zero, and
|
|
101
|
+
* `-verifystore` fails a chain check on a root it does happily hold). The
|
|
102
|
+
* thumbprint appearing in the listing is the only honest answer.
|
|
103
|
+
*/
|
|
104
|
+
function inWindowsStore(scope, fp) {
|
|
105
|
+
const scoped = scope === 'user' ? ['-user'] : [];
|
|
106
|
+
const has = (out) => out.replace(/[\s:]/g, '').toUpperCase().includes(fp);
|
|
107
|
+
// Targeted lookup first; fall back to a full dump for certutil builds that
|
|
108
|
+
// don't take a thumbprint as the cert-id argument.
|
|
109
|
+
if (has(run('certutil', [...scoped, '-store', 'Root', fp]).out))
|
|
110
|
+
return true;
|
|
111
|
+
return has(run('certutil', [...scoped, '-store', 'Root'], 60_000).out);
|
|
112
|
+
}
|
|
113
|
+
/** Pick the line that actually says what went wrong, not just the last one. */
|
|
114
|
+
function certutilError(out) {
|
|
115
|
+
const lines = out.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
116
|
+
const blame = [...lines].reverse().find((l) => /CertUtil:|FAILED|denied|0x[0-9A-Fa-f]{8}/.test(l));
|
|
117
|
+
return blame ?? lines.pop() ?? 'certutil failed';
|
|
118
|
+
}
|
|
119
|
+
function installWindows(certPath, fp) {
|
|
120
|
+
const manualHint = `certutil -addstore -f Root "${certPath}" (elevated prompt)`;
|
|
121
|
+
const found = (store, alreadyTrusted) => ({ ok: true, alreadyTrusted, store, certPath, fingerprint: fp, daemonRestarted: false });
|
|
122
|
+
// Go (which sbx is built with) reads the CURRENT_USER "ROOT" store, which the
|
|
123
|
+
// machine store is merged into — so the user store works WITHOUT elevation.
|
|
124
|
+
if (inWindowsStore('user', fp))
|
|
125
|
+
return found('windows-user', true);
|
|
126
|
+
if (inWindowsStore('machine', fp))
|
|
127
|
+
return found('windows-machine', true);
|
|
128
|
+
const user = run('certutil', ['-user', '-addstore', '-f', 'Root', certPath]);
|
|
129
|
+
if (inWindowsStore('user', fp))
|
|
130
|
+
return found('windows-user', false);
|
|
131
|
+
// Fall back to the machine store (needs an elevated prompt; usually fails here).
|
|
132
|
+
run('certutil', ['-addstore', '-f', 'Root', certPath]);
|
|
133
|
+
if (inWindowsStore('machine', fp))
|
|
134
|
+
return found('windows-machine', false);
|
|
135
|
+
return {
|
|
136
|
+
ok: false, alreadyTrusted: false, certPath, fingerprint: fp, daemonRestarted: false,
|
|
137
|
+
error: certutilError(user.out),
|
|
138
|
+
manualHint,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function installMacos(certPath, fp) {
|
|
142
|
+
const keychain = path_1.default.join(os_1.default.homedir(), 'Library/Keychains/login.keychain-db');
|
|
143
|
+
const manualHint = `security add-trusted-cert -r trustRoot -k "${keychain}" "${certPath}"`;
|
|
144
|
+
const found = run('security', ['find-certificate', '-a', '-Z', keychain]);
|
|
145
|
+
if (found.code === 0 && found.out.toUpperCase().includes(fp)) {
|
|
146
|
+
return { ok: true, alreadyTrusted: true, store: 'macos-login', certPath, fingerprint: fp, daemonRestarted: false };
|
|
147
|
+
}
|
|
148
|
+
// No -d: the login keychain needs no sudo (it may raise a GUI confirmation).
|
|
149
|
+
const add = run('security', ['add-trusted-cert', '-r', 'trustRoot', '-k', keychain, certPath], 60_000);
|
|
150
|
+
if (add.code === 0) {
|
|
151
|
+
return { ok: true, alreadyTrusted: false, store: 'macos-login', certPath, fingerprint: fp, daemonRestarted: false };
|
|
152
|
+
}
|
|
153
|
+
return { ok: false, alreadyTrusted: false, certPath, fingerprint: fp, daemonRestarted: false, error: add.out.trim(), manualHint };
|
|
154
|
+
}
|
|
155
|
+
function installLinux(certPath, pem, fp) {
|
|
156
|
+
const manualHint = `sudo cp "${certPath}" ${LINUX_CA_PATH} && sudo update-ca-certificates`;
|
|
157
|
+
try {
|
|
158
|
+
if (fs_1.default.readFileSync(LINUX_CA_PATH, 'utf8').trim() === pem.trim()) {
|
|
159
|
+
return { ok: true, alreadyTrusted: true, store: 'linux-system', certPath, fingerprint: fp, daemonRestarted: false };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch { /* not installed yet */ }
|
|
163
|
+
const copy = run('sh', ['-c', `cp ${JSON.stringify(certPath)} ${LINUX_CA_PATH} 2>/dev/null || (command -v sudo >/dev/null 2>&1 && sudo -n cp ${JSON.stringify(certPath)} ${LINUX_CA_PATH})`]);
|
|
164
|
+
if (copy.code !== 0) {
|
|
165
|
+
return { ok: false, alreadyTrusted: false, certPath, fingerprint: fp, daemonRestarted: false, error: 'need root to write ' + LINUX_CA_PATH, manualHint };
|
|
166
|
+
}
|
|
167
|
+
run('sh', ['-c', 'command -v update-ca-certificates >/dev/null 2>&1 && (update-ca-certificates >/dev/null 2>&1 || sudo -n update-ca-certificates >/dev/null 2>&1) || true'], 60_000);
|
|
168
|
+
return { ok: true, alreadyTrusted: false, store: 'linux-system', certPath, fingerprint: fp, daemonRestarted: false };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Trust Huddle's CA on the HOST, then restart the sbx daemon so it reloads its
|
|
172
|
+
* root set. Never throws — sandbox mode is optional
|
|
173
|
+
* and this must never fail `huddle init`.
|
|
174
|
+
*/
|
|
175
|
+
function installHostCa(opts = {}) {
|
|
176
|
+
const pem = readHostCa();
|
|
177
|
+
if (!pem) {
|
|
178
|
+
const caPath = path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
|
|
179
|
+
return {
|
|
180
|
+
ok: false, alreadyTrusted: false, daemonRestarted: false,
|
|
181
|
+
error: `could not read ${caPath} — is Huddle Node running?`,
|
|
182
|
+
manualHint: `huddle init (Huddle Node writes the CA on boot)`,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
let fp;
|
|
186
|
+
try {
|
|
187
|
+
fp = certFingerprint(pem);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
return { ok: false, alreadyTrusted: false, daemonRestarted: false, error: err.message };
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
fs_1.default.mkdirSync(config_1.CONFIG_DIR, { recursive: true });
|
|
194
|
+
fs_1.default.writeFileSync(exports.HOST_CA_PATH, pem, { mode: 0o644 });
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
return { ok: false, alreadyTrusted: false, fingerprint: fp, daemonRestarted: false, error: err.message };
|
|
198
|
+
}
|
|
199
|
+
let result;
|
|
200
|
+
if (process.platform === 'win32')
|
|
201
|
+
result = installWindows(exports.HOST_CA_PATH, fp);
|
|
202
|
+
else if (process.platform === 'darwin')
|
|
203
|
+
result = installMacos(exports.HOST_CA_PATH, fp);
|
|
204
|
+
else
|
|
205
|
+
result = installLinux(exports.HOST_CA_PATH, pem, fp);
|
|
206
|
+
// A freshly added root is only picked up by a running daemon after a restart.
|
|
207
|
+
// 'always' is for the explicit `huddle sbx trust-host`: you only type that when
|
|
208
|
+
// something is broken, and a store that was filled by an earlier run (before
|
|
209
|
+
// any restart) must not be silently skipped as "already trusted".
|
|
210
|
+
const mode = opts.restartDaemon ?? 'auto';
|
|
211
|
+
if (result.ok && mode !== 'never' && (mode === 'always' || !result.alreadyTrusted)) {
|
|
212
|
+
result.daemonRestarted = run((0, sbx_host_1.resolveSbxBin)(), ['daemon', 'restart'], 120_000).code === 0;
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
/** Human-readable one-liner + guidance. Shared by `huddle init` and `huddle sbx trust-host`. */
|
|
217
|
+
function printHostCaResult(r, indent = ' ') {
|
|
218
|
+
if (r.ok && r.alreadyTrusted) {
|
|
219
|
+
console.log((0, utils_1.dim)(`${indent}Huddle CA already trusted on the host (${r.store}) — sbx can reach Huddle over TLS.`));
|
|
220
|
+
if (r.daemonRestarted)
|
|
221
|
+
console.log((0, utils_1.dim)(`${indent} sbx daemon restarted so it re-reads the root store.`));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (r.ok) {
|
|
225
|
+
console.log((0, utils_1.green)(`${indent}[OK] Huddle CA trusted on the host (${r.store})`));
|
|
226
|
+
console.log((0, utils_1.dim)(`${indent} ${r.certPath} · SHA-1 ${r.fingerprint}`));
|
|
227
|
+
console.log((0, utils_1.dim)(`${indent} ${r.daemonRestarted ? 'sbx daemon restarted' : 'restart the sbx daemon to pick it up: sbx daemon restart'}`));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
console.log((0, utils_1.yellow)(`${indent}Could not trust Huddle's CA on the host: ${r.error}`));
|
|
231
|
+
console.log((0, utils_1.dim)(`${indent} Without it, sbx cannot validate Huddle for the hosts it MITMs itself`));
|
|
232
|
+
console.log((0, utils_1.dim)(`${indent} (e.g. platform.claude.com) — those requests die as "Empty reply from server".`));
|
|
233
|
+
if (r.manualHint)
|
|
234
|
+
console.log((0, utils_1.dim)(`${indent} Do it manually: ${r.manualHint}`));
|
|
235
|
+
if (r.certPath)
|
|
236
|
+
console.log((0, utils_1.dim)(`${indent} Then: sbx daemon restart`));
|
|
237
|
+
}
|
package/dist/sbx-host.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ── Finding sbx on the host ───────────────────────────────────────────────────
|
|
3
|
+
// Docker Sandboxes (`sbx`) is a HOST binary. It manages VMs/containers through
|
|
4
|
+
// the user's own Docker installation and it is the thing Huddle points at its
|
|
5
|
+
// egress proxy — it was never something the gateway container could run.
|
|
6
|
+
//
|
|
7
|
+
// This module is what remains of the sbx bridge after the split (step 5 of
|
|
8
|
+
// docs/ADR-huddle-node-split.md): the bridge existed only to carry argv from a
|
|
9
|
+
// containerized Huddle to the host and back, and Huddle Node runs on the host,
|
|
10
|
+
// so it exec's sbx directly. Resolving WHICH binary and keeping Windows from
|
|
11
|
+
// flashing a console window are still real problems, so they live on here.
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.NO_WINDOW = void 0;
|
|
14
|
+
exports.resolveSbxBin = resolveSbxBin;
|
|
15
|
+
const child_process_1 = require("child_process");
|
|
16
|
+
/**
|
|
17
|
+
* No console window per child process on Windows.
|
|
18
|
+
*
|
|
19
|
+
* Huddle spawns sbx often and sometimes from a detached, console-less process;
|
|
20
|
+
* without this, Windows opens a terminal window for every single call.
|
|
21
|
+
*/
|
|
22
|
+
exports.NO_WINDOW = { windowsHide: true };
|
|
23
|
+
/** Resolve the host sbx binary: HUDDLE_SBX_BIN, else `sbx`, else `sbx.exe`. */
|
|
24
|
+
function resolveSbxBin() {
|
|
25
|
+
const env = process.env.HUDDLE_SBX_BIN?.trim();
|
|
26
|
+
if (env)
|
|
27
|
+
return env;
|
|
28
|
+
for (const c of ['sbx', 'sbx.exe']) {
|
|
29
|
+
try {
|
|
30
|
+
(0, child_process_1.execFileSync)(c, ['version'], { stdio: 'ignore', timeout: 15000, ...exports.NO_WINDOW });
|
|
31
|
+
return c;
|
|
32
|
+
}
|
|
33
|
+
catch { /* try next */ }
|
|
34
|
+
}
|
|
35
|
+
return 'sbx';
|
|
36
|
+
}
|
package/dist/sbx.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ── `huddle sbx` — Docker Sandboxes command group ─────────────────────────────
|
|
3
|
+
// Thin client: every subcommand just calls the gateway's /api/sbx/* endpoints
|
|
4
|
+
// (same role the rest of the CLI plays). The gateway talks to the native
|
|
5
|
+
// host-agent over the volume-mapped socket; nothing sbx-related runs here.
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.runSbxStatus = runSbxStatus;
|
|
41
|
+
exports.runSbxList = runSbxList;
|
|
42
|
+
exports.runSbxStart = runSbxStart;
|
|
43
|
+
exports.runSbxRemove = runSbxRemove;
|
|
44
|
+
exports.runSbxLog = runSbxLog;
|
|
45
|
+
exports.runSbxIngest = runSbxIngest;
|
|
46
|
+
exports.runSbxTrustCa = runSbxTrustCa;
|
|
47
|
+
exports.runSbxTrustHost = runSbxTrustHost;
|
|
48
|
+
exports.runSbxSshSetup = runSbxSshSetup;
|
|
49
|
+
exports.runSbxReconcile = runSbxReconcile;
|
|
50
|
+
const api_1 = require("./api");
|
|
51
|
+
const utils_1 = require("./utils");
|
|
52
|
+
function scopeLabel(scope) {
|
|
53
|
+
return scope.kind === 'sandbox' && scope.name ? `sandbox:${scope.name}` : 'global';
|
|
54
|
+
}
|
|
55
|
+
async function runSbxStatus() {
|
|
56
|
+
const s = await (0, api_1.get)('/api/sbx/status');
|
|
57
|
+
console.log(`Sandbox (sbx) mode`);
|
|
58
|
+
console.log(` host-agent socket: ${s.socket ?? (0, utils_1.dim)('(not reachable)')}`);
|
|
59
|
+
console.log(` upstream proxy: ${s.upstreamUrl} ${(0, utils_1.dim)(`(port ${s.proxyPort})`)}`);
|
|
60
|
+
if (s.available) {
|
|
61
|
+
console.log(` sbx: ready — ${s.version}`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.log(` sbx: unavailable`);
|
|
65
|
+
if (s.error)
|
|
66
|
+
console.log((0, utils_1.dim)(` reason: ${s.error}`));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function runSbxList() {
|
|
70
|
+
const { sandboxes } = await (0, api_1.get)('/api/sbx/sandboxes');
|
|
71
|
+
if (!sandboxes.length) {
|
|
72
|
+
console.log((0, utils_1.dim)('No sandboxes.'));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const nameW = Math.max(4, ...sandboxes.map((s) => s.name.length));
|
|
76
|
+
console.log(`${'NAME'.padEnd(nameW)} STATUS`);
|
|
77
|
+
for (const s of sandboxes)
|
|
78
|
+
console.log(`${s.name.padEnd(nameW)} ${s.status ?? ''}`);
|
|
79
|
+
}
|
|
80
|
+
async function runSbxStart(opts) {
|
|
81
|
+
const body = {};
|
|
82
|
+
if (opts.name)
|
|
83
|
+
body.name = opts.name;
|
|
84
|
+
if (opts.agent)
|
|
85
|
+
body.agent = opts.agent;
|
|
86
|
+
// A sandbox can hold several folders: --workspace is the one the agent starts in,
|
|
87
|
+
// every --folder is mounted alongside it. `<path>:ro` mounts that folder
|
|
88
|
+
// read-only (sbx's own suffix). Huddle's settings folders are added server-side.
|
|
89
|
+
const folders = (opts.folders ?? []).map((f) => f.trim()).filter(Boolean);
|
|
90
|
+
if (folders.length) {
|
|
91
|
+
const first = opts.workspace ? [{ path: opts.workspace, readOnly: false }] : [];
|
|
92
|
+
body.workspaces = [...first, ...folders.map(parseFolderArg)];
|
|
93
|
+
}
|
|
94
|
+
else if (opts.workspace) {
|
|
95
|
+
body.workspace = opts.workspace;
|
|
96
|
+
}
|
|
97
|
+
const r = await (0, api_1.post)('/api/sbx/start', body);
|
|
98
|
+
console.log(`${r.ok ? '✓ sandbox created' : '✗ stopped at a wall'}: ${r.name}`);
|
|
99
|
+
console.log((0, utils_1.dim)(` upstream ${r.upstreamUrl}`));
|
|
100
|
+
for (const w of r.workspaces ?? [])
|
|
101
|
+
console.log((0, utils_1.dim)(` folder ${w.path}${w.readOnly ? ' (read-only)' : ''}`));
|
|
102
|
+
for (const step of r.steps) {
|
|
103
|
+
console.log(` ${step.code === 0 ? '✓' : '✗'} ${step.label} ${(0, utils_1.dim)(`(exit ${step.code})`)}`);
|
|
104
|
+
console.log((0, utils_1.dim)(` ${step.command}`));
|
|
105
|
+
if (step.stdout?.trim() && step.label.startsWith('link settings folders')) {
|
|
106
|
+
console.log((0, utils_1.dim)(` ${step.stdout.trim().split('\n').join('\n ')}`));
|
|
107
|
+
}
|
|
108
|
+
if (step.stderr.trim())
|
|
109
|
+
console.log((0, utils_1.dim)(` ${step.stderr.trim().split('\n').join('\n ')}`));
|
|
110
|
+
}
|
|
111
|
+
for (const s of r.settingsSkipped ?? [])
|
|
112
|
+
console.log((0, utils_1.dim)(` ! settings folder '${s.name}' not mounted: ${s.reason}`));
|
|
113
|
+
if (!r.ok)
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
}
|
|
116
|
+
/** `<host path>` or `<host path>:ro` — sbx's own read-only workspace suffix. */
|
|
117
|
+
function parseFolderArg(raw) {
|
|
118
|
+
const m = /^(.*?):(ro|rw)$/i.exec(raw);
|
|
119
|
+
if (!m)
|
|
120
|
+
return { path: raw, readOnly: false };
|
|
121
|
+
return { path: m[1], readOnly: m[2].toLowerCase() === 'ro' };
|
|
122
|
+
}
|
|
123
|
+
async function runSbxRemove(opts) {
|
|
124
|
+
if (!opts.name) {
|
|
125
|
+
console.error('Usage: huddle sbx rm <name> [--force]');
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
const q = opts.force ? '?force=1' : '';
|
|
129
|
+
const r = await (0, api_1.del)(`/api/sbx/sandboxes/${encodeURIComponent(opts.name)}${q}`);
|
|
130
|
+
console.log(`${r.ok ? '✓ removed' : '✗ failed'}: ${r.name} ${(0, utils_1.dim)(`(exit ${r.exitCode})`)}`);
|
|
131
|
+
if (!r.ok)
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}
|
|
134
|
+
async function runSbxLog(opts) {
|
|
135
|
+
if (!opts.name) {
|
|
136
|
+
console.error('Usage: huddle sbx log <name>');
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const r = await (0, api_1.get)(`/api/sbx/sandboxes/${encodeURIComponent(opts.name)}/log`);
|
|
140
|
+
console.log((0, utils_1.dim)('── raw `sbx policy log --json` ──'));
|
|
141
|
+
console.log(r.raw.trim() || (0, utils_1.dim)('(empty)'));
|
|
142
|
+
console.log((0, utils_1.dim)(`── parsed denied (${r.denied.length}) ──`));
|
|
143
|
+
for (const d of r.denied)
|
|
144
|
+
console.log(` ✗ ${d.domain}${d.sandbox ? (0, utils_1.dim)(' @ ' + d.sandbox) : ''}`);
|
|
145
|
+
if (r.denied.length === 0)
|
|
146
|
+
console.log((0, utils_1.dim)(' (parser matched nothing — paste the raw JSON above so the parser can be tuned)'));
|
|
147
|
+
}
|
|
148
|
+
async function runSbxIngest() {
|
|
149
|
+
const r = await (0, api_1.post)('/api/sbx/ingest', {});
|
|
150
|
+
console.log(`Ingested ${r.added} blocked request(s) from sbx → pending in Huddle.`);
|
|
151
|
+
}
|
|
152
|
+
async function runSbxTrustCa(opts) {
|
|
153
|
+
if (!opts.name) {
|
|
154
|
+
console.error('Usage: huddle sbx trust-ca <name>');
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
const r = await (0, api_1.post)(`/api/sbx/sandboxes/${encodeURIComponent(opts.name)}/trust-ca`, {});
|
|
158
|
+
const marker = (r.stdout || '').match(/HUDDLE_CA_INSTALLED_\w+/)?.[0];
|
|
159
|
+
console.log(`${r.ok ? '✓ Huddle CA installed' : '✗ CA install failed'}: ${r.name} ${(0, utils_1.dim)(`(exit ${r.code}${marker ? ', ' + marker.toLowerCase() : ''})`)}`);
|
|
160
|
+
if (r.stderr?.trim())
|
|
161
|
+
console.log((0, utils_1.dim)(` ${r.stderr.trim().split('\n').join('\n ')}`));
|
|
162
|
+
if (r.ok)
|
|
163
|
+
console.log((0, utils_1.dim)(' HTTPS from inside the sandbox now trusts Huddle — reconnect your editor.'));
|
|
164
|
+
else
|
|
165
|
+
process.exitCode = 1;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Trust Huddle's CA on the HOST (where the sbx daemon runs), not inside a
|
|
169
|
+
* sandbox. Needed because sbx terminates TLS itself for some hosts (measured:
|
|
170
|
+
* platform.claude.com gets a `Docker Sandboxes Proxy CA` leaf) and then
|
|
171
|
+
* validates Huddle's certificate against the host trust store. Without it those
|
|
172
|
+
* requests die as "Empty reply from server" / ECONNRESET — see sbx-host-ca.ts.
|
|
173
|
+
*/
|
|
174
|
+
async function runSbxTrustHost(opts = {}) {
|
|
175
|
+
const { installHostCa, printHostCaResult } = await Promise.resolve().then(() => __importStar(require('./sbx-host-ca')));
|
|
176
|
+
console.log('Trusting Huddle’s CA on the host (for the sbx daemon)');
|
|
177
|
+
const r = installHostCa({ restartDaemon: 'always' });
|
|
178
|
+
printHostCaResult(r);
|
|
179
|
+
if (!r.ok)
|
|
180
|
+
process.exitCode = 1;
|
|
181
|
+
}
|
|
182
|
+
async function runSbxSshSetup() {
|
|
183
|
+
const r = await (0, api_1.post)('/api/sbx/ssh-setup', {});
|
|
184
|
+
if (r.ok) {
|
|
185
|
+
console.log('✓ SSH bridge ready. Connect an editor with:');
|
|
186
|
+
console.log((0, utils_1.dim)(' ssh <sandbox-name>.sbx # or add it as a VS Code / JetBrains remote host'));
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
console.log(`✗ ssh setup failed (exit ${r.exitCode})`);
|
|
190
|
+
process.exitCode = 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function runSbxReconcile(opts) {
|
|
194
|
+
const q = opts.dryRun ? '?dryRun=1' : '';
|
|
195
|
+
const r = await (0, api_1.post)(`/api/sbx/reconcile${q}`, {});
|
|
196
|
+
const mode = r.dryRun ? 'DRY RUN — ' : '';
|
|
197
|
+
if (r.error) {
|
|
198
|
+
console.error(`✗ ${mode}reconcile could not run: ${r.error}`);
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
console.log(`${mode}Reconcile sbx policy (allow-all per sandbox; Huddle's proxy enforces)`);
|
|
202
|
+
console.log(` created: ${r.created} removed: ${r.deleted} failed: ${r.failed}`);
|
|
203
|
+
if (r.sandboxes.length)
|
|
204
|
+
console.log((0, utils_1.dim)(` sandboxes: ${r.sandboxes.map((n) => 'sandbox:' + n).join(', ')}`));
|
|
205
|
+
for (const a of r.actions) {
|
|
206
|
+
const sym = a.ok ? (a.op === 'create' ? '+' : '-') : '✗';
|
|
207
|
+
console.log(` ${sym} ${a.op} ${a.action} ${a.target} @ ${scopeLabel(a.scope)}${a.error ? (0, utils_1.dim)(' — ' + a.error) : ''}`);
|
|
208
|
+
}
|
|
209
|
+
if (r.failed > 0)
|
|
210
|
+
process.exitCode = 1;
|
|
211
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infosupport/huddle-cli",
|
|
3
|
-
"version": "0.0.0-experiment-
|
|
3
|
+
"version": "0.0.0-experiment-109.54.1",
|
|
4
4
|
"description": "Huddle CLI — start devcontainers and manage firewall rules",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"author": "Info Support B.V.",
|
|
@@ -20,15 +20,23 @@
|
|
|
20
20
|
"build": "tsc",
|
|
21
21
|
"dev": "tsc --watch",
|
|
22
22
|
"install-global": "npm run build && npm install -g .",
|
|
23
|
-
"typecheck": "tsc --noEmit"
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "^22.0.0",
|
|
27
|
-
"typescript": "^5.0.0"
|
|
28
|
+
"typescript": "^5.0.0",
|
|
29
|
+
"vitest": "^4.1.8"
|
|
28
30
|
},
|
|
29
31
|
"engines": {
|
|
30
32
|
"node": ">=18"
|
|
31
33
|
},
|
|
34
|
+
"optionalDependencies": {
|
|
35
|
+
"@infosupport/huddle-node-darwin-arm64": "1.3.0",
|
|
36
|
+
"@infosupport/huddle-node-darwin-x64": "1.3.0",
|
|
37
|
+
"@infosupport/huddle-node-linux-x64": "1.3.0",
|
|
38
|
+
"@infosupport/huddle-node-win32-x64": "1.3.0"
|
|
39
|
+
},
|
|
32
40
|
"files": [
|
|
33
41
|
"dist"
|
|
34
42
|
],
|