@infosupport/huddle-cli 1.2.0 → 1.2.4

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/api.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.del = exports.put = exports.post = exports.get = exports.ApiError = void 0;
4
4
  exports.setBaseUrl = setBaseUrl;
5
5
  exports.apiCall = apiCall;
6
+ const config_1 = require("./config");
6
7
  let baseUrl = normalizeBaseUrl(process.env.HUDDLE_URL ?? 'http://localhost:3000');
7
8
  class ApiError extends Error {
8
9
  status;
@@ -17,11 +18,19 @@ function setBaseUrl(url) {
17
18
  baseUrl = normalizeBaseUrl(url);
18
19
  }
19
20
  async function apiCall(method, path, body) {
21
+ const headers = {};
22
+ if (body !== undefined)
23
+ headers['content-type'] = 'application/json';
24
+ // Operator-auth: stuur het token als Bearer mee zodat de CLI de control-plane
25
+ // -auth passeert. Zonder token krijgen we een 401 met een duidelijke hint.
26
+ const token = (0, config_1.operatorToken)();
27
+ if (token)
28
+ headers['authorization'] = `Bearer ${token}`;
20
29
  let res;
21
30
  try {
22
31
  res = await fetch(`${baseUrl}${path}`, {
23
32
  method,
24
- headers: body !== undefined ? { 'content-type': 'application/json' } : {},
33
+ headers,
25
34
  body: body !== undefined ? JSON.stringify(body) : undefined,
26
35
  });
27
36
  }
@@ -32,6 +41,10 @@ async function apiCall(method, path, body) {
32
41
  const raw = await res.text();
33
42
  const payload = parsePayload(raw);
34
43
  if (!res.ok) {
44
+ if (res.status === 401) {
45
+ throw new ApiError(`${method} ${path} -> 401: operator authentication required. ` +
46
+ `Set HUDDLE_OPERATOR_TOKEN (find it in the huddle container logs, or re-run \`huddle init\`).`, 401);
47
+ }
35
48
  const msg = errorMessage(payload) ?? res.statusText;
36
49
  throw new ApiError(`${method} ${path} -> ${res.status}: ${msg}`, res.status);
37
50
  }
package/dist/config.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.configPath = configPath;
7
7
  exports.readConfig = readConfig;
8
8
  exports.writeConfig = writeConfig;
9
+ exports.operatorToken = operatorToken;
9
10
  exports.activeExperiment = activeExperiment;
10
11
  exports.imageTag = imageTag;
11
12
  const fs_1 = __importDefault(require("fs"));
@@ -28,6 +29,14 @@ function writeConfig(config) {
28
29
  fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
29
30
  fs_1.default.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
30
31
  }
32
+ /** Operator-token voor API-auth: env wint, anders uit de config. */
33
+ function operatorToken() {
34
+ const env = process.env.HUDDLE_OPERATOR_TOKEN?.trim();
35
+ if (env)
36
+ return env;
37
+ const t = readConfig().operatorToken;
38
+ return t && t.trim() ? t.trim() : undefined;
39
+ }
31
40
  /** Active experiment number, or undefined when running on stable. */
32
41
  function activeExperiment() {
33
42
  const cfg = readConfig();
package/dist/init.js CHANGED
@@ -5,9 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runInit = runInit;
7
7
  const child_process_1 = require("child_process");
8
+ const crypto_1 = __importDefault(require("crypto"));
8
9
  const utils_1 = require("./utils");
9
10
  const runtime_1 = require("./runtime");
10
11
  const images_1 = require("./images");
12
+ const config_1 = require("./config");
11
13
  const fs_1 = __importDefault(require("fs"));
12
14
  const CONTAINER = 'huddle';
13
15
  const VOLUME = 'huddle-data';
@@ -83,10 +85,20 @@ async function runInit(opts, images) {
83
85
  // gateway and devcontainers across two filesystems, and Unix sockets are
84
86
  // unreliable on such a drvfs/9p mount anyway.
85
87
  const hostTmpSockets = '/tmp/dc-sockets';
86
- if (process.platform === 'win32') {
87
- // Cannot be created locally from Windows; the engine creates a missing
88
- // bind source itself in the VM on `run`.
89
- console.log((0, utils_1.dim)(` (Windows: the engine creates ${hostTmpSockets} in the VM)`));
88
+ if (runtime.isRemote) {
89
+ if (runtime.name === 'podman') {
90
+ // Podman does NOT create a missing bind source itself (unlike Docker
91
+ // Desktop) and fails with "statfs: no such file or directory". So create
92
+ // the directory explicitly in the machine VM; the socket lives there too.
93
+ console.log((0, utils_1.dim)(` (Podman: creating ${hostTmpSockets} in the machine VM)`));
94
+ if (!runSilent(`podman machine ssh "mkdir -p ${hostTmpSockets}"`)) {
95
+ console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets} in the Podman VM.`));
96
+ }
97
+ }
98
+ else {
99
+ // Docker Desktop creates a missing bind source itself in the VM on `run`.
100
+ console.log((0, utils_1.dim)(` (${runtime.name}: the engine creates ${hostTmpSockets} in the VM)`));
101
+ }
90
102
  }
91
103
  else {
92
104
  try {
@@ -97,16 +109,55 @@ async function runInit(opts, images) {
97
109
  }
98
110
  }
99
111
  console.log((0, utils_1.dim)(`Starting container`));
112
+ // The gateway is engine-agnostic (talks the Docker-compatible API on the
113
+ // mounted socket), but does need to know it's Podman: it then sets
114
+ // `--security-opt label=disable` on every devcontainer so it can reach the
115
+ // SELinux-labeled proxy socket.
116
+ const securityOptFlags = runtime.securityOpts.map((opt) => ` --security-opt ${opt}`).join('');
117
+ // Operator-token voor de control-plane-auth. Hergebruik het token uit de
118
+ // config (zodat een bestaande browser-sessie/CLI blijft werken over re-inits),
119
+ // anders genereer er één. We geven het aan de gateway mee via env én bewaren
120
+ // het lokaal zodat volgende `huddle`-commando's zich kunnen authenticeren.
121
+ const cfg = (0, config_1.readConfig)();
122
+ const operatorToken = process.env.HUDDLE_OPERATOR_TOKEN?.trim() ||
123
+ (cfg.operatorToken && cfg.operatorToken.trim()) ||
124
+ crypto_1.default.randomBytes(32).toString('base64url');
125
+ if (cfg.operatorToken !== operatorToken) {
126
+ (0, config_1.writeConfig)({ ...cfg, operatorToken });
127
+ }
128
+ // The container is created on the engine's default network first (with -p),
129
+ // then joins devcontainer-net (--internal) afterwards: Docker skips the host
130
+ // port-forward entirely when a container is created directly on an --internal
131
+ // network (moby/moby#36174). Which source IP the gateway sees for forwarded
132
+ // traffic no longer matters — the control plane authenticates with the
133
+ // operator token instead of source-IP filtering.
100
134
  run(`${rt} run -d` +
101
135
  ` --name ${CONTAINER}` +
102
- ` --network ${INTERNAL_NET}` +
136
+ ` --network ${runtime.defaultNetwork}` +
137
+ securityOptFlags +
138
+ ` -e HUDDLE_RUNTIME=${runtime.name}` +
139
+ ` -e HUDDLE_OPERATOR_TOKEN=${operatorToken}` +
103
140
  ` -p ${HOST_PORT}:3000` +
104
141
  ` -v ${VOLUME}:/data` +
105
142
  ` -v ${runtime.socketPath}:/var/run/docker.sock` +
106
143
  ` -v "${hostTmpSockets}:/tmp/dc-sockets"` +
107
144
  (0, images_1.gatewayEnvFlags)(images) +
108
145
  ` ${IMAGE}`);
109
- runSilent(`${rt} network connect ${runtime.defaultNetwork} ${CONTAINER}`);
146
+ // Attaching devcontainer-net after the container has started pollutes
147
+ // resolv.conf on Podman with that network's internal aardvark-DNS; the
148
+ // gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
149
+ // index.ts).
150
+ runSilent(`${rt} network connect ${INTERNAL_NET} ${CONTAINER}`);
110
151
  console.log();
111
152
  console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
153
+ console.log();
154
+ // Volledige auto-login-link: open deze en de portal logt je automatisch in met
155
+ // het operator-token (de frontend leest ?token=..., logt in en verwijdert het
156
+ // daarna uit de adresbalk). Zo hoef je niets te plakken.
157
+ const loginUrl = `http://localhost:${HOST_PORT}/?token=${encodeURIComponent(operatorToken)}`;
158
+ console.log((0, utils_1.bold)('Open the portal (auto-login link):'));
159
+ console.log((0, utils_1.green)(` ${loginUrl}`));
160
+ console.log((0, utils_1.dim)(' Opens the portal and logs you in automatically.'));
161
+ console.log((0, utils_1.dim)(` Manual token (if you prefer to paste it): ${operatorToken}`));
162
+ console.log((0, utils_1.dim)(' The token is also saved to ~/.huddle/config.json for the CLI.'));
112
163
  }
package/dist/runtime.js CHANGED
@@ -15,6 +15,22 @@ function isAvailable(runtime) {
15
15
  // 'info' only succeeds if the daemon/machine is actually reachable.
16
16
  return commandOutput(`${runtime} info`) !== undefined;
17
17
  }
18
+ /**
19
+ * Bepaalt de ECHTE engine achter een commando, of undefined als de engine niet
20
+ * bereikbaar is. Vertrouw niet op de commandonaam: `docker` is vaak een
21
+ * symlink/shim naar Podman (podman-docker) en Podman emuleert dan zelfs
22
+ * `docker --version`. Podman's `info` kent daarentegen het veld
23
+ * Host.ServiceIsRemote; Docker's info-schema niet. Dat is een betrouwbaar
24
+ * onderscheid dat ook via de shim werkt.
25
+ */
26
+ function detectEngine(command) {
27
+ if (commandOutput(`${command} info --format "{{.Host.ServiceIsRemote}}"`) !== undefined) {
28
+ return 'podman';
29
+ }
30
+ if (isAvailable(command))
31
+ return 'docker';
32
+ return undefined;
33
+ }
18
34
  function podmanSocketPath() {
19
35
  // Podman knows where its own (rootless or rootful) socket lives.
20
36
  const reported = commandOutput(`podman info --format "{{.Host.RemoteSocket.Path}}"`);
@@ -26,11 +42,30 @@ function podmanSocketPath() {
26
42
  function dockerSocketPath() {
27
43
  return process.platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock';
28
44
  }
45
+ function podmanIsRemote() {
46
+ // Op macOS/Windows draait Podman altijd in een `podman machine`-VM; ook op
47
+ // Linux kan de client op een remote socket wijzen. `ServiceIsRemote` is de
48
+ // gezaghebbende bron.
49
+ return commandOutput(`podman info --format "{{.Host.ServiceIsRemote}}"`) === 'true';
50
+ }
29
51
  function buildRuntime(name) {
30
52
  if (name === 'podman') {
31
- return { name, socketPath: podmanSocketPath(), defaultNetwork: 'podman' };
53
+ return {
54
+ name,
55
+ socketPath: podmanSocketPath(),
56
+ defaultNetwork: 'podman',
57
+ isRemote: podmanIsRemote(),
58
+ securityOpts: ['label=disable'],
59
+ };
32
60
  }
33
- return { name, socketPath: dockerSocketPath(), defaultNetwork: 'bridge' };
61
+ return {
62
+ name,
63
+ socketPath: dockerSocketPath(),
64
+ defaultNetwork: 'bridge',
65
+ // Docker Desktop (macOS/Windows) draait in een VM; native Docker op Linux niet.
66
+ isRemote: process.platform !== 'linux',
67
+ securityOpts: [],
68
+ };
34
69
  }
35
70
  function parseRuntimeName(value) {
36
71
  const normalized = value.toLowerCase().trim();
@@ -52,10 +87,12 @@ function resolveRuntime(explicit) {
52
87
  }
53
88
  return buildRuntime(name);
54
89
  }
55
- if (isAvailable('docker'))
56
- return buildRuntime('docker');
57
- if (isAvailable('podman'))
58
- return buildRuntime('podman');
90
+ // Auto-detectie: kijk eerst achter het `docker`-commando (dat een Podman-shim
91
+ // kan zijn), daarna naar `podman`. Zo wint een echte Docker-engine als die er
92
+ // is, maar herkennen we Podman ook als het zich als `docker` voordoet.
93
+ const detected = detectEngine('docker') ?? detectEngine('podman');
94
+ if (detected)
95
+ return buildRuntime(detected);
59
96
  throw new Error('No working container runtime found. Install and start Docker or Podman,\n' +
60
97
  'or pick one explicitly with --runtime <docker|podman> or the HUDDLE_RUNTIME env var.');
61
98
  }
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@infosupport/huddle-cli",
3
- "version": "1.2.0",
4
- "description": "Huddle CLI \u2014 start devcontainers and manage firewall rules",
3
+ "version": "1.2.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.",
7
7
  "homepage": "https://github.com/infosupport/huddle",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/infosupport/huddle.git",
10
+ "url": "git+https://github.com/infosupport/huddle.git",
11
11
  "directory": "cli"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/infosupport/huddle/issues"
15
15
  },
16
16
  "bin": {
17
- "huddle": "./dist/index.js"
17
+ "huddle": "dist/index.js"
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsc",