@infosupport/huddle-cli 0.0.0-experiment-109.58.1 → 0.0.0-experiment-98.60.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 +32 -37
- package/dist/api.js +14 -52
- package/dist/experiment.js +0 -6
- package/dist/firewall.js +26 -10
- package/dist/images.js +9 -13
- package/dist/index.js +45 -136
- package/dist/indexfolder.js +167 -0
- package/dist/init.js +89 -354
- package/dist/migrate.js +17 -53
- 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 -593
- 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 = [];
|
|
@@ -607,8 +588,7 @@ async function runMigrate(opts) {
|
|
|
607
588
|
catch (err) {
|
|
608
589
|
throw new Error(`Could not parse ${composeFile}: ${err instanceof Error ? err.message : String(err)}`);
|
|
609
590
|
}
|
|
610
|
-
const
|
|
611
|
-
const result = buildOverride(compose, { caPath, hostCaPath, dockerSocket: opts.dockerSocket });
|
|
591
|
+
const result = buildOverride(compose, { caPath, dockerSocket: opts.dockerSocket });
|
|
612
592
|
console.log(`Marked network: ${(0, utils_1.bold)(result.markedNetwork)}`);
|
|
613
593
|
console.log(`Wired services: ${result.services.length ? result.services.map(utils_1.bold).join(', ') : (0, utils_1.dim)('(none)')}`);
|
|
614
594
|
for (const w of result.warnings)
|
|
@@ -640,32 +620,9 @@ async function runMigrate(opts) {
|
|
|
640
620
|
console.log((0, utils_1.yellow)(`[!] Could not confirm the "${init_1.INTERNAL_NET}" network exists. Run \`huddle init\` first.`));
|
|
641
621
|
console.log();
|
|
642
622
|
}
|
|
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);
|
|
623
|
+
printNextSteps(composeFile, outPath, caPath, !!opts.dockerSocket);
|
|
667
624
|
}
|
|
668
|
-
function printNextSteps(composeFile, outPath, caPath,
|
|
625
|
+
function printNextSteps(composeFile, outPath, caPath, dockerSocket) {
|
|
669
626
|
const composeBase = path_1.default.basename(composeFile);
|
|
670
627
|
const overrideBase = path_1.default.basename(outPath);
|
|
671
628
|
console.log((0, utils_1.bold)('Next steps (this command only GENERATED the override — it did not start anything):'));
|
|
@@ -673,8 +630,8 @@ function printNextSteps(composeFile, outPath, caPath, hostCaPath) {
|
|
|
673
630
|
console.log(' 1. Make sure Huddle is running:');
|
|
674
631
|
console.log((0, utils_1.cyan)(' huddle init'));
|
|
675
632
|
console.log();
|
|
676
|
-
console.log(' 2.
|
|
677
|
-
console.log((0, utils_1.cyan)(` ${
|
|
633
|
+
console.log(' 2. Fetch the Huddle CA inside the container. Add to your devcontainer.json:');
|
|
634
|
+
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
635
|
console.log((0, utils_1.dim)(` (Adjust ${caPath} to your remoteUser's home if it differs; pass --ca-path to change it.)`));
|
|
679
636
|
console.log();
|
|
680
637
|
console.log(' 3. Reference the override so the IDE merges it. In devcontainer.json:');
|
|
@@ -682,5 +639,12 @@ function printNextSteps(composeFile, outPath, caPath, hostCaPath) {
|
|
|
682
639
|
console.log((0, utils_1.dim)(' Or start it yourself:'));
|
|
683
640
|
console.log((0, utils_1.cyan)(` docker compose -f ${composeBase} -f ${overrideBase} up -d`));
|
|
684
641
|
console.log();
|
|
642
|
+
if (dockerSocket) {
|
|
643
|
+
console.log((0, utils_1.yellow)(' Note (--docker-socket): the socket mount is GENERATED but NOT yet served.'));
|
|
644
|
+
console.log((0, utils_1.dim)(' Huddle does not yet pre-provision the per-container filtered socket for IDE-started\n' +
|
|
645
|
+
' containers (issue #66 follow-up). Until it does, the mount source will not exist and\n' +
|
|
646
|
+
' DOCKER_HOST will point at a missing socket. Only enable this once that lands.'));
|
|
647
|
+
console.log();
|
|
648
|
+
}
|
|
685
649
|
console.log((0, utils_1.dim)('See docs/migrate-devcontainers.md for the full guide and the marked-network convention.'));
|
|
686
650
|
}
|
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-98.60.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": "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
|
-
},
|
|
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
|
-
}
|
package/dist/control-probe.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Does the gateway container ACTUALLY reach Huddle Node?
|
|
3
|
-
//
|
|
4
|
-
// control-address.ts derives an answer from what the engine says it is. That
|
|
5
|
-
// derivation has one assumption in it — "engine in a VM ⇒ the host is reachable
|
|
6
|
-
// on its loopback via host.docker.internal" — and it is false on Rancher
|
|
7
|
-
// Desktop for Windows: the engine runs in a WSL distro, `host.docker.internal`
|
|
8
|
-
// resolves to that distro's docker0 gateway (172.17.0.1), and Huddle Node is a
|
|
9
|
-
// Windows process bound to the Windows loopback. The name resolves, nothing
|
|
10
|
-
// listens, and the gateway fails closed: every devcontainer is denied all egress
|
|
11
|
-
// and nothing is filed as `requested`, because a gateway with no policy is not
|
|
12
|
-
// allowed to invent one.
|
|
13
|
-
//
|
|
14
|
-
// A derivation cannot tell that apart from a working setup. A connection can.
|
|
15
|
-
// So init stops guessing: it starts Node, then opens the real connection from a
|
|
16
|
-
// throwaway container, and only trusts an address that answered.
|
|
17
|
-
//
|
|
18
|
-
// Split from control-address.ts because everything here SPAWNS — the pure
|
|
19
|
-
// decision stays testable without an engine, and the parsers below are exported
|
|
20
|
-
// for the same reason.
|
|
21
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.parseProbeOutput = parseProbeOutput;
|
|
26
|
-
exports.probeControlUrl = probeControlUrl;
|
|
27
|
-
exports.parseDefaultGateway = parseDefaultGateway;
|
|
28
|
-
exports.engineHostAddress = engineHostAddress;
|
|
29
|
-
exports.hostCandidateUrls = hostCandidateUrls;
|
|
30
|
-
exports.localIpv4Addresses = localIpv4Addresses;
|
|
31
|
-
exports.pickBindAddress = pickBindAddress;
|
|
32
|
-
const child_process_1 = require("child_process");
|
|
33
|
-
const os_1 = __importDefault(require("os"));
|
|
34
|
-
/** How long any single engine call may take before we call it a failure. */
|
|
35
|
-
const PROBE_TIMEOUT_MS = 25_000;
|
|
36
|
-
/**
|
|
37
|
-
* Run the probe inside the gateway image itself.
|
|
38
|
-
*
|
|
39
|
-
* That image, not a stock one: it is already present (init just pulled or built
|
|
40
|
-
* it), so this costs no download, and it is the exact runtime the real gateway
|
|
41
|
-
* uses — same Node, same DNS resolution, same TLS stack.
|
|
42
|
-
*/
|
|
43
|
-
function runInImage(rt, image, runArgs, entrypoint, cmdArgs = []) {
|
|
44
|
-
try {
|
|
45
|
-
return (0, child_process_1.execFileSync)(rt, ['run', '--rm', '--entrypoint', entrypoint, ...runArgs, image, ...cmdArgs], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: PROBE_TIMEOUT_MS });
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// The script the probe container runs. One line, because it travels as an argv
|
|
52
|
-
// entry through a shell on Windows. A 4s timeout of its own: an address that is
|
|
53
|
-
// silently dropped (a host firewall) must come back as a result, not as a hang.
|
|
54
|
-
const PROBE_SCRIPT = "fetch(process.env.PROBE_URL + '/control/health', { signal: AbortSignal.timeout(4000) })" +
|
|
55
|
-
".then(r => console.log('PROBE_HTTP ' + r.status))" +
|
|
56
|
-
".catch(e => console.log('PROBE_ERR ' + ((e.cause && e.cause.code) || e.name || e.message)))";
|
|
57
|
-
/**
|
|
58
|
-
* Read the probe container's single line of output.
|
|
59
|
-
*
|
|
60
|
-
* ANY HTTP status means reachable, and 401 is the expected one: /control/health
|
|
61
|
-
* is behind the gateway token and the probe deliberately sends none. What is
|
|
62
|
-
* being tested is whether the packets arrive, not whether we are authorised —
|
|
63
|
-
* the token is checked separately, and conflating the two is how "unreachable"
|
|
64
|
-
* ends up hiding a token mismatch.
|
|
65
|
-
*/
|
|
66
|
-
function parseProbeOutput(out) {
|
|
67
|
-
if (out === null)
|
|
68
|
-
return { reachable: false, detail: 'the probe container could not be started' };
|
|
69
|
-
const line = out.split('\n').map((l) => l.trim()).filter(Boolean).pop() ?? '';
|
|
70
|
-
const http = /^PROBE_HTTP (\d+)$/.exec(line);
|
|
71
|
-
if (http)
|
|
72
|
-
return { reachable: true, detail: `HTTP ${http[1]}` };
|
|
73
|
-
const err = /^PROBE_ERR (.+)$/.exec(line);
|
|
74
|
-
if (err)
|
|
75
|
-
return { reachable: false, detail: err[1] };
|
|
76
|
-
return { reachable: false, detail: line || 'no output' };
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Open the control channel from where the gateway will open it: same image,
|
|
80
|
-
* same network, same --add-host arguments. Anything less tests a different path
|
|
81
|
-
* than the one that has to work.
|
|
82
|
-
*/
|
|
83
|
-
function probeControlUrl(rt, image, url, network, runArgs) {
|
|
84
|
-
const out = runInImage(rt, image, ['--network', network, ...runArgs, '-e', `PROBE_URL=${url}`], 'node', ['-e', PROBE_SCRIPT]);
|
|
85
|
-
return parseProbeOutput(out);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Pull the gateway out of `ip route show default`.
|
|
89
|
-
*
|
|
90
|
-
* Two shapes, since busybox and iproute2 order the fields differently:
|
|
91
|
-
* default via 172.20.144.1 dev eth0 proto kernel
|
|
92
|
-
* default dev eth0 scope link src 10.0.0.5 via 10.0.0.1
|
|
93
|
-
* so match on `via <ip>` wherever it sits rather than on a field position.
|
|
94
|
-
*/
|
|
95
|
-
function parseDefaultGateway(routeOutput) {
|
|
96
|
-
if (!routeOutput)
|
|
97
|
-
return null;
|
|
98
|
-
for (const line of routeOutput.split('\n')) {
|
|
99
|
-
if (!line.trim().startsWith('default'))
|
|
100
|
-
continue;
|
|
101
|
-
const via = /\bvia\s+(\d{1,3}(?:\.\d{1,3}){3})\b/.exec(line);
|
|
102
|
-
if (via && via[1].split('.').every((o) => Number(o) <= 255))
|
|
103
|
-
return via[1];
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The address of the machine the ENGINE runs on, seen from inside the engine.
|
|
109
|
-
*
|
|
110
|
-
* `--network host` puts the probe in the engine host's own network namespace —
|
|
111
|
-
* the WSL distro on Rancher Desktop, the Linux VM elsewhere — so its default
|
|
112
|
-
* route names the next hop out of that namespace. On WSL that next hop is the
|
|
113
|
-
* Windows host, on the vEthernet adapter the two share, which is exactly the
|
|
114
|
-
* address a container can reach and `host.docker.internal` failed to name.
|
|
115
|
-
*
|
|
116
|
-
* Only worth asking when the derived address did not answer: on Docker Desktop
|
|
117
|
-
* this returns the VM's own internal gateway, which is not what anyone wants.
|
|
118
|
-
*/
|
|
119
|
-
function engineHostAddress(rt, image) {
|
|
120
|
-
return parseDefaultGateway(runInImage(rt, image, ['--network', 'host'], 'ip', ['-4', 'route', 'show', 'default']));
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* The other names and addresses a container might reach this machine on, tried
|
|
124
|
-
* only when the derived one did not answer.
|
|
125
|
-
*
|
|
126
|
-
* `host.docker.internal` is not a promise. Rancher Desktop points it at the
|
|
127
|
-
* WSL distro's own docker0 gateway, which is the distro, not this machine —
|
|
128
|
-
* measured, and it is what sent us here. So try the aliases other engines
|
|
129
|
-
* publish, and then the one address that is not a guess at all:
|
|
130
|
-
*
|
|
131
|
-
* Rancher Desktop and `podman machine` both route the VM through
|
|
132
|
-
* gvisor-tap-vsock, which serves 192.168.127.0/24 with the gateway on .1 and
|
|
133
|
-
* THIS MACHINE on .254 — a userspace forwarder running here, so it reaches the
|
|
134
|
-
* host loopback exactly like Docker Desktop's alias does. Derived from whatever
|
|
135
|
-
* gateway the engine reported rather than hardcoded, because the subnet is
|
|
136
|
-
* configurable.
|
|
137
|
-
*
|
|
138
|
-
* Every one of these is a candidate, not an answer: each is probed, and only an
|
|
139
|
-
* address that replies is used.
|
|
140
|
-
*/
|
|
141
|
-
function hostCandidateUrls(port, vmGateway) {
|
|
142
|
-
const hosts = ['host.rancher-desktop.internal', 'host.containers.internal'];
|
|
143
|
-
const octets = vmGateway ? /^(\d{1,3}\.\d{1,3}\.\d{1,3})\.\d{1,3}$/.exec(vmGateway) : null;
|
|
144
|
-
if (octets)
|
|
145
|
-
hosts.push(`${octets[1]}.254`);
|
|
146
|
-
return hosts.map((h) => `http://${h}:${port}`);
|
|
147
|
-
}
|
|
148
|
-
/** Every IPv4 address this machine actually has, loopback excluded. */
|
|
149
|
-
function localIpv4Addresses() {
|
|
150
|
-
const out = [];
|
|
151
|
-
for (const addrs of Object.values(os_1.default.networkInterfaces())) {
|
|
152
|
-
for (const a of addrs ?? []) {
|
|
153
|
-
if (a.family === 'IPv4' && !a.internal)
|
|
154
|
-
out.push(a.address);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return out;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* An address Huddle Node can BIND that the engine can also reach.
|
|
161
|
-
*
|
|
162
|
-
* Both halves matter, and the second one is the trap: the engine's default
|
|
163
|
-
* gateway is not this machine. On Rancher Desktop it is 192.168.127.1, served by
|
|
164
|
-
* a forwarder — binding it fails with EADDRNOTAVAIL and takes Huddle Node down
|
|
165
|
-
* with it, which is exactly how a control-channel fix turned into no Huddle at
|
|
166
|
-
* all. So only ever offer an address this machine really owns, on the same
|
|
167
|
-
* subnet the engine routes through.
|
|
168
|
-
*/
|
|
169
|
-
function pickBindAddress(local, vmGateway) {
|
|
170
|
-
if (!vmGateway)
|
|
171
|
-
return null;
|
|
172
|
-
const prefix = vmGateway.replace(/\.\d+$/, '.');
|
|
173
|
-
return local.find((a) => a.startsWith(prefix)) ?? null;
|
|
174
|
-
}
|