@infosupport/huddle-cli 0.0.0-experiment-98.43.1 → 0.0.0-experiment-98.46.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 CHANGED
@@ -160,21 +160,25 @@ async function runFirewallExport(opts) {
160
160
  console.log(json);
161
161
  }
162
162
  }
163
- async function runFirewallImport(opts) {
163
+ // Read + JSON-parse a file with uniform, actionable errors. Shared by both
164
+ // import paths (flat rules and groups).
165
+ function readJsonFile(file) {
164
166
  let raw;
165
167
  try {
166
- raw = fs_1.default.readFileSync(opts.file, 'utf8');
168
+ raw = fs_1.default.readFileSync(file, 'utf8');
167
169
  }
168
170
  catch {
169
- throw new Error(`Cannot read ${opts.file}`);
171
+ throw new Error(`Cannot read ${file}`);
170
172
  }
171
- let doc;
172
173
  try {
173
- doc = JSON.parse(raw);
174
+ return JSON.parse(raw);
174
175
  }
175
176
  catch {
176
- throw new Error(`${opts.file} is not valid JSON`);
177
+ throw new Error(`${file} is not valid JSON`);
177
178
  }
179
+ }
180
+ async function runFirewallImport(opts) {
181
+ const doc = readJsonFile(opts.file);
178
182
  const mode = opts.replace ? 'replace' : 'merge';
179
183
  const qs = new URLSearchParams();
180
184
  if (opts.container)
@@ -223,20 +227,7 @@ async function runFirewallGroup(opts) {
223
227
  const file = (opts.arg ?? '').trim();
224
228
  if (!file)
225
229
  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
- }
230
+ const envelope = readJsonFile(file);
240
231
  const mode = opts.replace ? 'replace' : 'merge';
241
232
  const res = await (0, api_1.post)('/api/groups/import', { mode, envelope });
242
233
  console.error((0, utils_1.green)(`[OK] Imported group "${res.group.name}" (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
@@ -285,5 +276,23 @@ async function runFirewallFolder(opts) {
285
276
  console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
286
277
  return;
287
278
  }
288
- throw new Error(`Unknown folder action: ${action}. Use show | set | reload.`);
279
+ if (action === 'sync') {
280
+ // Write the portal's groups back out to the folder (app → files).
281
+ const res = await (0, api_1.post)('/api/firewall-rules-folder/sync', {});
282
+ if (!res.mounted) {
283
+ console.log((0, utils_1.dim)('No firewall rules folder mounted. Set one with `huddle firewall folder set <path>` and run `huddle restart`.'));
284
+ return;
285
+ }
286
+ if (res.written === 0 && res.errors.length > 0) {
287
+ console.error((0, utils_1.red)('[!] Could not write to the folder — it may still be mounted read-only. Run `huddle restart` to remount it writable.'));
288
+ for (const e of res.errors)
289
+ console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
290
+ return;
291
+ }
292
+ console.log((0, utils_1.green)(`[OK] Synced: ${res.written} group(s) written, ${res.pruned} stale file(s) removed, ${res.errors.length} error(s)`));
293
+ for (const e of res.errors)
294
+ console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
295
+ return;
296
+ }
297
+ throw new Error(`Unknown folder action: ${action}. Use show | set | reload | sync.`);
289
298
  }
package/dist/images.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveImages = resolveImages;
4
- exports.gatewayEnvFlags = gatewayEnvFlags;
4
+ exports.gatewayEnvArgs = gatewayEnvArgs;
5
5
  const config_1 = require("./config");
6
6
  function resolveImages() {
7
7
  const experiment = (0, config_1.activeExperiment)();
@@ -19,13 +19,17 @@ function resolveImages() {
19
19
  };
20
20
  }
21
21
  /**
22
- * `-e` flags for the gateway container. During an experiment (or with an
23
- * explicit override) the gateway must start devcontainers from the same
24
- * base images the CLI just pulled.
22
+ * `-e KEY=val` argv pairs for the gateway container. During an experiment (or
23
+ * with an explicit override) the gateway must start devcontainers from the same
24
+ * base images the CLI just pulled. Returned as an argv array (not a shell
25
+ * string) so init can spawn `docker run` without a shell.
25
26
  */
26
- function gatewayEnvFlags(resolved) {
27
- return resolved.baseImages
28
- .filter((b) => b.gatewayEnv && (resolved.experiment !== undefined || process.env[b.gatewayEnv]))
29
- .map((b) => ` -e ${b.gatewayEnv}=${b.image}`)
30
- .join('');
27
+ function gatewayEnvArgs(resolved) {
28
+ const args = [];
29
+ for (const b of resolved.baseImages) {
30
+ if (b.gatewayEnv && (resolved.experiment !== undefined || process.env[b.gatewayEnv])) {
31
+ args.push('-e', `${b.gatewayEnv}=${b.image}`);
32
+ }
33
+ }
34
+ return args;
31
35
  }
package/dist/index.js CHANGED
@@ -112,6 +112,7 @@ Usage:
112
112
  huddle firewall group apply <name> Apply a group (--container <id> or global)
113
113
  huddle firewall folder set <path> Set the team-managed rules folder
114
114
  huddle firewall folder reload Re-read the team-managed rules folder
115
+ huddle firewall folder sync Write the portal's groups back to the folder
115
116
  huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
116
117
  and run init
117
118
  huddle experiment reset Back to the stable release
package/dist/init.js CHANGED
@@ -29,12 +29,16 @@ exports.INTERNAL_NET = 'devcontainer-net';
29
29
  */
30
30
  exports.HOST_SOCKET_DIR = '/tmp/dc-sockets';
31
31
  const HOST_PORT = process.env.HUDDLE_PORT ?? '3000';
32
- function run(cmd) {
33
- (0, child_process_1.execSync)(cmd, { stdio: 'inherit' });
32
+ // Run a binary with an argv array — NO shell. Values that originate from config
33
+ // (team-folder paths, which are writable via `huddle firewall folder set` and the
34
+ // authenticated settings API) must never be interpolated into a shell string, or
35
+ // a path containing `$()`/quotes would execute on the host. Used for `docker run`.
36
+ function runArgs(file, args) {
37
+ (0, child_process_1.execFileSync)(file, args, { stdio: 'inherit' });
34
38
  }
35
- function runSilent(cmd) {
39
+ function runArgsSilent(file, args) {
36
40
  try {
37
- (0, child_process_1.execSync)(cmd, { stdio: 'ignore' });
41
+ (0, child_process_1.execFileSync)(file, args, { stdio: 'ignore' });
38
42
  return true;
39
43
  }
40
44
  catch {
@@ -52,7 +56,7 @@ function pullBaseImages(rt, images) {
52
56
  for (const image of images) {
53
57
  console.log((0, utils_1.dim)(` Pulling ${image}`));
54
58
  try {
55
- run(`${rt} pull ${image}`);
59
+ runArgs(rt, ['pull', image]);
56
60
  }
57
61
  catch {
58
62
  failed.push(image);
@@ -82,15 +86,15 @@ async function runInit(opts, images) {
82
86
  }
83
87
  else {
84
88
  console.log((0, utils_1.dim)(`Pulling ${IMAGE}`));
85
- run(`${rt} pull ${IMAGE}`);
89
+ runArgs(rt, ['pull', IMAGE]);
86
90
  pullBaseImages(rt, images.baseImages.map((b) => b.image));
87
91
  }
88
92
  console.log((0, utils_1.dim)(`Volume: ${VOLUME}`));
89
- runSilent(`${rt} volume inspect ${VOLUME}`) || run(`${rt} volume create ${VOLUME}`);
93
+ runArgsSilent(rt, ['volume', 'inspect', VOLUME]) || runArgs(rt, ['volume', 'create', VOLUME]);
90
94
  console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
91
- runSilent(`${rt} network inspect ${exports.INTERNAL_NET}`) || run(`${rt} network create --internal ${exports.INTERNAL_NET}`);
95
+ runArgsSilent(rt, ['network', 'inspect', exports.INTERNAL_NET]) || runArgs(rt, ['network', 'create', '--internal', exports.INTERNAL_NET]);
92
96
  console.log((0, utils_1.dim)(`Removing old container if it exists`));
93
- runSilent(`${rt} rm -f ${CONTAINER}`);
97
+ runArgsSilent(rt, ['rm', '-f', CONTAINER]);
94
98
  console.log((0, utils_1.dim)(`Socket directory: /tmp/dc-sockets`));
95
99
  // The mount SOURCE must be the path on the Docker ENGINE host (on Windows:
96
100
  // the WSL2/Linux VM), even when the CLI itself runs on Windows. The gateway
@@ -105,7 +109,7 @@ async function runInit(opts, images) {
105
109
  // Desktop) and fails with "statfs: no such file or directory". So create
106
110
  // the directory explicitly in the machine VM; the socket lives there too.
107
111
  console.log((0, utils_1.dim)(` (Podman: creating ${hostTmpSockets} in the machine VM)`));
108
- if (!runSilent(`podman machine ssh "mkdir -p ${hostTmpSockets}"`)) {
112
+ if (!runArgsSilent('podman', ['machine', 'ssh', `mkdir -p ${hostTmpSockets}`])) {
109
113
  console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets} in the Podman VM.`));
110
114
  }
111
115
  }
@@ -126,8 +130,7 @@ async function runInit(opts, images) {
126
130
  // The gateway is engine-agnostic (talks the Docker-compatible API on the
127
131
  // mounted socket), but does need to know it's Podman: it then sets
128
132
  // `--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('');
133
+ // SELinux-labeled proxy socket. (Applied as argv below via runtime.securityOpts.)
131
134
  // Operator token for control-plane auth. Reuse the token from the config (so an
132
135
  // existing browser session/CLI keeps working across re-inits), otherwise
133
136
  // generate one. We pass it to the gateway via env AND store it locally so that
@@ -148,36 +151,40 @@ async function runInit(opts, images) {
148
151
  // Team-managed folders (#69). Bind the CLI config dir (~/.huddle) read-write so
149
152
  // the gateway/portal read and write the folder paths there (config.json is the
150
153
  // 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.
154
+ // path so the gateway reads it without knowing the host path. The firewall-rules
155
+ // folder is bound read-write so the portal's "Sync to folder" can write the
156
+ // groups back out; extensions stay read-only (loaded, never written).
152
157
  const fwFolder = cfg.firewallRulesFolder?.trim();
153
158
  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
159
  if (fwFolder)
158
160
  console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
159
161
  if (extFolder)
160
162
  console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
161
- run(`${rt} run -d` +
162
- ` --name ${CONTAINER}` +
163
- ` --network ${runtime.defaultNetwork}` +
164
- securityOptFlags +
165
- ` -e HUDDLE_RUNTIME=${runtime.name}` +
166
- ` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
167
- ` -p ${HOST_PORT}:3000` +
168
- ` -v ${VOLUME}:/data` +
169
- ` -v "${runtime.socketPath}:/var/run/docker.sock"` +
170
- ` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
171
- homeMountFlag +
172
- fwMountFlag +
173
- extMountFlag +
174
- (0, images_1.gatewayEnvFlags)(images) +
175
- ` ${IMAGE}`);
163
+ // Build the container command as an argv array (runArgs → execFileSync, no
164
+ // shell). The folder paths below come from config and are operator-writable via
165
+ // the settings API, so they must never reach a shell as a string.
166
+ const dockerArgs = ['run', '-d', '--name', CONTAINER, '--network', runtime.defaultNetwork];
167
+ for (const opt of runtime.securityOpts)
168
+ dockerArgs.push('--security-opt', opt);
169
+ dockerArgs.push('-e', `HUDDLE_RUNTIME=${runtime.name}`);
170
+ dockerArgs.push('-e', `HUDDLE_OPERATOR_TOKEN=${operatorToken}`);
171
+ dockerArgs.push('-p', `${HOST_PORT}:3000`);
172
+ dockerArgs.push('-v', `${VOLUME}:/data`);
173
+ dockerArgs.push('-v', `${runtime.socketPath}:/var/run/docker.sock`);
174
+ dockerArgs.push('-v', `${hostTmpSockets}:/tmp/dc-sockets`);
175
+ dockerArgs.push('-v', `${config_1.CONFIG_DIR}:/huddle-home:rw`, '-e', 'HUDDLE_HOME_DIR=/huddle-home');
176
+ if (fwFolder)
177
+ dockerArgs.push('-v', `${fwFolder}:/firewall-rules:rw`);
178
+ if (extFolder)
179
+ dockerArgs.push('-v', `${extFolder}:/extensions:ro`);
180
+ dockerArgs.push(...(0, images_1.gatewayEnvArgs)(images));
181
+ dockerArgs.push(IMAGE);
182
+ runArgs(rt, dockerArgs);
176
183
  // Attaching devcontainer-net after the container has started pollutes
177
184
  // resolv.conf on Podman with that network's internal aardvark-DNS; the
178
185
  // gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
179
186
  // index.ts).
180
- runSilent(`${rt} network connect ${exports.INTERNAL_NET} ${CONTAINER}`);
187
+ runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, CONTAINER]);
181
188
  console.log();
182
189
  console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
183
190
  console.log();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-98.43.1",
3
+ "version": "0.0.0-experiment-98.46.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.",