@infosupport/huddle-cli 0.0.0-experiment-66.39.1 → 0.0.0-experiment-66.40.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/dist/firewall.js +5 -1
- package/dist/init.js +1 -1
- package/dist/migrate.js +47 -17
- package/dist/runtime.js +7 -6
- package/package.json +1 -1
package/dist/firewall.js
CHANGED
|
@@ -109,7 +109,11 @@ async function runFirewallDelete(opts) {
|
|
|
109
109
|
qs.set('container', opts.container);
|
|
110
110
|
const query = qs.toString();
|
|
111
111
|
const rules = await (0, api_1.get)(`/api/rules${query ? `?${query}` : ''}`);
|
|
112
|
-
|
|
112
|
+
// Hostnames are case-insensitive everywhere else in the firewall stack, so
|
|
113
|
+
// match the domain case-insensitively — a rule stored as `GitHub.com` must be
|
|
114
|
+
// deletable by typing `github.com`.
|
|
115
|
+
const needle = target.toLowerCase();
|
|
116
|
+
const matches = rules.filter((r) => r.domain.toLowerCase() === needle);
|
|
113
117
|
if (matches.length === 0) {
|
|
114
118
|
const scope = opts.container ? ` for container ${opts.container}` : '';
|
|
115
119
|
throw new Error(`No firewall rule found for "${target}"${scope}.`);
|
package/dist/init.js
CHANGED
|
@@ -166,7 +166,7 @@ async function runInit(opts, images) {
|
|
|
166
166
|
` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
|
|
167
167
|
` -p ${HOST_PORT}:3000` +
|
|
168
168
|
` -v ${VOLUME}:/data` +
|
|
169
|
-
` -v ${runtime.socketPath}:/var/run/docker.sock` +
|
|
169
|
+
` -v "${runtime.socketPath}:/var/run/docker.sock"` +
|
|
170
170
|
` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
|
|
171
171
|
homeMountFlag +
|
|
172
172
|
fwMountFlag +
|
package/dist/migrate.js
CHANGED
|
@@ -123,6 +123,7 @@ function buildOverride(compose, opts = {}) {
|
|
|
123
123
|
const internalNet = opts.internalNet ?? init_1.INTERNAL_NET;
|
|
124
124
|
const socketDir = opts.socketDir ?? init_1.HOST_SOCKET_DIR;
|
|
125
125
|
const warnings = [];
|
|
126
|
+
const blockers = [];
|
|
126
127
|
const marked = findMarkedNetworks(compose);
|
|
127
128
|
if (marked.length === 0) {
|
|
128
129
|
throw new Error(`No network marked with \`${exports.HUDDLE_NETWORK_LABEL}: "true"\` was found. ` +
|
|
@@ -132,17 +133,25 @@ function buildOverride(compose, opts = {}) {
|
|
|
132
133
|
throw new Error(`Multiple networks marked with \`${exports.HUDDLE_NETWORK_LABEL}\`: ${marked.join(', ')}. Mark exactly one.`);
|
|
133
134
|
}
|
|
134
135
|
const markedNetwork = marked[0];
|
|
135
|
-
// Pick a
|
|
136
|
-
|
|
136
|
+
// Pick a key for the injected egress network that collides with NOTHING: not
|
|
137
|
+
// an existing network, and not the marked network itself (otherwise the two
|
|
138
|
+
// keys in the service's `networks` map below collapse into one and the egress
|
|
139
|
+
// net is silently never added). Keep suffixing until it is unique.
|
|
140
|
+
const taken = new Set(Object.keys(compose.networks ?? {}));
|
|
141
|
+
taken.add(markedNetwork);
|
|
137
142
|
let huddleNetKey = opts.huddleNetKey ?? exports.HUDDLE_NET_KEY;
|
|
138
|
-
if (
|
|
139
|
-
|
|
143
|
+
if (taken.has(huddleNetKey)) {
|
|
144
|
+
let n = 0;
|
|
145
|
+
do {
|
|
146
|
+
huddleNetKey = n === 0 ? `${exports.HUDDLE_NET_KEY}-egress` : `${exports.HUDDLE_NET_KEY}-egress-${n}`;
|
|
147
|
+
n++;
|
|
148
|
+
} while (taken.has(huddleNetKey));
|
|
140
149
|
}
|
|
141
150
|
// Guardrail: the marked network must be internal, otherwise it already has a
|
|
142
151
|
// route to the internet and would bypass the firewall/proxy.
|
|
143
152
|
const markedDef = (compose.networks?.[markedNetwork] ?? {});
|
|
144
153
|
if (!isTruthy(markedDef.internal)) {
|
|
145
|
-
|
|
154
|
+
blockers.push(`Network "${markedNetwork}" is not marked \`internal: true\`. It must be internal, ` +
|
|
146
155
|
'otherwise services can reach the internet directly and bypass Huddle.');
|
|
147
156
|
}
|
|
148
157
|
const services = Object.entries(compose.services ?? {})
|
|
@@ -161,7 +170,7 @@ function buildOverride(compose, opts = {}) {
|
|
|
161
170
|
continue;
|
|
162
171
|
const def = (compose.networks?.[netKey] ?? {});
|
|
163
172
|
if (!isTruthy(def.internal)) {
|
|
164
|
-
|
|
173
|
+
blockers.push(`Service "${name}" is also on network "${netKey}", which is not internal. ` +
|
|
165
174
|
'Remove it or make it internal — a second non-internal network bypasses Huddle.');
|
|
166
175
|
}
|
|
167
176
|
}
|
|
@@ -191,7 +200,7 @@ function buildOverride(compose, opts = {}) {
|
|
|
191
200
|
[huddleNetKey]: { external: true, name: internalNet },
|
|
192
201
|
},
|
|
193
202
|
};
|
|
194
|
-
return { markedNetwork, services, override, warnings };
|
|
203
|
+
return { markedNetwork, services, override, warnings, blockers };
|
|
195
204
|
}
|
|
196
205
|
function tokenize(input) {
|
|
197
206
|
const out = [];
|
|
@@ -253,9 +262,14 @@ function rejectUnsupportedYaml(lines) {
|
|
|
253
262
|
const value = lineValue(text);
|
|
254
263
|
if (BLOCK_SCALAR_HEADER.test(value))
|
|
255
264
|
throw unsupportedYaml('a block scalar (`|` or `>`)');
|
|
256
|
-
|
|
265
|
+
// Match an anchor/alias in any NODE position: at the value start OR right
|
|
266
|
+
// after a flow opener/separator (`[`, `{`, `,`) or a flow-map colon — so
|
|
267
|
+
// `networks: [*net]` and `{n: *net}` are caught too, not just `x: *net`.
|
|
268
|
+
// The trailing name char keeps this off scalar `&`/`*` (env URLs, globs like
|
|
269
|
+
// `*.log`), which never start an anchor/alias name.
|
|
270
|
+
if (/(^|[[{,:]\s*)&[A-Za-z0-9_]/.test(value))
|
|
257
271
|
throw unsupportedYaml('a YAML anchor (`&`)');
|
|
258
|
-
if (
|
|
272
|
+
if (/(^|[[{,:]\s*)\*[A-Za-z0-9_]/.test(value))
|
|
259
273
|
throw unsupportedYaml('a YAML alias (`*`)');
|
|
260
274
|
}
|
|
261
275
|
}
|
|
@@ -263,12 +277,18 @@ function parseYaml(input) {
|
|
|
263
277
|
const lines = tokenize(input);
|
|
264
278
|
rejectUnsupportedYaml(lines);
|
|
265
279
|
let pos = 0;
|
|
266
|
-
|
|
280
|
+
// Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
|
|
281
|
+
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
282
|
+
const MAX_DEPTH = 64;
|
|
283
|
+
function parseNode(indent, depth) {
|
|
284
|
+
if (depth > MAX_DEPTH) {
|
|
285
|
+
throw new Error(`YAML nesting exceeds ${MAX_DEPTH} levels; refusing to parse this compose file.`);
|
|
286
|
+
}
|
|
267
287
|
if (pos >= lines.length || lines[pos].indent < indent)
|
|
268
288
|
return null;
|
|
269
|
-
return isSeqItem(lines[pos].text) ? parseSequence(indent) : parseMapping(indent);
|
|
289
|
+
return isSeqItem(lines[pos].text) ? parseSequence(indent, depth) : parseMapping(indent, depth);
|
|
270
290
|
}
|
|
271
|
-
function parseMapping(indent) {
|
|
291
|
+
function parseMapping(indent, depth) {
|
|
272
292
|
const map = {};
|
|
273
293
|
while (pos < lines.length && lines[pos].indent === indent && !isSeqItem(lines[pos].text)) {
|
|
274
294
|
const { text } = lines[pos];
|
|
@@ -284,7 +304,7 @@ function parseYaml(input) {
|
|
|
284
304
|
map[key] = parseScalar(rest);
|
|
285
305
|
}
|
|
286
306
|
else if (pos < lines.length && lines[pos].indent > indent) {
|
|
287
|
-
map[key] = parseNode(lines[pos].indent);
|
|
307
|
+
map[key] = parseNode(lines[pos].indent, depth + 1);
|
|
288
308
|
}
|
|
289
309
|
else {
|
|
290
310
|
map[key] = null;
|
|
@@ -292,20 +312,20 @@ function parseYaml(input) {
|
|
|
292
312
|
}
|
|
293
313
|
return map;
|
|
294
314
|
}
|
|
295
|
-
function parseSequence(indent) {
|
|
315
|
+
function parseSequence(indent, depth) {
|
|
296
316
|
const arr = [];
|
|
297
317
|
while (pos < lines.length && lines[pos].indent === indent && isSeqItem(lines[pos].text)) {
|
|
298
318
|
const afterDash = lines[pos].text.replace(/^-\s*/, '');
|
|
299
319
|
if (afterDash === '') {
|
|
300
320
|
pos++;
|
|
301
|
-
arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent) : null);
|
|
321
|
+
arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent, depth + 1) : null);
|
|
302
322
|
}
|
|
303
323
|
else if (findKeyColon(afterDash) >= 0) {
|
|
304
324
|
// Inline map item: "- key: value". Re-interpret the remainder as a
|
|
305
325
|
// mapping that starts at a virtual indent past the dash.
|
|
306
326
|
const virtualIndent = indent + (lines[pos].text.length - afterDash.length);
|
|
307
327
|
lines[pos] = { indent: virtualIndent, text: afterDash };
|
|
308
|
-
arr.push(parseMapping(virtualIndent));
|
|
328
|
+
arr.push(parseMapping(virtualIndent, depth + 1));
|
|
309
329
|
}
|
|
310
330
|
else {
|
|
311
331
|
arr.push(parseScalar(afterDash));
|
|
@@ -314,7 +334,7 @@ function parseYaml(input) {
|
|
|
314
334
|
}
|
|
315
335
|
return arr;
|
|
316
336
|
}
|
|
317
|
-
const root = parseNode(lines.length ? lines[0].indent : 0);
|
|
337
|
+
const root = parseNode(lines.length ? lines[0].indent : 0, 0);
|
|
318
338
|
return (root && typeof root === 'object' ? root : {});
|
|
319
339
|
}
|
|
320
340
|
function isSeqItem(text) {
|
|
@@ -535,7 +555,17 @@ async function runMigrate(opts) {
|
|
|
535
555
|
console.log(`Wired services: ${result.services.length ? result.services.map(utils_1.bold).join(', ') : (0, utils_1.dim)('(none)')}`);
|
|
536
556
|
for (const w of result.warnings)
|
|
537
557
|
console.log((0, utils_1.yellow)(`[!] ${w}`));
|
|
558
|
+
for (const b of result.blockers)
|
|
559
|
+
console.log((0, utils_1.red)(`[x] ${b}`));
|
|
538
560
|
console.log();
|
|
561
|
+
// Fail closed: these blockers mean the migrated service would keep a direct
|
|
562
|
+
// route to the internet, so writing the override and reporting success would
|
|
563
|
+
// be misleading. Refuse unless the operator explicitly overrides with --force.
|
|
564
|
+
if (result.blockers.length > 0 && !opts.force) {
|
|
565
|
+
throw new Error(`Refusing to write the override: the migration would leave a direct internet path ` +
|
|
566
|
+
`(${result.blockers.length} blocker(s) above). Fix your compose file, or re-run with ` +
|
|
567
|
+
`--force to generate it anyway.`);
|
|
568
|
+
}
|
|
539
569
|
const overrideText = '# Generated by `huddle migrate` — do NOT edit by hand; re-run the command instead.\n' +
|
|
540
570
|
'# Merge this on top of your docker-compose.yml so the marked services reach the\n' +
|
|
541
571
|
'# internet only through the Huddle proxy. Your own compose file stays untouched.\n' +
|
package/dist/runtime.js
CHANGED
|
@@ -72,13 +72,14 @@ function parseDockerContextSocket(json) {
|
|
|
72
72
|
const path = host.slice('unix://'.length);
|
|
73
73
|
if (!path.startsWith('/'))
|
|
74
74
|
return null;
|
|
75
|
-
// The returned path is
|
|
76
|
-
//
|
|
75
|
+
// The returned path is interpolated into a `docker run -v "<path>:..."` shell
|
|
76
|
+
// command (init.ts), where it is DOUBLE-QUOTED. The `Host` from `docker context
|
|
77
77
|
// inspect` is attacker-influenceable (whoever can create/activate a docker
|
|
78
|
-
// context controls the value), so
|
|
79
|
-
// socket path
|
|
80
|
-
//
|
|
81
|
-
|
|
78
|
+
// context controls the value), so restrict it to characters that occur in a real
|
|
79
|
+
// socket path: allow spaces (legal in e.g. macOS `/Users/First Last/.rd/...`)
|
|
80
|
+
// but never the metacharacters that stay dangerous inside double quotes
|
|
81
|
+
// ($, backtick, ", \) or the command separators (;, |, &, (), newline).
|
|
82
|
+
if (!/^[A-Za-z0-9._/ -]+$/.test(path))
|
|
82
83
|
return null;
|
|
83
84
|
return path;
|
|
84
85
|
}
|
package/package.json
CHANGED