@infosupport/huddle-cli 0.0.0-experiment-109.66.1 → 0.0.0-experiment-56.68.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/init.js
CHANGED
|
@@ -1,210 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
// Huddle Node on the HOST — portal, API, database, CA, Docker
|
|
7
|
-
// orchestration, sbx. Started here, detached.
|
|
8
|
-
// huddle-gateway in a CONTAINER — the filtering proxies devcontainers are
|
|
9
|
-
// DNAT'ed to, and nothing else.
|
|
10
|
-
//
|
|
11
|
-
// Order matters: Node owns the database, the CA and the gateway token, so it has
|
|
12
|
-
// to exist before there is anything for the gateway to be handed. The container
|
|
13
|
-
// is started second and given exactly three things — where Node is, the token to
|
|
14
|
-
// talk to it with, and the CA directory read-only.
|
|
15
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
-
}
|
|
21
|
-
Object.defineProperty(o, k2, desc);
|
|
22
|
-
}) : (function(o, m, k, k2) {
|
|
23
|
-
if (k2 === undefined) k2 = k;
|
|
24
|
-
o[k2] = m[k];
|
|
25
|
-
}));
|
|
26
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
-
}) : function(o, v) {
|
|
29
|
-
o["default"] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
-
var ownKeys = function(o) {
|
|
33
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
-
var ar = [];
|
|
35
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
-
return ar;
|
|
37
|
-
};
|
|
38
|
-
return ownKeys(o);
|
|
39
|
-
};
|
|
40
|
-
return function (mod) {
|
|
41
|
-
if (mod && mod.__esModule) return mod;
|
|
42
|
-
var result = {};
|
|
43
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
-
__setModuleDefault(result, mod);
|
|
45
|
-
return result;
|
|
46
|
-
};
|
|
47
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
48
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
6
|
exports.HOST_SOCKET_DIR = exports.INTERNAL_NET = void 0;
|
|
50
7
|
exports.runInit = runInit;
|
|
51
8
|
const child_process_1 = require("child_process");
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
52
10
|
const utils_1 = require("./utils");
|
|
53
11
|
const runtime_1 = require("./runtime");
|
|
54
12
|
const images_1 = require("./images");
|
|
55
13
|
const config_1 = require("./config");
|
|
56
|
-
const
|
|
57
|
-
const control_probe_1 = require("./control-probe");
|
|
58
|
-
const node_1 = require("./node");
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
59
15
|
const CONTAINER = 'huddle';
|
|
60
|
-
|
|
61
|
-
* Ask Huddle Node to wire the freshly created gateway into every devcontainer.
|
|
62
|
-
*
|
|
63
|
-
* The container above is brand new, so each existing devcontainer is attached to
|
|
64
|
-
* a `huddle` that no longer exists and DNATs port 80 to an IP that is gone —
|
|
65
|
-
* which is silent, not loud: the devcontainer just stops reaching anything.
|
|
66
|
-
*
|
|
67
|
-
* Node does this itself at boot, but that only covers a first install. Re-running
|
|
68
|
-
* init reuses the Node that is already up while replacing the container, so the
|
|
69
|
-
* request has to come from here. Node's job and not the CLI's, because rebuilding
|
|
70
|
-
* those rules means exec'ing into every devcontainer.
|
|
71
|
-
*
|
|
72
|
-
* Best-effort: a gateway that is up but not yet wired is worth reporting, not
|
|
73
|
-
* worth failing init over — the portal offers a per-container reconnect too.
|
|
74
|
-
*/
|
|
75
|
-
async function rewireGateway(port, token) {
|
|
76
|
-
const url = `${(0, node_1.nodeProbeUrls)(port)[0]}/api/docker/rewire-gateway`;
|
|
77
|
-
try {
|
|
78
|
-
const res = await fetch(url, {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers: token ? { authorization: `Bearer ${token}` } : {},
|
|
81
|
-
});
|
|
82
|
-
if (!res.ok)
|
|
83
|
-
throw new Error(`HTTP ${res.status}`);
|
|
84
|
-
const rep = (await res.json());
|
|
85
|
-
const attached = rep.attached?.length ?? 0;
|
|
86
|
-
const reissued = rep.reissued?.length ?? 0;
|
|
87
|
-
console.log((0, utils_1.dim)(` wired into ${attached} devcontainer network(s), ${rep.refreshed?.length ?? 0} refreshed`));
|
|
88
|
-
// Only when it happened: a container that already trusted this root is the
|
|
89
|
-
// normal case and says nothing. A container that did NOT is worth seeing,
|
|
90
|
-
// because until this ran its HTTPS was failing on the CA signature.
|
|
91
|
-
if (reissued)
|
|
92
|
-
console.log((0, utils_1.dim)(` root CA reinstalled in ${reissued} devcontainer(s)`));
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
console.log((0, utils_1.yellow)(`[!] Could not wire the gateway into the devcontainer networks: ${err.message}`));
|
|
96
|
-
console.log((0, utils_1.dim)(' Existing devcontainers may not reach Huddle until you reconnect them in the portal.'));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Confirm the gateway can actually reach Huddle Node — and move the control
|
|
101
|
-
* channel if it cannot.
|
|
102
|
-
*
|
|
103
|
-
* resolveControlAddress() derives an address from what the engine reports about
|
|
104
|
-
* itself, and that derivation is right until it is not: on Rancher Desktop for
|
|
105
|
-
* Windows the engine is a WSL distro, so `host.docker.internal` resolves to that
|
|
106
|
-
* distro's own docker0 gateway while Huddle Node is a Windows process on the
|
|
107
|
-
* Windows loopback. Both halves are healthy and they cannot see each other.
|
|
108
|
-
*
|
|
109
|
-
* There is no way to tell that from a derivation, and getting it wrong is
|
|
110
|
-
* expensive: the gateway fails closed, so every devcontainer is denied all
|
|
111
|
-
* egress and nothing appears in the portal to approve — a firewall that looks
|
|
112
|
-
* installed and blocks everything. So open the connection for real, from the
|
|
113
|
-
* gateway's own image on the gateway's own network, and believe the result.
|
|
114
|
-
*
|
|
115
|
-
* `rebind` restarts Huddle Node on a different interface and reports whether it
|
|
116
|
-
* managed to. Passed in rather than done here because init owns the options
|
|
117
|
-
* Node was started with.
|
|
118
|
-
*/
|
|
119
|
-
async function verifyControlChannel(rt, image, network, control, rebind) {
|
|
120
|
-
const first = (0, control_probe_1.probeControlUrl)(rt, image, control.url, network, control.runArgs);
|
|
121
|
-
if (first.reachable) {
|
|
122
|
-
console.log((0, utils_1.dim)(` reachable from a container at ${control.url} (${first.detail})`));
|
|
123
|
-
return { ...control, reachable: true };
|
|
124
|
-
}
|
|
125
|
-
const unreachable = (fixed, detail) => {
|
|
126
|
-
console.log((0, utils_1.yellow)(`[!] The gateway cannot reach Huddle Node at ${fixed.url} (${detail}).`));
|
|
127
|
-
console.log((0, utils_1.yellow)(' It fails closed, so every devcontainer will be denied all egress and'));
|
|
128
|
-
console.log((0, utils_1.yellow)(' nothing will show up in the portal to approve.'));
|
|
129
|
-
return { ...fixed, reachable: false };
|
|
130
|
-
};
|
|
131
|
-
// An address someone named by hand is not ours to overrule — they know their
|
|
132
|
-
// own topology, and silently moving the channel would hide the real problem.
|
|
133
|
-
if (process.env.HUDDLE_NODE_CONTROL_URL?.trim() || process.env.HUDDLE_CONTROL_HOST?.trim()) {
|
|
134
|
-
const out = unreachable(control, first.detail);
|
|
135
|
-
console.log((0, utils_1.dim)(' That address was set explicitly, so it is left as it is.'));
|
|
136
|
-
return out;
|
|
137
|
-
}
|
|
138
|
-
console.log((0, utils_1.dim)(` ${control.url} did not answer (${first.detail}) — looking for an address that does`));
|
|
139
|
-
const vmGateway = (0, control_probe_1.engineHostAddress)(rt, image);
|
|
140
|
-
// Cheapest first: another way for the container to reach the loopback Node is
|
|
141
|
-
// already bound to. Nothing restarts, and nothing about how Huddle is exposed
|
|
142
|
-
// changes — so this is the outcome to want, not merely the quickest one.
|
|
143
|
-
for (const url of (0, control_probe_1.hostCandidateUrls)(CONTROL_PORT, vmGateway)) {
|
|
144
|
-
const probe = (0, control_probe_1.probeControlUrl)(rt, image, url, network, []);
|
|
145
|
-
if (!probe.reachable)
|
|
146
|
-
continue;
|
|
147
|
-
console.log((0, utils_1.dim)(` reachable from a container at ${url} (${probe.detail})`));
|
|
148
|
-
return {
|
|
149
|
-
bindHost: control.bindHost,
|
|
150
|
-
url,
|
|
151
|
-
runArgs: [],
|
|
152
|
-
reason: `${control_address_1.HOST_ALIAS} does not reach this machine from ${rt}; ${new URL(url).hostname} does`,
|
|
153
|
-
reachable: true,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
// Nothing reaches loopback, so Huddle Node has to move to an interface the
|
|
157
|
-
// engine can route to. Only an address this machine actually owns: the
|
|
158
|
-
// engine's own gateway is not one, and binding it kills Node outright.
|
|
159
|
-
const bindIp = (0, control_probe_1.pickBindAddress)((0, control_probe_1.localIpv4Addresses)(), vmGateway);
|
|
160
|
-
if (!bindIp) {
|
|
161
|
-
const out = unreachable(control, first.detail);
|
|
162
|
-
console.log((0, utils_1.dim)(` Tried every address ${rt} suggested${vmGateway ? ` (its gateway is ${vmGateway})` : ''}.`));
|
|
163
|
-
console.log((0, utils_1.dim)(' Name one yourself and re-run init:'));
|
|
164
|
-
console.log((0, utils_1.cyan)(' HUDDLE_CONTROL_HOST=<address the container reaches this machine on> huddle init'));
|
|
165
|
-
return out;
|
|
166
|
-
}
|
|
167
|
-
const moved = {
|
|
168
|
-
bindHost: bindIp,
|
|
169
|
-
url: `http://${bindIp}:${CONTROL_PORT}`,
|
|
170
|
-
runArgs: [],
|
|
171
|
-
reason: `${control_address_1.HOST_ALIAS} does not reach this machine; ${rt} routes to it at ${bindIp}`,
|
|
172
|
-
reachable: false,
|
|
173
|
-
};
|
|
174
|
-
console.log((0, utils_1.dim)(` moving the control channel to ${bindIp} and restarting Huddle Node`));
|
|
175
|
-
if (!(await rebind(bindIp))) {
|
|
176
|
-
// Put it back where it was. A control channel that does not work is a broken
|
|
177
|
-
// firewall; no Huddle Node at all is a broken machine — no portal, no API,
|
|
178
|
-
// and init about to hand the gateway a token it cannot read.
|
|
179
|
-
console.log((0, utils_1.yellow)(`[!] Huddle Node would not start on ${bindIp} — restoring ${control.bindHost}.`));
|
|
180
|
-
if (!(await rebind(control.bindHost))) {
|
|
181
|
-
console.log((0, utils_1.red)(' It would not start there either. Check the log:'));
|
|
182
|
-
console.log((0, utils_1.cyan)(` ${node_1.NODE_LOG_FILE}`));
|
|
183
|
-
}
|
|
184
|
-
const out = unreachable(control, first.detail);
|
|
185
|
-
console.log((0, utils_1.dim)(' Name an address yourself and re-run init:'));
|
|
186
|
-
console.log((0, utils_1.cyan)(' HUDDLE_CONTROL_HOST=<address the container reaches this machine on> huddle init'));
|
|
187
|
-
return out;
|
|
188
|
-
}
|
|
189
|
-
const second = (0, control_probe_1.probeControlUrl)(rt, image, moved.url, network, []);
|
|
190
|
-
if (second.reachable) {
|
|
191
|
-
console.log((0, utils_1.dim)(` reachable from a container at ${moved.url} (${second.detail})`));
|
|
192
|
-
return { ...moved, reachable: true };
|
|
193
|
-
}
|
|
194
|
-
const out = unreachable(moved, second.detail);
|
|
195
|
-
console.log((0, utils_1.dim)(` ${rt} routes to this machine at ${bindIp} and Huddle Node is bound there,`));
|
|
196
|
-
console.log((0, utils_1.dim)(' so something here is dropping the connection. On Windows that is Defender'));
|
|
197
|
-
console.log((0, utils_1.dim)(` Firewall: allow inbound TCP ${CONTROL_PORT} for node.exe on that adapter.`));
|
|
198
|
-
console.log((0, utils_1.dim)(' Nothing needs re-running afterwards — the gateway keeps retrying.'));
|
|
199
|
-
return out;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Huddle Node's control channel on the host. Its own port, never the portal's:
|
|
203
|
-
* the portal carries the operator token and stays on loopback, while this one
|
|
204
|
-
* may have to be reachable from the gateway container. Must match
|
|
205
|
-
* HUDDLE_CONTROL_PORT in gateway/src/runtime-env.ts.
|
|
206
|
-
*/
|
|
207
|
-
const CONTROL_PORT = Number(process.env.HUDDLE_CONTROL_PORT ?? 24843);
|
|
16
|
+
const VOLUME = 'huddle-data';
|
|
208
17
|
/**
|
|
209
18
|
* The shared, internal network that `huddle init` creates (`--internal`, so it
|
|
210
19
|
* has no route to the internet of its own). Devcontainers attach to it to reach
|
|
@@ -219,40 +28,19 @@ exports.INTERNAL_NET = 'devcontainer-net';
|
|
|
219
28
|
* `huddle migrate` can generate the matching bind mount.
|
|
220
29
|
*/
|
|
221
30
|
exports.HOST_SOCKET_DIR = '/tmp/dc-sockets';
|
|
222
|
-
const HOST_PORT = process.env.HUDDLE_PORT ??
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
// authenticated settings API) must never be interpolated into a shell string, or
|
|
226
|
-
// a path containing `$()`/quotes would execute on the host. Used for `docker run`.
|
|
227
|
-
function runArgs(file, args) {
|
|
228
|
-
(0, child_process_1.execFileSync)(file, args, { stdio: 'inherit' });
|
|
31
|
+
const HOST_PORT = process.env.HUDDLE_PORT ?? '3000';
|
|
32
|
+
function run(cmd) {
|
|
33
|
+
(0, child_process_1.execSync)(cmd, { stdio: 'inherit' });
|
|
229
34
|
}
|
|
230
|
-
function
|
|
35
|
+
function runSilent(cmd) {
|
|
231
36
|
try {
|
|
232
|
-
(0, child_process_1.
|
|
37
|
+
(0, child_process_1.execSync)(cmd, { stdio: 'ignore' });
|
|
233
38
|
return true;
|
|
234
39
|
}
|
|
235
40
|
catch {
|
|
236
41
|
return false;
|
|
237
42
|
}
|
|
238
43
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Report where each devcontainer's filtered Docker socket will be served.
|
|
241
|
-
*
|
|
242
|
-
* On the ENGINE host, and by the GATEWAY — which is the only process guaranteed
|
|
243
|
-
* to be there. Huddle Node is on the operator's machine, and that is the engine
|
|
244
|
-
* host only when the engine is native: on Docker Desktop, Rancher and `podman
|
|
245
|
-
* machine` the engine lives in a VM, so a socket Node created would sit on
|
|
246
|
-
* macOS/Windows while the devcontainer mounts one out of the VM. Node keeps the
|
|
247
|
-
* filter — the security boundary — and the gateway tunnels each connection to
|
|
248
|
-
* it over the control channel (gateway/src/control/socket-relay-protocol.ts).
|
|
249
|
-
*
|
|
250
|
-
* Nothing to create here, therefore: the directory is the gateway's bind mount,
|
|
251
|
-
* and the engine makes it on the engine side when it does not exist.
|
|
252
|
-
*/
|
|
253
|
-
function reportSocketDir() {
|
|
254
|
-
console.log((0, utils_1.dim)(`Socket directory: ${exports.HOST_SOCKET_DIR} (on the engine host, served by the gateway)`));
|
|
255
|
-
}
|
|
256
44
|
/**
|
|
257
45
|
* Pulls the devcontainer base images ahead of time. Best-effort: if an image is
|
|
258
46
|
* not (yet) available in the registry, we only warn — the gateway then builds it
|
|
@@ -264,7 +52,7 @@ function pullBaseImages(rt, images) {
|
|
|
264
52
|
for (const image of images) {
|
|
265
53
|
console.log((0, utils_1.dim)(` Pulling ${image}`));
|
|
266
54
|
try {
|
|
267
|
-
|
|
55
|
+
run(`${rt} pull ${image}`);
|
|
268
56
|
}
|
|
269
57
|
catch {
|
|
270
58
|
failed.push(image);
|
|
@@ -294,172 +82,96 @@ async function runInit(opts, images) {
|
|
|
294
82
|
}
|
|
295
83
|
else {
|
|
296
84
|
console.log((0, utils_1.dim)(`Pulling ${IMAGE}`));
|
|
297
|
-
|
|
85
|
+
run(`${rt} pull ${IMAGE}`);
|
|
298
86
|
pullBaseImages(rt, images.baseImages.map((b) => b.image));
|
|
299
87
|
}
|
|
88
|
+
console.log((0, utils_1.dim)(`Volume: ${VOLUME}`));
|
|
89
|
+
runSilent(`${rt} volume inspect ${VOLUME}`) || run(`${rt} volume create ${VOLUME}`);
|
|
300
90
|
console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
|
|
301
|
-
|
|
91
|
+
runSilent(`${rt} network inspect ${exports.INTERNAL_NET}`) || run(`${rt} network create --internal ${exports.INTERNAL_NET}`);
|
|
302
92
|
console.log((0, utils_1.dim)(`Removing old container if it exists`));
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
//
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
//
|
|
310
|
-
//
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
// resolved together (control-address.ts).
|
|
326
|
-
let control = (0, control_address_1.resolveControlAddress)({
|
|
327
|
-
isRemote: runtime.isRemote,
|
|
328
|
-
port: CONTROL_PORT,
|
|
329
|
-
gatewayIp: (0, control_address_1.bridgeGateway)(rt, runtime.defaultNetwork),
|
|
330
|
-
override: process.env.HUDDLE_NODE_CONTROL_URL,
|
|
331
|
-
bindOverride: process.env.HUDDLE_CONTROL_HOST,
|
|
332
|
-
});
|
|
333
|
-
console.log((0, utils_1.dim)('Starting Huddle Node (host)'));
|
|
334
|
-
// Deliberately NOT passed as environment: Huddle Node reads both folders from
|
|
335
|
-
// this same config file, per call. Handing them over at startup would freeze
|
|
336
|
-
// them for the lifetime of the process — and since startNodeDetached() reuses
|
|
337
|
-
// an already-running Node, even `huddle restart` would not always refresh it.
|
|
338
|
-
const extraEnv = { ...(0, images_1.baseImageEnv)(images), HUDDLE_RUNTIME: runtime.name };
|
|
339
|
-
let node;
|
|
340
|
-
try {
|
|
341
|
-
node = await (0, node_1.startNodeDetached)({
|
|
342
|
-
port: HOST_PORT,
|
|
343
|
-
controlHost: control.bindHost,
|
|
344
|
-
operatorToken,
|
|
345
|
-
extraEnv,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
catch (err) {
|
|
349
|
-
if (err instanceof node_1.MissingNodeEntryError) {
|
|
350
|
-
console.error((0, utils_1.red)('No Huddle Node build found — Huddle cannot start without one.'));
|
|
351
|
-
console.error('');
|
|
352
|
-
console.error(' In a repo checkout, build it first:');
|
|
353
|
-
console.error((0, utils_1.cyan)(' npm --prefix gateway install && npm --prefix gateway run build'));
|
|
354
|
-
console.error((0, utils_1.dim)(' Or point at an existing build with HUDDLE_NODE_ENTRY.'));
|
|
355
|
-
process.exit(1);
|
|
93
|
+
runSilent(`${rt} rm -f ${CONTAINER}`);
|
|
94
|
+
console.log((0, utils_1.dim)(`Socket directory: /tmp/dc-sockets`));
|
|
95
|
+
// The mount SOURCE must be the path on the Docker ENGINE host (on Windows:
|
|
96
|
+
// the WSL2/Linux VM), even when the CLI itself runs on Windows. The gateway
|
|
97
|
+
// (SOCKET_DIR in docker.ts) and every devcontainer socket mount rely on
|
|
98
|
+
// /tmp/dc-sockets on the engine host; mounting a Windows temp dir splits
|
|
99
|
+
// gateway and devcontainers across two filesystems, and Unix sockets are
|
|
100
|
+
// unreliable on such a drvfs/9p mount anyway.
|
|
101
|
+
const hostTmpSockets = exports.HOST_SOCKET_DIR;
|
|
102
|
+
if (runtime.isRemote) {
|
|
103
|
+
if (runtime.name === 'podman') {
|
|
104
|
+
// Podman does NOT create a missing bind source itself (unlike Docker
|
|
105
|
+
// Desktop) and fails with "statfs: no such file or directory". So create
|
|
106
|
+
// the directory explicitly in the machine VM; the socket lives there too.
|
|
107
|
+
console.log((0, utils_1.dim)(` (Podman: creating ${hostTmpSockets} in the machine VM)`));
|
|
108
|
+
if (!runSilent(`podman machine ssh "mkdir -p ${hostTmpSockets}"`)) {
|
|
109
|
+
console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets} in the Podman VM.`));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Docker Desktop creates a missing bind source itself in the VM on `run`.
|
|
114
|
+
console.log((0, utils_1.dim)(` (${runtime.name}: the engine creates ${hostTmpSockets} in the VM)`));
|
|
356
115
|
}
|
|
357
|
-
throw err;
|
|
358
116
|
}
|
|
359
|
-
|
|
360
|
-
? ` already running on ${(0, node_1.nodeUrl)(node.port)}`
|
|
361
|
-
: ` pid ${node.pid}, log ${node_1.NODE_LOG_FILE}`));
|
|
362
|
-
console.log((0, utils_1.dim)(` control channel: ${control.bindHost}:${CONTROL_PORT} — ${control.reason}`));
|
|
363
|
-
// Both halves are up; now prove they can see each other, before the gateway is
|
|
364
|
-
// handed an address it may never reach.
|
|
365
|
-
control = await verifyControlChannel(rt, IMAGE, runtime.defaultNetwork, control, async (bindHost) => {
|
|
366
|
-
// startNodeDetached() now recognizes a running Node bound to a different
|
|
367
|
-
// control host than requested and stops-and-restarts it on its own
|
|
368
|
-
// (cli/src/node.ts) — so naming the new host here is enough.
|
|
117
|
+
else {
|
|
369
118
|
try {
|
|
370
|
-
|
|
371
|
-
return true;
|
|
119
|
+
fs_1.default.mkdirSync(hostTmpSockets, { recursive: true });
|
|
372
120
|
}
|
|
373
|
-
catch {
|
|
374
|
-
|
|
375
|
-
// rollback. Throwing here would abort init with Huddle Node already down.
|
|
376
|
-
return false;
|
|
121
|
+
catch (err) {
|
|
122
|
+
console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets}: ${err}`));
|
|
377
123
|
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
//
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
//
|
|
386
|
-
//
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
//
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
dockerArgs.push('-v', `${exports.HOST_SOCKET_DIR}:${exports.HOST_SOCKET_DIR}`);
|
|
415
|
-
dockerArgs.push(IMAGE);
|
|
416
|
-
runArgs(rt, dockerArgs);
|
|
124
|
+
}
|
|
125
|
+
console.log((0, utils_1.dim)(`Starting container`));
|
|
126
|
+
// The gateway is engine-agnostic (talks the Docker-compatible API on the
|
|
127
|
+
// mounted socket), but does need to know it's Podman: it then sets
|
|
128
|
+
// `--security-opt label=disable` on every devcontainer so it can reach the
|
|
129
|
+
// SELinux-labeled proxy socket.
|
|
130
|
+
const securityOptFlags = runtime.securityOpts.map((opt) => ` --security-opt ${opt}`).join('');
|
|
131
|
+
// Operator token for control-plane auth. Reuse the token from the config (so an
|
|
132
|
+
// existing browser session/CLI keeps working across re-inits), otherwise
|
|
133
|
+
// generate one. We pass it to the gateway via env AND store it locally so that
|
|
134
|
+
// subsequent `huddle` commands can authenticate.
|
|
135
|
+
const cfg = (0, config_1.readConfig)();
|
|
136
|
+
const operatorToken = process.env.HUDDLE_OPERATOR_TOKEN?.trim() ||
|
|
137
|
+
(cfg.operatorToken && cfg.operatorToken.trim()) ||
|
|
138
|
+
crypto_1.default.randomBytes(32).toString('base64url');
|
|
139
|
+
if (cfg.operatorToken !== operatorToken) {
|
|
140
|
+
(0, config_1.writeConfig)({ ...cfg, operatorToken });
|
|
141
|
+
}
|
|
142
|
+
// The container is created on the engine's default network first (with -p),
|
|
143
|
+
// then joins devcontainer-net (--internal) afterwards: Docker skips the host
|
|
144
|
+
// port-forward entirely when a container is created directly on an --internal
|
|
145
|
+
// network (moby/moby#36174). Which source IP the gateway sees for forwarded
|
|
146
|
+
// traffic no longer matters — the control plane authenticates with the
|
|
147
|
+
// operator token instead of source-IP filtering.
|
|
148
|
+
run(`${rt} run -d` +
|
|
149
|
+
` --name ${CONTAINER}` +
|
|
150
|
+
` --network ${runtime.defaultNetwork}` +
|
|
151
|
+
securityOptFlags +
|
|
152
|
+
` -e HUDDLE_RUNTIME=${runtime.name}` +
|
|
153
|
+
` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
|
|
154
|
+
` -p ${HOST_PORT}:3000` +
|
|
155
|
+
` -v ${VOLUME}:/data` +
|
|
156
|
+
` -v "${runtime.socketPath}:/var/run/docker.sock"` +
|
|
157
|
+
` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
|
|
158
|
+
(0, images_1.gatewayEnvFlags)(images) +
|
|
159
|
+
` ${IMAGE}`);
|
|
417
160
|
// Attaching devcontainer-net after the container has started pollutes
|
|
418
161
|
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
419
|
-
// gateway cleans that up itself (see dns-egress.ts /
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
console.log();
|
|
423
|
-
console.log((0, utils_1.green)(`[OK] Huddle is running at ${(0, node_1.nodeUrl)(HOST_PORT)}`));
|
|
162
|
+
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
163
|
+
// index.ts).
|
|
164
|
+
runSilent(`${rt} network connect ${exports.INTERNAL_NET} ${CONTAINER}`);
|
|
424
165
|
console.log();
|
|
425
|
-
|
|
426
|
-
// host — there is nothing to start here. What still has to happen at init time
|
|
427
|
-
// is the host trust store, and only when sbx is actually installed. Best-effort;
|
|
428
|
-
// never fails the init.
|
|
429
|
-
try {
|
|
430
|
-
const { resolveSbxBin } = await Promise.resolve().then(() => __importStar(require('./sbx-host')));
|
|
431
|
-
const bin = resolveSbxBin();
|
|
432
|
-
const sbxPresent = (() => { try {
|
|
433
|
-
(0, child_process_1.execFileSync)(bin, ['version'], { stdio: 'ignore', timeout: 15000 });
|
|
434
|
-
return true;
|
|
435
|
-
}
|
|
436
|
-
catch {
|
|
437
|
-
return false;
|
|
438
|
-
} })();
|
|
439
|
-
if (sbxPresent) {
|
|
440
|
-
// Huddle's CA has to be trusted on the HOST too, not just inside each
|
|
441
|
-
// sandbox: sbx terminates TLS itself for some hosts (measured on
|
|
442
|
-
// platform.claude.com) and then validates Huddle's leaf against the host
|
|
443
|
-
// trust store. Without this the sandbox gets "Empty reply from server"
|
|
444
|
-
// and `claude` fails with ECONNRESET. See cli/src/sbx-host-ca.ts.
|
|
445
|
-
const { installHostCa, printHostCaResult } = await Promise.resolve().then(() => __importStar(require('./sbx-host-ca')));
|
|
446
|
-
printHostCaResult(installHostCa());
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
console.log((0, utils_1.dim)(' (sbx not found on PATH — install Docker Sandboxes to use sbx boxes)'));
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
catch (err) {
|
|
453
|
-
console.log((0, utils_1.dim)(` (could not prepare sbx on the host: ${err.message})`));
|
|
454
|
-
}
|
|
166
|
+
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
455
167
|
console.log();
|
|
456
168
|
// Full auto-login link: open it and the portal logs you in automatically with
|
|
457
169
|
// the operator token (the frontend reads ?token=..., logs in and then removes it
|
|
458
170
|
// from the address bar). This way you don't have to paste anything.
|
|
459
|
-
const loginUrl =
|
|
171
|
+
const loginUrl = `http://localhost:${HOST_PORT}/?token=${encodeURIComponent(operatorToken)}`;
|
|
460
172
|
console.log((0, utils_1.bold)('Open the portal (auto-login link):'));
|
|
461
173
|
console.log((0, utils_1.green)(` ${loginUrl}`));
|
|
462
174
|
console.log((0, utils_1.dim)(' Opens the portal and logs you in automatically.'));
|
|
463
|
-
console.log((0, utils_1.dim)(` Manual token (if you prefer to paste it): ${
|
|
175
|
+
console.log((0, utils_1.dim)(` Manual token (if you prefer to paste it): ${operatorToken}`));
|
|
464
176
|
console.log((0, utils_1.dim)(' The token is also saved to ~/.huddle/config.json for the CLI.'));
|
|
465
177
|
}
|