@infosupport/huddle-cli 0.0.0-experiment-109.61.1 → 0.0.0-experiment-128.65.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 +1 -59
- package/dist/api.js +14 -52
- package/dist/config.js +6 -145
- package/dist/experiment.js +7 -18
- package/dist/firewall.js +3 -168
- package/dist/images.js +8 -16
- package/dist/index.js +17 -222
- package/dist/init.js +84 -372
- package/dist/migrate.js +75 -120
- package/dist/start.js +2 -49
- package/package.json +3 -11
- package/dist/control-address.js +0 -160
- package/dist/control-probe.js +0 -174
- package/dist/logs.js +0 -213
- package/dist/node.js +0 -667
- package/dist/sbx-host-ca.js +0 -237
- package/dist/sbx-host.js +0 -36
- package/dist/sbx.js +0 -206
package/dist/migrate.js
CHANGED
|
@@ -19,8 +19,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
19
19
|
const utils_1 = require("./utils");
|
|
20
20
|
const runtime_1 = require("./runtime");
|
|
21
21
|
const init_1 = require("./init");
|
|
22
|
-
const node_1 = require("./node");
|
|
23
|
-
const api_1 = require("./api");
|
|
24
22
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
25
23
|
// Conventions
|
|
26
24
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -154,7 +152,7 @@ function pickHuddleNetKey(compose, markedNetwork, preferred) {
|
|
|
154
152
|
// add the Huddle egress network + proxy env, and (with --docker-socket) mount the
|
|
155
153
|
// filtered Docker socket. Any second, non-internal network is flagged as a
|
|
156
154
|
// blocker — it would be an unfiltered route out that bypasses Huddle.
|
|
157
|
-
function buildInjectedService(svc, name, compose, ctx, warnings, blockers
|
|
155
|
+
function buildInjectedService(svc, name, compose, ctx, warnings, blockers) {
|
|
158
156
|
for (const netKey of serviceNetworkKeys(svc)) {
|
|
159
157
|
if (netKey === ctx.markedNetwork)
|
|
160
158
|
continue;
|
|
@@ -164,18 +162,11 @@ function buildInjectedService(svc, name, compose, ctx, warnings, blockers, socke
|
|
|
164
162
|
'Remove it or make it internal — a second non-internal network bypasses Huddle.');
|
|
165
163
|
}
|
|
166
164
|
}
|
|
167
|
-
// The MITM CA is mounted, not fetched. Huddle Node holds the CA on the host and
|
|
168
|
-
// the gateway only gets it read-only, so there is no endpoint in the gateway to
|
|
169
|
-
// download it from — and adding one would be a devcontainer→Huddle path we
|
|
170
|
-
// deliberately do not have. A read-only bind is also what Huddle's own
|
|
171
|
-
// containers get, just seeded differently.
|
|
172
|
-
const volumes = [`${ctx.hostCaPath}:${ctx.caPath}:ro`];
|
|
173
165
|
const injected = {
|
|
174
166
|
// Keep the service on its own network AND add the Huddle egress network.
|
|
175
167
|
// Map form is robust regardless of Compose's list merge semantics.
|
|
176
168
|
networks: { [ctx.markedNetwork]: null, [ctx.huddleNetKey]: null },
|
|
177
169
|
environment: huddleProxyEnv(ctx.caPath, ctx.dockerSocket),
|
|
178
|
-
volumes,
|
|
179
170
|
};
|
|
180
171
|
if (ctx.dockerSocket) {
|
|
181
172
|
const cn = svc.container_name;
|
|
@@ -184,15 +175,13 @@ function buildInjectedService(svc, name, compose, ctx, warnings, blockers, socke
|
|
|
184
175
|
'at a stable path. Set a fixed container_name or drop --docker-socket for this service.');
|
|
185
176
|
}
|
|
186
177
|
else {
|
|
187
|
-
volumes
|
|
188
|
-
socketContainers.push(cn);
|
|
178
|
+
injected.volumes = [`${ctx.socketDir}/${cn}:/var/run/huddle`];
|
|
189
179
|
}
|
|
190
180
|
}
|
|
191
181
|
return injected;
|
|
192
182
|
}
|
|
193
183
|
function buildOverride(compose, opts = {}) {
|
|
194
184
|
const caPath = opts.caPath ?? exports.DEFAULT_CA_PATH;
|
|
195
|
-
const hostCaPath = opts.hostCaPath ?? path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
|
|
196
185
|
const internalNet = opts.internalNet ?? init_1.INTERNAL_NET;
|
|
197
186
|
const socketDir = opts.socketDir ?? init_1.HOST_SOCKET_DIR;
|
|
198
187
|
const warnings = [];
|
|
@@ -212,19 +201,11 @@ function buildOverride(compose, opts = {}) {
|
|
|
212
201
|
if (services.length === 0) {
|
|
213
202
|
warnings.push(`No service is attached to the marked network "${markedNetwork}"; the override wires nothing.`);
|
|
214
203
|
}
|
|
215
|
-
const ctx = {
|
|
216
|
-
markedNetwork,
|
|
217
|
-
huddleNetKey,
|
|
218
|
-
caPath,
|
|
219
|
-
hostCaPath,
|
|
220
|
-
socketDir,
|
|
221
|
-
dockerSocket: !!opts.dockerSocket,
|
|
222
|
-
};
|
|
204
|
+
const ctx = { markedNetwork, huddleNetKey, caPath, socketDir, dockerSocket: !!opts.dockerSocket };
|
|
223
205
|
const overrideServices = {};
|
|
224
|
-
const socketContainers = [];
|
|
225
206
|
for (const name of services) {
|
|
226
207
|
const svc = (compose.services?.[name] ?? {});
|
|
227
|
-
overrideServices[name] = buildInjectedService(svc, name, compose, ctx, warnings, blockers
|
|
208
|
+
overrideServices[name] = buildInjectedService(svc, name, compose, ctx, warnings, blockers);
|
|
228
209
|
}
|
|
229
210
|
const override = {
|
|
230
211
|
services: overrideServices,
|
|
@@ -234,7 +215,7 @@ function buildOverride(compose, opts = {}) {
|
|
|
234
215
|
[huddleNetKey]: { external: true, name: internalNet },
|
|
235
216
|
},
|
|
236
217
|
};
|
|
237
|
-
return { markedNetwork, services, override, warnings, blockers
|
|
218
|
+
return { markedNetwork, services, override, warnings, blockers };
|
|
238
219
|
}
|
|
239
220
|
function tokenize(input) {
|
|
240
221
|
const out = [];
|
|
@@ -311,76 +292,67 @@ function rejectUnsupportedYaml(lines) {
|
|
|
311
292
|
throw unsupportedYaml('a YAML alias (`*`)');
|
|
312
293
|
}
|
|
313
294
|
}
|
|
314
|
-
function atIndent(c, indent) {
|
|
315
|
-
return c.pos < c.lines.length && c.lines[c.pos].indent === indent;
|
|
316
|
-
}
|
|
317
|
-
// Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
|
|
318
|
-
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
319
|
-
function parseNode(c, indent, depth) {
|
|
320
|
-
if (depth > MAX_YAML_DEPTH) {
|
|
321
|
-
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
322
|
-
}
|
|
323
|
-
if (c.pos >= c.lines.length || c.lines[c.pos].indent < indent)
|
|
324
|
-
return null;
|
|
325
|
-
return isSeqItem(c.lines[c.pos].text) ? parseSequence(c, indent, depth) : parseMapping(c, indent, depth);
|
|
326
|
-
}
|
|
327
|
-
function parseMapping(c, indent, depth) {
|
|
328
|
-
const map = {};
|
|
329
|
-
while (atIndent(c, indent) && !isSeqItem(c.lines[c.pos].text)) {
|
|
330
|
-
const { text } = c.lines[c.pos];
|
|
331
|
-
const colon = findKeyColon(text);
|
|
332
|
-
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
333
|
-
if (colon < 0)
|
|
334
|
-
break;
|
|
335
|
-
const key = unquote(text.slice(0, colon).trim());
|
|
336
|
-
const rest = text.slice(colon + 1).trim();
|
|
337
|
-
c.pos++;
|
|
338
|
-
map[key] = parseMappingValue(c, rest, indent, depth);
|
|
339
|
-
}
|
|
340
|
-
return map;
|
|
341
|
-
}
|
|
342
|
-
/** The value belonging to `key:` — inline, the indented block below it, or none. */
|
|
343
|
-
function parseMappingValue(c, rest, indent, depth) {
|
|
344
|
-
if (rest !== '')
|
|
345
|
-
return parseScalar(rest);
|
|
346
|
-
if (c.pos < c.lines.length && c.lines[c.pos].indent > indent) {
|
|
347
|
-
return parseNode(c, c.lines[c.pos].indent, depth + 1);
|
|
348
|
-
}
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
function parseSequence(c, indent, depth) {
|
|
352
|
-
const arr = [];
|
|
353
|
-
while (atIndent(c, indent) && isSeqItem(c.lines[c.pos].text)) {
|
|
354
|
-
arr.push(parseSequenceItem(c, indent, depth));
|
|
355
|
-
}
|
|
356
|
-
return arr;
|
|
357
|
-
}
|
|
358
|
-
function parseSequenceItem(c, indent, depth) {
|
|
359
|
-
const line = c.lines[c.pos];
|
|
360
|
-
const afterDash = line.text.replace(/^-\s*/, '');
|
|
361
|
-
// A bare `-`: the item is the indented block on the following lines.
|
|
362
|
-
if (afterDash === '') {
|
|
363
|
-
c.pos++;
|
|
364
|
-
return c.pos < c.lines.length && c.lines[c.pos].indent > indent
|
|
365
|
-
? parseNode(c, c.lines[c.pos].indent, depth + 1)
|
|
366
|
-
: null;
|
|
367
|
-
}
|
|
368
|
-
// Inline map item: "- key: value". Re-interpret the remainder as a mapping
|
|
369
|
-
// that starts at a virtual indent past the dash. parseMapping consumes this
|
|
370
|
-
// same line, so the cursor deliberately does not advance here.
|
|
371
|
-
if (findKeyColon(afterDash) >= 0) {
|
|
372
|
-
const virtualIndent = indent + (line.text.length - afterDash.length);
|
|
373
|
-
c.lines[c.pos] = { indent: virtualIndent, text: afterDash };
|
|
374
|
-
return parseMapping(c, virtualIndent, depth + 1);
|
|
375
|
-
}
|
|
376
|
-
c.pos++;
|
|
377
|
-
return parseScalar(afterDash);
|
|
378
|
-
}
|
|
379
295
|
function parseYaml(input) {
|
|
380
296
|
const lines = tokenize(input);
|
|
381
297
|
rejectUnsupportedYaml(lines);
|
|
382
|
-
|
|
383
|
-
|
|
298
|
+
let pos = 0;
|
|
299
|
+
// Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
|
|
300
|
+
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
301
|
+
function parseNode(indent, depth) {
|
|
302
|
+
if (depth > MAX_YAML_DEPTH) {
|
|
303
|
+
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
304
|
+
}
|
|
305
|
+
if (pos >= lines.length || lines[pos].indent < indent)
|
|
306
|
+
return null;
|
|
307
|
+
return isSeqItem(lines[pos].text) ? parseSequence(indent, depth) : parseMapping(indent, depth);
|
|
308
|
+
}
|
|
309
|
+
function parseMapping(indent, depth) {
|
|
310
|
+
const map = {};
|
|
311
|
+
while (pos < lines.length && lines[pos].indent === indent && !isSeqItem(lines[pos].text)) {
|
|
312
|
+
const { text } = lines[pos];
|
|
313
|
+
const colon = findKeyColon(text);
|
|
314
|
+
if (colon < 0) {
|
|
315
|
+
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
const key = unquote(text.slice(0, colon).trim());
|
|
319
|
+
const rest = text.slice(colon + 1).trim();
|
|
320
|
+
pos++;
|
|
321
|
+
if (rest !== '') {
|
|
322
|
+
map[key] = parseScalar(rest);
|
|
323
|
+
}
|
|
324
|
+
else if (pos < lines.length && lines[pos].indent > indent) {
|
|
325
|
+
map[key] = parseNode(lines[pos].indent, depth + 1);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
map[key] = null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return map;
|
|
332
|
+
}
|
|
333
|
+
function parseSequence(indent, depth) {
|
|
334
|
+
const arr = [];
|
|
335
|
+
while (pos < lines.length && lines[pos].indent === indent && isSeqItem(lines[pos].text)) {
|
|
336
|
+
const afterDash = lines[pos].text.replace(/^-\s*/, '');
|
|
337
|
+
if (afterDash === '') {
|
|
338
|
+
pos++;
|
|
339
|
+
arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent, depth + 1) : null);
|
|
340
|
+
}
|
|
341
|
+
else if (findKeyColon(afterDash) >= 0) {
|
|
342
|
+
// Inline map item: "- key: value". Re-interpret the remainder as a
|
|
343
|
+
// mapping that starts at a virtual indent past the dash.
|
|
344
|
+
const virtualIndent = indent + (lines[pos].text.length - afterDash.length);
|
|
345
|
+
lines[pos] = { indent: virtualIndent, text: afterDash };
|
|
346
|
+
arr.push(parseMapping(virtualIndent, depth + 1));
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
arr.push(parseScalar(afterDash));
|
|
350
|
+
pos++;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return arr;
|
|
354
|
+
}
|
|
355
|
+
const root = parseNode(lines.length ? lines[0].indent : 0, 0);
|
|
384
356
|
return (root && typeof root === 'object' ? root : {});
|
|
385
357
|
}
|
|
386
358
|
function isSeqItem(text) {
|
|
@@ -607,8 +579,7 @@ async function runMigrate(opts) {
|
|
|
607
579
|
catch (err) {
|
|
608
580
|
throw new Error(`Could not parse ${composeFile}: ${err instanceof Error ? err.message : String(err)}`);
|
|
609
581
|
}
|
|
610
|
-
const
|
|
611
|
-
const result = buildOverride(compose, { caPath, hostCaPath, dockerSocket: opts.dockerSocket });
|
|
582
|
+
const result = buildOverride(compose, { caPath, dockerSocket: opts.dockerSocket });
|
|
612
583
|
console.log(`Marked network: ${(0, utils_1.bold)(result.markedNetwork)}`);
|
|
613
584
|
console.log(`Wired services: ${result.services.length ? result.services.map(utils_1.bold).join(', ') : (0, utils_1.dim)('(none)')}`);
|
|
614
585
|
for (const w of result.warnings)
|
|
@@ -640,32 +611,9 @@ async function runMigrate(opts) {
|
|
|
640
611
|
console.log((0, utils_1.yellow)(`[!] Could not confirm the "${init_1.INTERNAL_NET}" network exists. Run \`huddle init\` first.`));
|
|
641
612
|
console.log();
|
|
642
613
|
}
|
|
643
|
-
|
|
644
|
-
console.log((0, utils_1.yellow)(`[!] ${hostCaPath} does not exist yet — the override mounts it. Run \`huddle init\` first.`));
|
|
645
|
-
console.log();
|
|
646
|
-
}
|
|
647
|
-
// Register the socket-mounted container_names with Node NOW, before `docker
|
|
648
|
-
// compose up` ever runs them: the socket has to already exist inside the
|
|
649
|
-
// bind-mounted directory by the time the container starts, or it mounts an
|
|
650
|
-
// empty directory instead (see /api/docker/register-socket, api.ts). This is
|
|
651
|
-
// the only way Node learns about these containers at all — they carry none
|
|
652
|
-
// of the labels a Huddle-created devcontainer does.
|
|
653
|
-
if (result.socketContainers.length > 0) {
|
|
654
|
-
try {
|
|
655
|
-
await (0, api_1.post)('/api/docker/register-socket', { names: result.socketContainers });
|
|
656
|
-
console.log((0, utils_1.green)(`[OK] Registered filtered socket(s) for: ${result.socketContainers.join(', ')}`));
|
|
657
|
-
}
|
|
658
|
-
catch (err) {
|
|
659
|
-
const detail = err instanceof api_1.ApiError ? err.message : String(err);
|
|
660
|
-
console.log((0, utils_1.yellow)(`[!] Could not register the filtered socket with Huddle Node: ${detail}`));
|
|
661
|
-
console.log((0, utils_1.dim)(' Run `huddle init` (or re-run `huddle migrate --docker-socket`) once it is reachable —'));
|
|
662
|
-
console.log((0, utils_1.dim)(' until then the socket mount will not exist and DOCKER_HOST will point at nothing.'));
|
|
663
|
-
}
|
|
664
|
-
console.log();
|
|
665
|
-
}
|
|
666
|
-
printNextSteps(composeFile, outPath, caPath, hostCaPath);
|
|
614
|
+
printNextSteps(composeFile, outPath, caPath, !!opts.dockerSocket);
|
|
667
615
|
}
|
|
668
|
-
function printNextSteps(composeFile, outPath, caPath,
|
|
616
|
+
function printNextSteps(composeFile, outPath, caPath, dockerSocket) {
|
|
669
617
|
const composeBase = path_1.default.basename(composeFile);
|
|
670
618
|
const overrideBase = path_1.default.basename(outPath);
|
|
671
619
|
console.log((0, utils_1.bold)('Next steps (this command only GENERATED the override — it did not start anything):'));
|
|
@@ -673,8 +621,8 @@ function printNextSteps(composeFile, outPath, caPath, hostCaPath) {
|
|
|
673
621
|
console.log(' 1. Make sure Huddle is running:');
|
|
674
622
|
console.log((0, utils_1.cyan)(' huddle init'));
|
|
675
623
|
console.log();
|
|
676
|
-
console.log(' 2.
|
|
677
|
-
console.log((0, utils_1.cyan)(` ${
|
|
624
|
+
console.log(' 2. Fetch the Huddle CA inside the container. Add to your devcontainer.json:');
|
|
625
|
+
console.log((0, utils_1.cyan)(` "postCreateCommand": "curl -fsS http://huddle:3000/api/tls/ca.crt -o ${caPath} || echo 'CA not fetched (HTTPS tunnelled, no MITM)'"`));
|
|
678
626
|
console.log((0, utils_1.dim)(` (Adjust ${caPath} to your remoteUser's home if it differs; pass --ca-path to change it.)`));
|
|
679
627
|
console.log();
|
|
680
628
|
console.log(' 3. Reference the override so the IDE merges it. In devcontainer.json:');
|
|
@@ -682,5 +630,12 @@ function printNextSteps(composeFile, outPath, caPath, hostCaPath) {
|
|
|
682
630
|
console.log((0, utils_1.dim)(' Or start it yourself:'));
|
|
683
631
|
console.log((0, utils_1.cyan)(` docker compose -f ${composeBase} -f ${overrideBase} up -d`));
|
|
684
632
|
console.log();
|
|
633
|
+
if (dockerSocket) {
|
|
634
|
+
console.log((0, utils_1.yellow)(' Note (--docker-socket): the socket mount is GENERATED but NOT yet served.'));
|
|
635
|
+
console.log((0, utils_1.dim)(' Huddle does not yet pre-provision the per-container filtered socket for IDE-started\n' +
|
|
636
|
+
' containers (issue #66 follow-up). Until it does, the mount source will not exist and\n' +
|
|
637
|
+
' DOCKER_HOST will point at a missing socket. Only enable this once that lands.'));
|
|
638
|
+
console.log();
|
|
639
|
+
}
|
|
685
640
|
console.log((0, utils_1.dim)('See docs/migrate-devcontainers.md for the full guide and the marked-network convention.'));
|
|
686
641
|
}
|
package/dist/start.js
CHANGED
|
@@ -10,47 +10,12 @@ const api_1 = require("./api");
|
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
async function runStart(opts) {
|
|
12
12
|
const ide = parseIde(opts.ide);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
throw new Error('Cannot combine --workspace with --mount; use --mount for every folder instead.');
|
|
16
|
-
}
|
|
17
|
-
if (hasMounts && opts.empty) {
|
|
18
|
-
throw new Error('Cannot combine --empty with --mount.');
|
|
19
|
-
}
|
|
20
|
-
const resolvedMounts = hasMounts
|
|
21
|
-
? opts.mounts.map((m) => ({ hostPath: resolveWorkspace(m.hostPath), containerPath: validateContainerPath(m.containerPath) }))
|
|
22
|
-
: undefined;
|
|
23
|
-
if (resolvedMounts) {
|
|
24
|
-
const seen = new Set();
|
|
25
|
-
for (const m of resolvedMounts) {
|
|
26
|
-
if (seen.has(m.containerPath))
|
|
27
|
-
throw new Error(`Duplicate --mount container path: ${m.containerPath}`);
|
|
28
|
-
seen.add(m.containerPath);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const workspaceRoot = opts.workspaceRoot?.trim() || undefined;
|
|
32
|
-
if (workspaceRoot && !hasMounts) {
|
|
33
|
-
throw new Error('--workspace-root requires at least one --mount.');
|
|
34
|
-
}
|
|
35
|
-
if (workspaceRoot && !workspaceRoot.startsWith('/')) {
|
|
36
|
-
throw new Error(`--workspace-root must be an absolute container path: "${workspaceRoot}".`);
|
|
37
|
-
}
|
|
38
|
-
const workspaceDir = opts.empty || hasMounts ? undefined : resolveWorkspace(opts.workspace);
|
|
39
|
-
const baseName = opts.empty
|
|
40
|
-
? 'empty'
|
|
41
|
-
: hasMounts
|
|
42
|
-
? (resolvedMounts[0].containerPath.split('/').filter(Boolean).pop() ?? 'workspace')
|
|
43
|
-
: path_1.default.basename(workspaceDir);
|
|
13
|
+
const workspaceDir = opts.empty ? undefined : resolveWorkspace(opts.workspace);
|
|
14
|
+
const baseName = opts.empty ? 'empty' : path_1.default.basename(workspaceDir);
|
|
44
15
|
const containerName = opts.name ? validateContainerName(opts.name) : defaultContainerName(baseName);
|
|
45
16
|
console.log(`Starting ${(0, utils_1.bold)(containerName)} with ${(0, utils_1.bold)(ide)}...`);
|
|
46
17
|
if (workspaceDir)
|
|
47
18
|
console.log((0, utils_1.dim)(`Workspace: ${workspaceDir}`));
|
|
48
|
-
if (resolvedMounts) {
|
|
49
|
-
for (const m of resolvedMounts)
|
|
50
|
-
console.log((0, utils_1.dim)(`Mount ${m.hostPath} -> ${m.containerPath}`));
|
|
51
|
-
if (workspaceRoot)
|
|
52
|
-
console.log((0, utils_1.dim)(`Open IDE at: ${workspaceRoot}`));
|
|
53
|
-
}
|
|
54
19
|
let imageName = opts.image;
|
|
55
20
|
if (!imageName) {
|
|
56
21
|
const res = await (0, api_1.get)(`/api/docker/base-image?ide=${encodeURIComponent(ide)}`);
|
|
@@ -65,11 +30,6 @@ async function runStart(opts) {
|
|
|
65
30
|
if (opts.empty) {
|
|
66
31
|
body.empty = true;
|
|
67
32
|
}
|
|
68
|
-
else if (resolvedMounts) {
|
|
69
|
-
body.mounts = resolvedMounts;
|
|
70
|
-
if (workspaceRoot)
|
|
71
|
-
body.containerWorkspace = workspaceRoot;
|
|
72
|
-
}
|
|
73
33
|
else {
|
|
74
34
|
body.workspaceDir = workspaceDir;
|
|
75
35
|
}
|
|
@@ -119,13 +79,6 @@ function validateContainerName(name) {
|
|
|
119
79
|
}
|
|
120
80
|
return trimmed;
|
|
121
81
|
}
|
|
122
|
-
function validateContainerPath(path) {
|
|
123
|
-
const trimmed = (path ?? '').replace(/\\/g, '/').replace(/\/+$/, '').trim();
|
|
124
|
-
if (!trimmed.startsWith('/')) {
|
|
125
|
-
throw new Error(`Invalid --mount container path: "${path}". Use an absolute path, e.g. /workspace/backend.`);
|
|
126
|
-
}
|
|
127
|
-
return trimmed;
|
|
128
|
-
}
|
|
129
82
|
function parseIde(value) {
|
|
130
83
|
const normalized = value.toLowerCase().replace(/[ _-]+/g, '');
|
|
131
84
|
if (normalized === 'rider')
|
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-128.65.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,23 +20,15 @@
|
|
|
20
20
|
"build": "tsc",
|
|
21
21
|
"dev": "tsc --watch",
|
|
22
22
|
"install-global": "npm run build && npm install -g .",
|
|
23
|
-
"typecheck": "tsc --noEmit"
|
|
24
|
-
"test": "vitest run"
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@types/node": "^22.0.0",
|
|
28
|
-
"typescript": "^5.0.0"
|
|
29
|
-
"vitest": "^4.1.8"
|
|
27
|
+
"typescript": "^5.0.0"
|
|
30
28
|
},
|
|
31
29
|
"engines": {
|
|
32
30
|
"node": ">=18"
|
|
33
31
|
},
|
|
34
|
-
"optionalDependencies": {
|
|
35
|
-
"@infosupport/huddle-node-darwin-arm64": "0.0.0-experiment-109.61.1",
|
|
36
|
-
"@infosupport/huddle-node-darwin-x64": "0.0.0-experiment-109.61.1",
|
|
37
|
-
"@infosupport/huddle-node-linux-x64": "0.0.0-experiment-109.61.1",
|
|
38
|
-
"@infosupport/huddle-node-win32-x64": "0.0.0-experiment-109.61.1"
|
|
39
|
-
},
|
|
40
32
|
"files": [
|
|
41
33
|
"dist"
|
|
42
34
|
],
|
package/dist/control-address.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Where huddle-gateway finds Huddle Node.
|
|
3
|
-
//
|
|
4
|
-
// The gateway follows Huddle Node's control channel (policy in, decisions out).
|
|
5
|
-
// Node runs on the host now, so this is a container→host call, and how a
|
|
6
|
-
// container reaches its host is the one thing that genuinely differs per engine:
|
|
7
|
-
//
|
|
8
|
-
// Engine in a VM (Docker Desktop, Rancher, `podman machine`)
|
|
9
|
-
// `host.docker.internal` is routed to the real host, and a process bound
|
|
10
|
-
// to the host's LOOPBACK is reachable through it. Node keeps 127.0.0.1.
|
|
11
|
-
//
|
|
12
|
-
// Engine native on Linux (docker/podman on the same kernel)
|
|
13
|
-
// There is no such routing: the container sees the host only as the bridge
|
|
14
|
-
// gateway address (172.17.0.1 for Docker's `bridge`, 10.88.0.1 for
|
|
15
|
-
// Podman's `podman`). A loopback-bound listener is simply not reachable,
|
|
16
|
-
// so the control channel has to bind that address.
|
|
17
|
-
//
|
|
18
|
-
// Only the CONTROL channel moves. The portal and the REST API stay on loopback
|
|
19
|
-
// in both cases — they carry the operator token, which opens container
|
|
20
|
-
// terminals, execs and policy writes. The control channel carries a second,
|
|
21
|
-
// narrower token (gateway/src/auth.ts) and is the only thing worth exposing to
|
|
22
|
-
// the bridge. Devcontainers cannot reach even that: their network is `--internal`
|
|
23
|
-
// and has no route off itself.
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.HOST_ALIAS = void 0;
|
|
26
|
-
exports.parseBridgeGateway = parseBridgeGateway;
|
|
27
|
-
exports.bridgeGateway = bridgeGateway;
|
|
28
|
-
exports.resolveControlAddress = resolveControlAddress;
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
|
-
exports.HOST_ALIAS = 'host.docker.internal';
|
|
31
|
-
/**
|
|
32
|
-
* Pull the bridge gateway address out of `network inspect` JSON.
|
|
33
|
-
*
|
|
34
|
-
* Two shapes, because the engines disagree: Docker nests it under
|
|
35
|
-
* `IPAM.Config[].Gateway`, Podman under `subnets[].gateway`. Parsing the JSON
|
|
36
|
-
* rather than passing a Go template is what makes one code path serve both.
|
|
37
|
-
*
|
|
38
|
-
* Pure, so the shapes can be tested without an engine.
|
|
39
|
-
*/
|
|
40
|
-
function parseBridgeGateway(json) {
|
|
41
|
-
let parsed;
|
|
42
|
-
try {
|
|
43
|
-
parsed = JSON.parse(json);
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
const entry = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
49
|
-
if (!entry || typeof entry !== 'object')
|
|
50
|
-
return null;
|
|
51
|
-
const docker = entry.IPAM?.Config;
|
|
52
|
-
const podman = entry.subnets;
|
|
53
|
-
const rows = Array.isArray(docker) ? docker : Array.isArray(podman) ? podman : [];
|
|
54
|
-
for (const row of rows) {
|
|
55
|
-
if (!row || typeof row !== 'object')
|
|
56
|
-
continue;
|
|
57
|
-
const value = row.Gateway
|
|
58
|
-
?? row.gateway;
|
|
59
|
-
if (typeof value === 'string' && isIpLiteral(value))
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* An IP literal and nothing else. This value ends up as a bind address and
|
|
66
|
-
* inside a `-e HUDDLE_NODE_CONTROL_URL=...` argument, and it comes from whatever
|
|
67
|
-
* the engine reports — so a hostname, a CIDR suffix or anything with a shell
|
|
68
|
-
* metacharacter in it is rejected rather than passed on.
|
|
69
|
-
*/
|
|
70
|
-
function isIpLiteral(value) {
|
|
71
|
-
const v = value.trim();
|
|
72
|
-
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(v)) {
|
|
73
|
-
return v.split('.').every((o) => Number(o) <= 255);
|
|
74
|
-
}
|
|
75
|
-
return /^[0-9a-fA-F:]+$/.test(v) && v.includes(':');
|
|
76
|
-
}
|
|
77
|
-
/** Ask the engine for the default network's gateway address. Best-effort. */
|
|
78
|
-
function bridgeGateway(rt, network) {
|
|
79
|
-
try {
|
|
80
|
-
const out = (0, child_process_1.execFileSync)(rt, ['network', 'inspect', network], {
|
|
81
|
-
encoding: 'utf8',
|
|
82
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
83
|
-
timeout: 15_000,
|
|
84
|
-
});
|
|
85
|
-
return parseBridgeGateway(out);
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/** Bracket a literal IPv6 host for use in a URL, the way every other http://host:port here does. */
|
|
92
|
-
function formatHost(host) {
|
|
93
|
-
return host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Decide the pair (bind host, URL) from what we know about the engine. Pure —
|
|
97
|
-
* the engine probing happens in bridgeGateway() above.
|
|
98
|
-
*/
|
|
99
|
-
function resolveControlAddress(input) {
|
|
100
|
-
const override = input.override?.trim();
|
|
101
|
-
const bindOverride = input.bindOverride?.trim();
|
|
102
|
-
const derived = derive(input);
|
|
103
|
-
// HUDDLE_CONTROL_HOST moves where Node binds; unless HUDDLE_NODE_CONTROL_URL
|
|
104
|
-
// says otherwise too, the URL handed to the gateway has to move with it. Left
|
|
105
|
-
// pinned to the auto-derived URL, Node ends up listening on the overridden
|
|
106
|
-
// host while the gateway keeps probing the stale one — and being fail-closed,
|
|
107
|
-
// denies every request. HUDDLE_NODE_CONTROL_URL, when given, still wins: it is
|
|
108
|
-
// the more specific override and may legitimately name something other than
|
|
109
|
-
// the bind host (a different port, a tunnel, host.docker.internal itself).
|
|
110
|
-
const url = override || (bindOverride ? `http://${formatHost(bindOverride)}:${input.port}` : derived.url);
|
|
111
|
-
return {
|
|
112
|
-
...derived,
|
|
113
|
-
bindHost: bindOverride || derived.bindHost,
|
|
114
|
-
url,
|
|
115
|
-
reason: override || bindOverride
|
|
116
|
-
? 'set explicitly via HUDDLE_NODE_CONTROL_URL / HUDDLE_CONTROL_HOST'
|
|
117
|
-
: derived.reason,
|
|
118
|
-
// Whoever set it explicitly knows their own topology better than we do.
|
|
119
|
-
reachable: derived.reachable || !!override || !!bindOverride,
|
|
120
|
-
// Either override may name something other than the alias; adding a host
|
|
121
|
-
// entry for a name nobody asked about would be noise at best.
|
|
122
|
-
runArgs: (override || bindOverride) ? [] : derived.runArgs,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function derive(input) {
|
|
126
|
-
const { port } = input;
|
|
127
|
-
if (input.isRemote) {
|
|
128
|
-
return {
|
|
129
|
-
bindHost: '127.0.0.1',
|
|
130
|
-
url: `http://${exports.HOST_ALIAS}:${port}`,
|
|
131
|
-
// Docker Desktop provides the alias already; Podman machine and Rancher
|
|
132
|
-
// are less consistent about it, and asking for it twice costs nothing.
|
|
133
|
-
runArgs: ['--add-host', `${exports.HOST_ALIAS}:host-gateway`],
|
|
134
|
-
reason: 'the engine runs in a VM, so the host is reachable on its loopback',
|
|
135
|
-
reachable: true,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (input.gatewayIp) {
|
|
139
|
-
return {
|
|
140
|
-
bindHost: input.gatewayIp,
|
|
141
|
-
url: `http://${formatHost(input.gatewayIp)}:${port}`,
|
|
142
|
-
runArgs: [],
|
|
143
|
-
reason: `native engine — the container reaches this host at ${input.gatewayIp}`,
|
|
144
|
-
reachable: true,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
// Native engine, and we could not read the bridge address — so there is no
|
|
148
|
-
// address we can honestly name. Loopback is deliberate: 0.0.0.0 would put the
|
|
149
|
-
// control channel on the LAN and any VPN to fix a problem we have not even
|
|
150
|
-
// confirmed. The gateway then reaches nothing and, being fail-closed, denies
|
|
151
|
-
// every request until an operator sets HUDDLE_CONTROL_HOST. A visibly dead
|
|
152
|
-
// firewall beats a quietly widened one.
|
|
153
|
-
return {
|
|
154
|
-
bindHost: '127.0.0.1',
|
|
155
|
-
url: `http://${exports.HOST_ALIAS}:${port}`,
|
|
156
|
-
runArgs: ['--add-host', `${exports.HOST_ALIAS}:host-gateway`],
|
|
157
|
-
reason: 'the bridge gateway address could not be read from the engine',
|
|
158
|
-
reachable: false,
|
|
159
|
-
};
|
|
160
|
-
}
|