@infosupport/huddle-cli 0.0.0-experiment-66.28.1 → 0.0.0-experiment-66.30.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
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runFirewallList = runFirewallList;
7
7
  exports.runFirewallAdd = runFirewallAdd;
8
+ exports.runFirewallDelete = runFirewallDelete;
8
9
  exports.runFirewallExport = runFirewallExport;
9
10
  exports.runFirewallImport = runFirewallImport;
10
11
  const fs_1 = __importDefault(require("fs"));
@@ -59,11 +60,11 @@ async function reviewRule(rule, idx, total) {
59
60
  async function resolveRule(rule, status, scope) {
60
61
  await (0, api_1.post)(`/api/rules/${rule.id}/resolve`, { status, scope });
61
62
  }
62
- // Maakt een eigen firewall-regel aan. Ondersteunt wildcards: `*.` in het domein
63
- // (bv. `*.pkgs.dev.azure.com`) en `*` in het padpatroon (bv.
64
- // `/_packaging/*/nuget/v3/*` voor een Azure-DevOps-feed met een wisselende
65
- // GUID). Standaard 'allow'; met --deny een block-regel. Zonder --container is
66
- // de regel globaal.
63
+ // Creates a custom firewall rule. Supports wildcards: `*.` in the domain
64
+ // (e.g. `*.pkgs.dev.azure.com`) and `*` in the path pattern (e.g.
65
+ // `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a changing
66
+ // GUID). Defaults to 'allow'; --deny creates a block rule. Without --container
67
+ // the rule is global.
67
68
  async function runFirewallAdd(opts) {
68
69
  const domain = (opts.domain ?? '').trim();
69
70
  if (!domain) {
@@ -84,6 +85,43 @@ async function runFirewallAdd(opts) {
84
85
  const verb = status === 'deny' ? (0, utils_1.red)('Denied') : (0, utils_1.green)('Allowed');
85
86
  console.log(`${verb} ${(0, utils_1.bold)((0, utils_1.cyan)(target))} ${(0, utils_1.dim)(`(${scope})`)}`);
86
87
  }
88
+ // Deletes a firewall rule. Accepts the numeric id shown by `firewall list`
89
+ // (deleted directly) or a domain, which is resolved to a single rule id via a
90
+ // lookup. `--container` narrows a domain match to one scope; an ambiguous
91
+ // domain (multiple matching rules) is refused with the candidate ids so the
92
+ // caller can re-run with an exact id.
93
+ async function runFirewallDelete(opts) {
94
+ const target = (opts.target ?? '').trim();
95
+ if (!target) {
96
+ throw new Error('Usage: huddle firewall delete <id-or-domain> [--container <id>]');
97
+ }
98
+ let id;
99
+ if (/^\d+$/.test(target)) {
100
+ id = Number(target);
101
+ }
102
+ else {
103
+ // Domain form: list all rules (optionally scoped) and resolve to one id.
104
+ const qs = new URLSearchParams();
105
+ if (opts.container)
106
+ qs.set('container', opts.container);
107
+ const query = qs.toString();
108
+ const rules = await (0, api_1.get)(`/api/rules${query ? `?${query}` : ''}`);
109
+ const matches = rules.filter((r) => r.domain === target);
110
+ if (matches.length === 0) {
111
+ const scope = opts.container ? ` for container ${opts.container}` : '';
112
+ throw new Error(`No firewall rule found for "${target}"${scope}.`);
113
+ }
114
+ if (matches.length > 1) {
115
+ const ids = matches
116
+ .map((r) => ` ${r.id} ${r.status.padEnd(9)} ${formatTarget(r)} ${r.container_id ?? '(global)'}`)
117
+ .join('\n');
118
+ throw new Error(`"${target}" matches ${matches.length} rules — delete by id (or narrow with --container):\n${ids}`);
119
+ }
120
+ id = matches[0].id;
121
+ }
122
+ await (0, api_1.del)(`/api/rules/${id}`);
123
+ console.log(`${(0, utils_1.green)('Deleted')} rule ${(0, utils_1.bold)((0, utils_1.cyan)(String(id)))}`);
124
+ }
87
125
  function printRulesTable(rules) {
88
126
  const headers = ['ID', 'Status', 'Domain/path', 'Container', 'Requests', 'Seen'];
89
127
  const rows = rules.map((r) => [
@@ -108,7 +146,7 @@ async function runFirewallExport(opts) {
108
146
  const json = JSON.stringify(doc, null, 2);
109
147
  if (opts.out) {
110
148
  fs_1.default.writeFileSync(opts.out, `${json}\n`);
111
- // Voortgang naar stderr zodat een pure `--out` run niets naar stdout lekt.
149
+ // Progress to stderr so a pure `--out` run leaks nothing to stdout.
112
150
  console.error((0, utils_1.green)(`[OK] Exported ${doc.rules.length} rule(s) to ${opts.out}`));
113
151
  }
114
152
  else {
package/dist/index.js CHANGED
@@ -100,6 +100,8 @@ Usage:
100
100
  huddle fw list [options] Alias for firewall list
101
101
  huddle firewall add <domain> Add a custom firewall rule (wildcards
102
102
  supported: *.example.com and /path/*)
103
+ huddle firewall delete <id> Delete a firewall rule by id (or domain;
104
+ narrow with --container)
103
105
  huddle firewall export [options] Export firewall rules as JSON
104
106
  huddle firewall import <file> Import firewall rules from a JSON file
105
107
  huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
@@ -244,6 +246,12 @@ async function main() {
244
246
  container: flagString(flags, 'container'),
245
247
  });
246
248
  }
249
+ else if (subCmd === 'delete' || subCmd === 'remove' || subCmd === 'rm') {
250
+ await (0, firewall_1.runFirewallDelete)({
251
+ target: positional[2],
252
+ container: flagString(flags, 'container'),
253
+ });
254
+ }
247
255
  else if (subCmd === 'export') {
248
256
  await (0, firewall_1.runFirewallExport)({
249
257
  container: flagString(flags, 'container'),
package/dist/init.js CHANGED
@@ -128,10 +128,10 @@ async function runInit(opts, images) {
128
128
  // `--security-opt label=disable` on every devcontainer so it can reach the
129
129
  // SELinux-labeled proxy socket.
130
130
  const securityOptFlags = runtime.securityOpts.map((opt) => ` --security-opt ${opt}`).join('');
131
- // Operator-token voor de control-plane-auth. Hergebruik het token uit de
132
- // config (zodat een bestaande browser-sessie/CLI blijft werken over re-inits),
133
- // anders genereer er één. We geven het aan de gateway mee via env én bewaren
134
- // het lokaal zodat volgende `huddle`-commando's zich kunnen authenticeren.
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
135
  const cfg = (0, config_1.readConfig)();
136
136
  const operatorToken = process.env.HUDDLE_OPERATOR_TOKEN?.trim() ||
137
137
  (cfg.operatorToken && cfg.operatorToken.trim()) ||
@@ -165,9 +165,9 @@ async function runInit(opts, images) {
165
165
  console.log();
166
166
  console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
167
167
  console.log();
168
- // Volledige auto-login-link: open deze en de portal logt je automatisch in met
169
- // het operator-token (de frontend leest ?token=..., logt in en verwijdert het
170
- // daarna uit de adresbalk). Zo hoef je niets te plakken.
168
+ // Full auto-login link: open it and the portal logs you in automatically with
169
+ // the operator token (the frontend reads ?token=..., logs in and then removes it
170
+ // from the address bar). This way you don't have to paste anything.
171
171
  const loginUrl = `http://localhost:${HOST_PORT}/?token=${encodeURIComponent(operatorToken)}`;
172
172
  console.log((0, utils_1.bold)('Open the portal (auto-login link):'));
173
173
  console.log((0, utils_1.green)(` ${loginUrl}`));
package/dist/migrate.js CHANGED
@@ -220,8 +220,48 @@ function stripComment(line) {
220
220
  }
221
221
  return line;
222
222
  }
223
+ function unsupportedYaml(feature) {
224
+ return new Error(`the compose file uses ${feature}, which \`huddle migrate\`'s built-in YAML reader does ` +
225
+ 'not support and would mis-parse (risking a dropped, un-filtered service). Inline or ' +
226
+ 'quote it, or flatten the file first with `docker compose config`, then re-run `huddle migrate`.');
227
+ }
228
+ // A YAML block-scalar header: `|` or `>` followed by an optional indentation
229
+ // indicator (1-9) and/or chomping indicator (+/-), each at most once, in either
230
+ // order. Anchored so plain scalars that merely start with `>`/`|` (e.g. `>=1.0`)
231
+ // do not match.
232
+ const BLOCK_SCALAR_HEADER = /^[|>]([1-9][+-]?|[+-][1-9]?)?$/;
233
+ // The value carried by a tokenized line: a mapping value (after `key:`), a
234
+ // sequence-item value (after `- `), or the bare line.
235
+ function lineValue(text) {
236
+ const colon = findKeyColon(text);
237
+ if (colon >= 0)
238
+ return text.slice(colon + 1).trim();
239
+ if (isSeqItem(text))
240
+ return text.replace(/^-\s*/, '').trim();
241
+ return text;
242
+ }
243
+ // Fail-closed on YAML features the indentation reader below cannot represent
244
+ // (finding #9). Block scalars (`|`/`>`), anchors/aliases (`&`/`*`) and merge keys
245
+ // (`<<`) are silently mis-parsed — a block scalar's indented body is read as real
246
+ // structure, which can swallow the next service and drop it from the generated
247
+ // override (leaving it with an unfiltered route out). Detect them up front and
248
+ // refuse with a clear, actionable error instead of guessing.
249
+ function rejectUnsupportedYaml(lines) {
250
+ for (const { text } of lines) {
251
+ if (/^<<\s*:/.test(text))
252
+ throw unsupportedYaml('a merge key (`<<`)');
253
+ const value = lineValue(text);
254
+ if (BLOCK_SCALAR_HEADER.test(value))
255
+ throw unsupportedYaml('a block scalar (`|` or `>`)');
256
+ if (/^&[A-Za-z0-9_]/.test(value))
257
+ throw unsupportedYaml('a YAML anchor (`&`)');
258
+ if (/^\*[A-Za-z0-9_]/.test(value))
259
+ throw unsupportedYaml('a YAML alias (`*`)');
260
+ }
261
+ }
223
262
  function parseYaml(input) {
224
263
  const lines = tokenize(input);
264
+ rejectUnsupportedYaml(lines);
225
265
  let pos = 0;
226
266
  function parseNode(indent) {
227
267
  if (pos >= lines.length || lines[pos].indent < indent)
@@ -468,8 +508,8 @@ function resolveComposeFile(target) {
468
508
  function huddleNetworkExists(internalNet, runtime) {
469
509
  try {
470
510
  const rt = (0, runtime_1.resolveRuntime)(runtime);
471
- // execFileSync (arg-array, geen shell) i.p.v. execSync: er komt geen shell aan
472
- // te pas, dus geen command-injection-oppervlak via de runtime-/netwerknaam.
511
+ // execFileSync (arg array, no shell) instead of execSync: no shell is
512
+ // involved, so there is no command-injection surface via the runtime/network name.
473
513
  (0, child_process_1.execFileSync)(rt.name, ['network', 'inspect', internalNet], { stdio: 'ignore' });
474
514
  return true;
475
515
  }
package/dist/runtime.js CHANGED
@@ -18,12 +18,12 @@ function isAvailable(runtime) {
18
18
  return commandOutput(`${runtime} info`) !== undefined;
19
19
  }
20
20
  /**
21
- * Bepaalt de ECHTE engine achter een commando, of undefined als de engine niet
22
- * bereikbaar is. Vertrouw niet op de commandonaam: `docker` is vaak een
23
- * symlink/shim naar Podman (podman-docker) en Podman emuleert dan zelfs
24
- * `docker --version`. Podman's `info` kent daarentegen het veld
25
- * Host.ServiceIsRemote; Docker's info-schema niet. Dat is een betrouwbaar
26
- * onderscheid dat ook via de shim werkt.
21
+ * Determines the REAL engine behind a command, or undefined if the engine is
22
+ * not reachable. Do not trust the command name: `docker` is often a
23
+ * symlink/shim to Podman (podman-docker), and Podman then even emulates
24
+ * `docker --version`. Podman's `info`, on the other hand, has the field
25
+ * Host.ServiceIsRemote; Docker's info schema does not. That is a reliable
26
+ * distinction that also works through the shim.
27
27
  */
28
28
  function detectEngine(command) {
29
29
  if (commandOutput(`${command} info --format "{{.Host.ServiceIsRemote}}"`) !== undefined) {
@@ -45,15 +45,15 @@ function dockerSocketPath() {
45
45
  return process.platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock';
46
46
  }
47
47
  /**
48
- * Haalt het unix-socketpad uit de JSON van `docker context inspect`. De actieve
49
- * context bepaalt naar welke engine het `docker`-commando praat; Rancher Desktop
50
- * (dockerd/moby-modus) zet een `rancher-desktop`-context waarvan
51
- * `Endpoints.docker.Host` naar `unix:///<home>/.rd/docker.sock` wijst i.p.v. de
52
- * standaard `/var/run/docker.sock`.
48
+ * Extracts the unix socket path from the JSON of `docker context inspect`. The
49
+ * active context determines which engine the `docker` command talks to; Rancher
50
+ * Desktop (dockerd/moby mode) sets a `rancher-desktop` context whose
51
+ * `Endpoints.docker.Host` points to `unix:///<home>/.rd/docker.sock` instead of
52
+ * the default `/var/run/docker.sock`.
53
53
  *
54
- * Pure functie zodat we het parsen los kunnen testen. Geeft `null` terug bij
55
- * niet-parsebare invoer of een niet-unix endpoint (npipe:// op Windows,
56
- * tcp:// / ssh:// remote), want die zijn niet als bestandspad te bind-mounten.
54
+ * Pure function so we can test the parsing in isolation. Returns `null` for
55
+ * non-parsable input or a non-unix endpoint (npipe:// on Windows,
56
+ * tcp:// / ssh:// remote), because those cannot be bind-mounted as a file path.
57
57
  */
58
58
  function parseDockerContextSocket(json) {
59
59
  let parsed;
@@ -63,7 +63,7 @@ function parseDockerContextSocket(json) {
63
63
  catch {
64
64
  return null;
65
65
  }
66
- // `docker context inspect` levert een array; één context is één element.
66
+ // `docker context inspect` returns an array; one context is one element.
67
67
  const entry = Array.isArray(parsed) ? parsed[0] : parsed;
68
68
  const host = entry
69
69
  ?.Endpoints?.docker?.Host;
@@ -72,21 +72,21 @@ function parseDockerContextSocket(json) {
72
72
  const path = host.slice('unix://'.length);
73
73
  if (!path.startsWith('/'))
74
74
  return null;
75
- // Het teruggegeven pad wordt later ONgequote in een `docker run -v <pad>:...`
76
- // shell-commando geïnterpoleerd (init.ts). De `Host` uit `docker context
77
- // inspect` is beïnvloedbaar (wie een docker-context kan aanmaken/activeren
78
- // bepaalt de waarde), dus laat alleen tekens toe die in een echt socketpad
79
- // voorkomen. Zo kan een gemanipuleerde context geen shell-metatekens
80
- // ($(), backticks, ;, |, spaties, ...) binnensmokkelen — command injection.
75
+ // The returned path is later interpolated UNquoted into a `docker run -v
76
+ // <path>:...` shell command (init.ts). The `Host` from `docker context
77
+ // inspect` is attacker-influenceable (whoever can create/activate a docker
78
+ // context controls the value), so only allow characters that occur in a real
79
+ // socket path. This way a manipulated context cannot smuggle in shell
80
+ // metacharacters ($(), backticks, ;, |, spaces, ...) — command injection.
81
81
  if (!/^[A-Za-z0-9._/-]+$/.test(path))
82
82
  return null;
83
83
  return path;
84
84
  }
85
- /** Herkent het socketpad van Rancher Desktop (dockerd/moby-modus): `~/.rd/docker.sock`. */
85
+ /** Recognizes the Rancher Desktop socket path (dockerd/moby mode): `~/.rd/docker.sock`. */
86
86
  function isRancherDesktopSocket(socketPath) {
87
87
  return typeof socketPath === 'string' && /(^|\/)\.rd\/docker\.sock$/.test(socketPath);
88
88
  }
89
- /** Socketpad van de actieve docker-context, of undefined als het niet op te vragen is. */
89
+ /** Socket path of the active docker context, or undefined if it cannot be queried. */
90
90
  function dockerContextSocket() {
91
91
  const json = commandOutput('docker context inspect');
92
92
  if (!json)
@@ -94,9 +94,9 @@ function dockerContextSocket() {
94
94
  return parseDockerContextSocket(json) ?? undefined;
95
95
  }
96
96
  function podmanIsRemote() {
97
- // Op macOS/Windows draait Podman altijd in een `podman machine`-VM; ook op
98
- // Linux kan de client op een remote socket wijzen. `ServiceIsRemote` is de
99
- // gezaghebbende bron.
97
+ // On macOS/Windows Podman always runs in a `podman machine` VM; on Linux too
98
+ // the client can point at a remote socket. `ServiceIsRemote` is the
99
+ // authoritative source.
100
100
  return commandOutput(`podman info --format "{{.Host.ServiceIsRemote}}"`) === 'true';
101
101
  }
102
102
  function buildRuntime(name) {
@@ -109,20 +109,20 @@ function buildRuntime(name) {
109
109
  securityOpts: ['label=disable'],
110
110
  };
111
111
  }
112
- // Rancher Desktop (dockerd/moby-modus) ziet er als een gewone Docker-engine
113
- // uit, maar de socket zit niet op /var/run/docker.sock: de actieve
114
- // docker-context wijst naar `~/.rd/docker.sock`. Volg die context zodat we de
115
- // juiste socket bind-mounten; anders vallen we terug op de standaardlocatie
116
- // (echte native Docker, Docker Desktop). Rancher Desktop draait de engine op
117
- // ELK platform in een VM (Lima/WSL), dus is hij altijd 'remote'.
112
+ // Rancher Desktop (dockerd/moby mode) looks like an ordinary Docker engine,
113
+ // but the socket is not at /var/run/docker.sock: the active docker context
114
+ // points to `~/.rd/docker.sock`. Follow that context so we bind-mount the
115
+ // correct socket; otherwise we fall back to the default location (real native
116
+ // Docker, Docker Desktop). Rancher Desktop runs the engine in a VM (Lima/WSL)
117
+ // on EVERY platform, so it is always 'remote'.
118
118
  const contextSocket = dockerContextSocket();
119
119
  const isRancher = isRancherDesktopSocket(contextSocket);
120
120
  return {
121
121
  name,
122
122
  socketPath: isRancher ? contextSocket : dockerSocketPath(),
123
123
  defaultNetwork: 'bridge',
124
- // Docker Desktop (macOS/Windows) en Rancher Desktop draaien in een VM;
125
- // native Docker op Linux niet.
124
+ // Docker Desktop (macOS/Windows) and Rancher Desktop run in a VM; native
125
+ // Docker on Linux does not.
126
126
  isRemote: isRancher || process.platform !== 'linux',
127
127
  securityOpts: [],
128
128
  };
@@ -147,9 +147,9 @@ function resolveRuntime(explicit) {
147
147
  }
148
148
  return buildRuntime(name);
149
149
  }
150
- // Auto-detectie: kijk eerst achter het `docker`-commando (dat een Podman-shim
151
- // kan zijn), daarna naar `podman`. Zo wint een echte Docker-engine als die er
152
- // is, maar herkennen we Podman ook als het zich als `docker` voordoet.
150
+ // Auto-detection: first look behind the `docker` command (which may be a
151
+ // Podman shim), then at `podman`. This way a real Docker engine wins if there
152
+ // is one, but we also recognize Podman when it poses as `docker`.
153
153
  const detected = detectEngine('docker') ?? detectEngine('podman');
154
154
  if (detected)
155
155
  return buildRuntime(detected);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "0.0.0-experiment-66.28.1",
3
+ "version": "0.0.0-experiment-66.30.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.",