@infosupport/huddle-cli 0.0.0-experiment-66.40.1 → 0.0.0-experiment-97.41.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/config.js CHANGED
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CONFIG_DIR = void 0;
7
6
  exports.configPath = configPath;
8
7
  exports.readConfig = readConfig;
9
8
  exports.writeConfig = writeConfig;
@@ -13,8 +12,8 @@ exports.imageTag = imageTag;
13
12
  const fs_1 = __importDefault(require("fs"));
14
13
  const os_1 = __importDefault(require("os"));
15
14
  const path_1 = __importDefault(require("path"));
16
- exports.CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.huddle');
17
- const CONFIG_PATH = path_1.default.join(exports.CONFIG_DIR, 'config.json');
15
+ const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.huddle');
16
+ const CONFIG_PATH = path_1.default.join(CONFIG_DIR, 'config.json');
18
17
  function configPath() {
19
18
  return CONFIG_PATH;
20
19
  }
@@ -27,7 +26,7 @@ function readConfig() {
27
26
  }
28
27
  }
29
28
  function writeConfig(config) {
30
- fs_1.default.mkdirSync(exports.CONFIG_DIR, { recursive: true });
29
+ fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
31
30
  fs_1.default.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
32
31
  }
33
32
  /** Operator-token voor API-auth: env wint, anders uit de config. */
package/dist/firewall.js CHANGED
@@ -1,18 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.runFirewallList = runFirewallList;
7
4
  exports.runFirewallAdd = runFirewallAdd;
8
5
  exports.runFirewallDelete = runFirewallDelete;
9
- exports.runFirewallExport = runFirewallExport;
10
- exports.runFirewallImport = runFirewallImport;
11
- exports.runFirewallGroup = runFirewallGroup;
12
- exports.runFirewallFolder = runFirewallFolder;
13
- const fs_1 = __importDefault(require("fs"));
14
6
  const api_1 = require("./api");
15
- const config_1 = require("./config");
16
7
  const utils_1 = require("./utils");
17
8
  async function runFirewallList(opts) {
18
9
  const qs = new URLSearchParams({ status: opts.status ?? 'requested' });
@@ -65,9 +56,9 @@ async function resolveRule(rule, status, scope) {
65
56
  }
66
57
  // Creates a custom firewall rule. Supports wildcards: `*.` in the domain
67
58
  // (e.g. `*.pkgs.dev.azure.com`) and `*` in the path pattern (e.g.
68
- // `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a changing
69
- // GUID). Defaults to 'allow'; --deny creates a block rule. Without --container
70
- // the rule is global.
59
+ // `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a rotating
60
+ // GUID). Defaults to 'allow'; with --deny a block rule. Without --container the
61
+ // rule is global.
71
62
  async function runFirewallAdd(opts) {
72
63
  const domain = (opts.domain ?? '').trim();
73
64
  if (!domain) {
@@ -144,146 +135,3 @@ function printRulesTable(rules) {
144
135
  function formatTarget(rule) {
145
136
  return rule.path_pattern ? `${rule.domain}${rule.path_pattern}` : rule.domain;
146
137
  }
147
- async function runFirewallExport(opts) {
148
- const qs = new URLSearchParams();
149
- if (opts.container)
150
- qs.set('container', opts.container);
151
- const suffix = qs.toString() ? `?${qs}` : '';
152
- const doc = await (0, api_1.get)(`/api/rules/export${suffix}`);
153
- const json = JSON.stringify(doc, null, 2);
154
- if (opts.out) {
155
- fs_1.default.writeFileSync(opts.out, `${json}\n`);
156
- // Progress to stderr so a pure `--out` run leaks nothing to stdout.
157
- console.error((0, utils_1.green)(`[OK] Exported ${doc.rules.length} rule(s) to ${opts.out}`));
158
- }
159
- else {
160
- console.log(json);
161
- }
162
- }
163
- async function runFirewallImport(opts) {
164
- let raw;
165
- try {
166
- raw = fs_1.default.readFileSync(opts.file, 'utf8');
167
- }
168
- catch {
169
- throw new Error(`Cannot read ${opts.file}`);
170
- }
171
- let doc;
172
- try {
173
- doc = JSON.parse(raw);
174
- }
175
- catch {
176
- throw new Error(`${opts.file} is not valid JSON`);
177
- }
178
- const mode = opts.replace ? 'replace' : 'merge';
179
- const qs = new URLSearchParams();
180
- if (opts.container)
181
- qs.set('container', opts.container);
182
- const suffix = qs.toString() ? `?${qs}` : '';
183
- const res = await (0, api_1.post)(`/api/rules/import${suffix}`, { mode, rules: doc.rules });
184
- console.error((0, utils_1.green)(`[OK] Imported (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
185
- }
186
- async function resolveGroupByName(name) {
187
- const groups = await (0, api_1.get)('/api/groups');
188
- const match = groups.filter((g) => g.name.toLowerCase() === name.toLowerCase());
189
- if (match.length === 0)
190
- throw new Error(`No group named "${name}". Run \`huddle firewall group list\`.`);
191
- return match[0];
192
- }
193
- async function runFirewallGroup(opts) {
194
- const action = opts.action ?? 'list';
195
- if (action === 'list') {
196
- const groups = await (0, api_1.get)('/api/groups');
197
- if (groups.length === 0) {
198
- console.log((0, utils_1.dim)('No firewall groups yet.'));
199
- return;
200
- }
201
- const headers = ['ID', 'Name', 'Rules', 'Shared', 'Source'];
202
- const rows = groups.map((g) => [String(g.id), g.name, String(g.rule_count), g.shared ? 'yes' : 'no', g.source]);
203
- (0, utils_1.printTable)(headers, rows);
204
- return;
205
- }
206
- if (action === 'export') {
207
- const name = (opts.arg ?? '').trim();
208
- if (!name)
209
- throw new Error('Usage: huddle firewall group export <name> [--out <file>]');
210
- const g = await resolveGroupByName(name);
211
- const env = await (0, api_1.get)(`/api/groups/${g.id}/export`);
212
- const json = JSON.stringify(env, null, 2);
213
- if (opts.out) {
214
- fs_1.default.writeFileSync(opts.out, `${json}\n`);
215
- console.error((0, utils_1.green)(`[OK] Exported group "${g.name}" to ${opts.out}`));
216
- }
217
- else {
218
- console.log(json);
219
- }
220
- return;
221
- }
222
- if (action === 'import') {
223
- const file = (opts.arg ?? '').trim();
224
- if (!file)
225
- throw new Error('Usage: huddle firewall group import <file> [--replace]');
226
- let raw;
227
- try {
228
- raw = fs_1.default.readFileSync(file, 'utf8');
229
- }
230
- catch {
231
- throw new Error(`Cannot read ${file}`);
232
- }
233
- let envelope;
234
- try {
235
- envelope = JSON.parse(raw);
236
- }
237
- catch {
238
- throw new Error(`${file} is not valid JSON`);
239
- }
240
- const mode = opts.replace ? 'replace' : 'merge';
241
- const res = await (0, api_1.post)('/api/groups/import', { mode, envelope });
242
- console.error((0, utils_1.green)(`[OK] Imported group "${res.group.name}" (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
243
- return;
244
- }
245
- if (action === 'apply') {
246
- const name = (opts.arg ?? '').trim();
247
- if (!name)
248
- throw new Error('Usage: huddle firewall group apply <name> [--container <id>]');
249
- const g = await resolveGroupByName(name);
250
- const container = opts.container ?? null;
251
- const res = await (0, api_1.post)(`/api/groups/${g.id}/apply`, { container });
252
- const scope = container ? `container ${container}` : 'global';
253
- console.log((0, utils_1.green)(`[OK] Applied "${g.name}" to ${scope}: ${res.applied} added, ${res.updated} updated`));
254
- return;
255
- }
256
- throw new Error(`Unknown group action: ${action}. Use list | export | import | apply.`);
257
- }
258
- async function runFirewallFolder(opts) {
259
- const action = opts.action ?? 'show';
260
- if (action === 'show') {
261
- // The CLI config is the source of truth for the path.
262
- const folder = (0, config_1.readConfig)().firewallRulesFolder;
263
- console.log(folder ? folder : (0, utils_1.dim)('(no firewall rules folder configured)'));
264
- return;
265
- }
266
- if (action === 'set') {
267
- const path = (opts.path ?? '').trim();
268
- if (!path)
269
- throw new Error('Usage: huddle firewall folder set <path>');
270
- // Config-only: the gateway reads the folder at the fixed mount point the CLI
271
- // binds it to; there is no DB setting. Persist here and mount on restart.
272
- (0, config_1.writeConfig)({ ...(0, config_1.readConfig)(), firewallRulesFolder: path });
273
- console.log((0, utils_1.green)(`[OK] Firewall rules folder set to ${(0, utils_1.cyan)(path)}`));
274
- console.log((0, utils_1.dim)(' Run `huddle restart` to mount it into the gateway; it is then read on start & reload.'));
275
- return;
276
- }
277
- if (action === 'reload') {
278
- const res = await (0, api_1.post)('/api/firewall-rules-folder/reload', {});
279
- if (!res.mounted) {
280
- console.log((0, utils_1.dim)('No firewall rules folder mounted. Set one with `huddle firewall folder set <path>` and run `huddle restart`.'));
281
- return;
282
- }
283
- console.log((0, utils_1.green)(`[OK] Reloaded: ${res.groups} group(s), ${res.imported} rule(s), ${res.errors.length} error(s)`));
284
- for (const e of res.errors)
285
- console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
286
- return;
287
- }
288
- throw new Error(`Unknown folder action: ${action}. Use show | set | reload.`);
289
- }
package/dist/index.js CHANGED
@@ -15,9 +15,9 @@ const images_1 = require("./images");
15
15
  const self_update_1 = require("./self-update");
16
16
  const utils_1 = require("./utils");
17
17
  const experiment_1 = require("./experiment");
18
- const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'out', 'ca-path', 'output']);
19
- const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'replace', 'docker-socket', 'force']);
20
- const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'restart', 'experiment', 'migrate', 'help', 'version']);
18
+ const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output']);
19
+ const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force']);
20
+ const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'experiment', 'migrate', 'help', 'version']);
21
21
  function parseArgs(argv) {
22
22
  const positional = [];
23
23
  const flags = {};
@@ -94,8 +94,6 @@ Usage:
94
94
  huddle start [options] [folder] Explicitly start a devcontainer
95
95
  huddle init [options] Pull the Huddle + devcontainer base images and
96
96
  start them via Docker or Podman
97
- huddle restart Recreate the gateway (e.g. to mount a changed
98
- team firewall-rules folder)
99
97
  huddle migrate [folder] Wire an existing docker-compose devcontainer
100
98
  behind Huddle by generating an override file
101
99
  huddle firewall list [options] Show firewall requests
@@ -104,14 +102,6 @@ Usage:
104
102
  supported: *.example.com and /path/*)
105
103
  huddle firewall delete <id> Delete a firewall rule by id (or domain;
106
104
  narrow with --container)
107
- huddle firewall export [options] Export firewall rules as JSON
108
- huddle firewall import <file> Import firewall rules from a JSON file
109
- huddle firewall group list List firewall groups (#69)
110
- huddle firewall group export <name> Export a group as JSON (--out <file>)
111
- huddle firewall group import <file> Import a group (--replace to mirror)
112
- huddle firewall group apply <name> Apply a group (--container <id> or global)
113
- huddle firewall folder set <path> Set the team-managed rules folder
114
- huddle firewall folder reload Re-read the team-managed rules folder
115
105
  huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
116
106
  and run init
117
107
  huddle experiment reset Back to the stable release
@@ -142,8 +132,6 @@ Migrate options:
142
132
  Firewall options:
143
133
  -i, --interactive Interactively approve/deny (list)
144
134
  --container <name> Filter by (list) / scope to (add) a container
145
- (or __global__). On import: remap all rules
146
- to this scope
147
135
  --status <requested|allow|deny> Filter by status (default: requested)
148
136
 
149
137
  Firewall add options:
@@ -152,11 +140,6 @@ Firewall add options:
152
140
  (e.g. /_packaging/*/nuget/v3/*)
153
141
  --deny Create a block rule (default: allow)
154
142
 
155
- Firewall export/import options:
156
- --out <file> Write export to a file (default: stdout)
157
- --replace Import in replace mode: wipe the target
158
- scope first (default: merge/upsert)
159
-
160
143
  Global options:
161
144
  --url <url> Huddle URL (default: http://localhost:3000)
162
145
  Or via the HUDDLE_URL env var
@@ -219,15 +202,6 @@ async function main() {
219
202
  await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
220
203
  return;
221
204
  }
222
- if (cmd === 'restart') {
223
- // Stop + recreate the gateway (runInit does `rm -f` first) so changed team
224
- // folders get mounted. The portal writes the paths straight into the mounted
225
- // ~/.huddle/config.json, so runInit already reads the latest values here.
226
- const initOpts = { runtime: flagString(flags, 'runtime') };
227
- (0, experiment_1.ensureCliForChannel)(process.argv.slice(2));
228
- await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
229
- return;
230
- }
231
205
  if (cmd === 'experiment') {
232
206
  const subCmd = sub ?? 'status';
233
207
  if (subCmd === 'use') {
@@ -269,36 +243,6 @@ async function main() {
269
243
  container: flagString(flags, 'container'),
270
244
  });
271
245
  }
272
- else if (subCmd === 'export') {
273
- await (0, firewall_1.runFirewallExport)({
274
- container: flagString(flags, 'container'),
275
- out: flagString(flags, 'out'),
276
- });
277
- }
278
- else if (subCmd === 'import') {
279
- const file = positional[2];
280
- if (!file) {
281
- console.error('Usage: huddle firewall import <file> [--replace] [--container <id>]');
282
- process.exit(1);
283
- }
284
- await (0, firewall_1.runFirewallImport)({
285
- file,
286
- replace: flagBool(flags, 'replace'),
287
- container: flagString(flags, 'container'),
288
- });
289
- }
290
- else if (subCmd === 'group' || subCmd === 'groups') {
291
- await (0, firewall_1.runFirewallGroup)({
292
- action: positional[2],
293
- arg: positional[3],
294
- out: flagString(flags, 'out'),
295
- replace: flagBool(flags, 'replace'),
296
- container: flagString(flags, 'container'),
297
- });
298
- }
299
- else if (subCmd === 'folder') {
300
- await (0, firewall_1.runFirewallFolder)({ action: positional[2], path: positional[3] });
301
- }
302
246
  else {
303
247
  console.error(`Unknown firewall subcommand: ${subCmd}`);
304
248
  process.exit(1);
package/dist/init.js CHANGED
@@ -145,19 +145,6 @@ async function runInit(opts, images) {
145
145
  // network (moby/moby#36174). Which source IP the gateway sees for forwarded
146
146
  // traffic no longer matters — the control plane authenticates with the
147
147
  // operator token instead of source-IP filtering.
148
- // Team-managed folders (#69). Bind the CLI config dir (~/.huddle) read-write so
149
- // the gateway/portal read and write the folder paths there (config.json is the
150
- // single source of truth), then bind each configured team folder to a FIXED
151
- // path so the gateway reads it without knowing the host path. Read-only.
152
- const fwFolder = cfg.firewallRulesFolder?.trim();
153
- const extFolder = cfg.extensionsFolder?.trim();
154
- const homeMountFlag = ` -v "${config_1.CONFIG_DIR}:/huddle-home:rw" -e HUDDLE_HOME_DIR=/huddle-home`;
155
- const fwMountFlag = fwFolder ? ` -v "${fwFolder}:/firewall-rules:ro"` : '';
156
- const extMountFlag = extFolder ? ` -v "${extFolder}:/extensions:ro"` : '';
157
- if (fwFolder)
158
- console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
159
- if (extFolder)
160
- console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
161
148
  run(`${rt} run -d` +
162
149
  ` --name ${CONTAINER}` +
163
150
  ` --network ${runtime.defaultNetwork}` +
@@ -168,9 +155,6 @@ async function runInit(opts, images) {
168
155
  ` -v ${VOLUME}:/data` +
169
156
  ` -v "${runtime.socketPath}:/var/run/docker.sock"` +
170
157
  ` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
171
- homeMountFlag +
172
- fwMountFlag +
173
- extMountFlag +
174
158
  (0, images_1.gatewayEnvFlags)(images) +
175
159
  ` ${IMAGE}`);
176
160
  // Attaching devcontainer-net after the container has started pollutes
package/dist/migrate.js CHANGED
@@ -118,12 +118,9 @@ function findMarkedNetworks(compose) {
118
118
  * Throws on hard configuration errors (no/ambiguous marked network); collects
119
119
  * softer problems in `warnings`.
120
120
  */
121
- function buildOverride(compose, opts = {}) {
122
- const caPath = opts.caPath ?? exports.DEFAULT_CA_PATH;
123
- const internalNet = opts.internalNet ?? init_1.INTERNAL_NET;
124
- const socketDir = opts.socketDir ?? init_1.HOST_SOCKET_DIR;
125
- const warnings = [];
126
- const blockers = [];
121
+ // Exactly one network must carry the huddle.network label. Zero or more than one
122
+ // is a hard error the operator must resolve before a safe override can be built.
123
+ function resolveMarkedNetwork(compose) {
127
124
  const marked = findMarkedNetworks(compose);
128
125
  if (marked.length === 0) {
129
126
  throw new Error(`No network marked with \`${exports.HUDDLE_NETWORK_LABEL}: "true"\` was found. ` +
@@ -132,21 +129,65 @@ function buildOverride(compose, opts = {}) {
132
129
  if (marked.length > 1) {
133
130
  throw new Error(`Multiple networks marked with \`${exports.HUDDLE_NETWORK_LABEL}\`: ${marked.join(', ')}. Mark exactly one.`);
134
131
  }
135
- const markedNetwork = marked[0];
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.
132
+ return marked[0];
133
+ }
134
+ // Pick a key for the injected egress network that collides with NOTHING: not an
135
+ // existing network, and not the marked network itself (otherwise the two keys in
136
+ // the service's `networks` map collapse into one and the egress net is silently
137
+ // never added). Keep suffixing until it is unique.
138
+ function pickHuddleNetKey(compose, markedNetwork, preferred) {
140
139
  const taken = new Set(Object.keys(compose.networks ?? {}));
141
140
  taken.add(markedNetwork);
142
- let huddleNetKey = opts.huddleNetKey ?? exports.HUDDLE_NET_KEY;
143
- if (taken.has(huddleNetKey)) {
141
+ let key = preferred;
142
+ if (taken.has(key)) {
144
143
  let n = 0;
145
144
  do {
146
- huddleNetKey = n === 0 ? `${exports.HUDDLE_NET_KEY}-egress` : `${exports.HUDDLE_NET_KEY}-egress-${n}`;
145
+ key = n === 0 ? `${exports.HUDDLE_NET_KEY}-egress` : `${exports.HUDDLE_NET_KEY}-egress-${n}`;
147
146
  n++;
148
- } while (taken.has(huddleNetKey));
147
+ } while (taken.has(key));
148
+ }
149
+ return key;
150
+ }
151
+ // Build the override entry for a single service: keep it on the marked network,
152
+ // add the Huddle egress network + proxy env, and (with --docker-socket) mount the
153
+ // filtered Docker socket. Any second, non-internal network is flagged as a
154
+ // blocker — it would be an unfiltered route out that bypasses Huddle.
155
+ function buildInjectedService(svc, name, compose, ctx, warnings, blockers) {
156
+ for (const netKey of serviceNetworkKeys(svc)) {
157
+ if (netKey === ctx.markedNetwork)
158
+ continue;
159
+ const def = (compose.networks?.[netKey] ?? {});
160
+ if (!isTruthy(def.internal)) {
161
+ blockers.push(`Service "${name}" is also on network "${netKey}", which is not internal. ` +
162
+ 'Remove it or make it internal — a second non-internal network bypasses Huddle.');
163
+ }
164
+ }
165
+ const injected = {
166
+ // Keep the service on its own network AND add the Huddle egress network.
167
+ // Map form is robust regardless of Compose's list merge semantics.
168
+ networks: { [ctx.markedNetwork]: null, [ctx.huddleNetKey]: null },
169
+ environment: huddleProxyEnv(ctx.caPath, ctx.dockerSocket),
170
+ };
171
+ if (ctx.dockerSocket) {
172
+ const cn = svc.container_name;
173
+ if (!cn) {
174
+ warnings.push(`Service "${name}" has no \`container_name\`, so the filtered Docker socket cannot be mounted ` +
175
+ 'at a stable path. Set a fixed container_name or drop --docker-socket for this service.');
176
+ }
177
+ else {
178
+ injected.volumes = [`${ctx.socketDir}/${cn}:/var/run/huddle`];
179
+ }
149
180
  }
181
+ return injected;
182
+ }
183
+ function buildOverride(compose, opts = {}) {
184
+ const caPath = opts.caPath ?? exports.DEFAULT_CA_PATH;
185
+ const internalNet = opts.internalNet ?? init_1.INTERNAL_NET;
186
+ const socketDir = opts.socketDir ?? init_1.HOST_SOCKET_DIR;
187
+ const warnings = [];
188
+ const blockers = [];
189
+ const markedNetwork = resolveMarkedNetwork(compose);
190
+ const huddleNetKey = pickHuddleNetKey(compose, markedNetwork, opts.huddleNetKey ?? exports.HUDDLE_NET_KEY);
150
191
  // Guardrail: the marked network must be internal, otherwise it already has a
151
192
  // route to the internet and would bypass the firewall/proxy.
152
193
  const markedDef = (compose.networks?.[markedNetwork] ?? {});
@@ -160,37 +201,11 @@ function buildOverride(compose, opts = {}) {
160
201
  if (services.length === 0) {
161
202
  warnings.push(`No service is attached to the marked network "${markedNetwork}"; the override wires nothing.`);
162
203
  }
204
+ const ctx = { markedNetwork, huddleNetKey, caPath, socketDir, dockerSocket: !!opts.dockerSocket };
163
205
  const overrideServices = {};
164
206
  for (const name of services) {
165
207
  const svc = (compose.services?.[name] ?? {});
166
- // Guardrail: warn if the service also sits on another network that is not
167
- // internal — that would be a second, unfiltered route out.
168
- for (const netKey of serviceNetworkKeys(svc)) {
169
- if (netKey === markedNetwork)
170
- continue;
171
- const def = (compose.networks?.[netKey] ?? {});
172
- if (!isTruthy(def.internal)) {
173
- blockers.push(`Service "${name}" is also on network "${netKey}", which is not internal. ` +
174
- 'Remove it or make it internal — a second non-internal network bypasses Huddle.');
175
- }
176
- }
177
- const injected = {
178
- // Keep the service on its own network AND add the Huddle egress network.
179
- // Map form is robust regardless of Compose's list merge semantics.
180
- networks: { [markedNetwork]: null, [huddleNetKey]: null },
181
- environment: huddleProxyEnv(caPath, !!opts.dockerSocket),
182
- };
183
- if (opts.dockerSocket) {
184
- const cn = svc.container_name;
185
- if (!cn) {
186
- warnings.push(`Service "${name}" has no \`container_name\`, so the filtered Docker socket cannot be mounted ` +
187
- 'at a stable path. Set a fixed container_name or drop --docker-socket for this service.');
188
- }
189
- else {
190
- injected.volumes = [`${socketDir}/${cn}:/var/run/huddle`];
191
- }
192
- }
193
- overrideServices[name] = injected;
208
+ overrideServices[name] = buildInjectedService(svc, name, compose, ctx, warnings, blockers);
194
209
  }
195
210
  const override = {
196
211
  services: overrideServices,
@@ -229,6 +244,10 @@ function stripComment(line) {
229
244
  }
230
245
  return line;
231
246
  }
247
+ // Shared depth cap for both the reader (parseNode ↔ parseMapping/parseSequence)
248
+ // and the writer (dumpYaml ↔ dumpInlineOrBlock). Real compose trees are only a
249
+ // few levels deep; a much larger cap still forecloses stack-exhaustion (CWE-674).
250
+ const MAX_YAML_DEPTH = 64;
232
251
  function unsupportedYaml(feature) {
233
252
  return new Error(`the compose file uses ${feature}, which \`huddle migrate\`'s built-in YAML reader does ` +
234
253
  'not support and would mis-parse (risking a dropped, un-filtered service). Inline or ' +
@@ -279,10 +298,9 @@ function parseYaml(input) {
279
298
  let pos = 0;
280
299
  // Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
281
300
  // nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
282
- const MAX_DEPTH = 64;
283
301
  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.`);
302
+ if (depth > MAX_YAML_DEPTH) {
303
+ throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
286
304
  }
287
305
  if (pos >= lines.length || lines[pos].indent < indent)
288
306
  return null;
@@ -365,8 +383,12 @@ function parseScalar(raw) {
365
383
  const map = {};
366
384
  for (const part of splitFlow(value.slice(1, -1))) {
367
385
  const colon = findKeyColon(part);
386
+ // Fail closed: a flow-map entry we cannot split into `key: value` (e.g. the
387
+ // compact `{networks:[dev, public]}` form, where the colon has no following
388
+ // space) must NOT be silently dropped — that would omit the service from the
389
+ // generated override and leave it on its original, un-filtered network.
368
390
  if (colon < 0)
369
- continue;
391
+ throw unsupportedYaml('a compact flow-mapping entry (`{key:value}` without a space after the colon)');
370
392
  map[unquote(part.slice(0, colon).trim())] = parseScalar(part.slice(colon + 1).trim());
371
393
  }
372
394
  return map;
@@ -425,6 +447,13 @@ function unquote(value) {
425
447
  }
426
448
  /** Emits an object as YAML using the subset the reader understands. */
427
449
  function dumpYaml(obj, indent = 0) {
450
+ // `indent` doubles as the recursion depth (dumpYaml ↔ dumpInlineOrBlock each
451
+ // step it by one). Cap it so a pathologically nested object cannot exhaust the
452
+ // stack (CWE-674) — mirrors the MAX_DEPTH guard on the parse side. Legitimate
453
+ // compose trees are only a few levels deep.
454
+ if (indent > MAX_YAML_DEPTH) {
455
+ throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to emit this override.`);
456
+ }
428
457
  const pad = ' '.repeat(indent);
429
458
  if (obj === null || obj === undefined)
430
459
  return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-66.40.1",
3
+ "version": "0.0.0-experiment-97.41.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.",