@infosupport/huddle-cli 0.0.0-experiment-98.43.1 → 0.0.0-experiment-98.44.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 +11 -20
- package/dist/images.js +13 -9
- package/dist/init.js +36 -31
- package/package.json +1 -1
package/dist/firewall.js
CHANGED
|
@@ -160,21 +160,25 @@ async function runFirewallExport(opts) {
|
|
|
160
160
|
console.log(json);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
|
|
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(
|
|
168
|
+
raw = fs_1.default.readFileSync(file, 'utf8');
|
|
167
169
|
}
|
|
168
170
|
catch {
|
|
169
|
-
throw new Error(`Cannot read ${
|
|
171
|
+
throw new Error(`Cannot read ${file}`);
|
|
170
172
|
}
|
|
171
|
-
let doc;
|
|
172
173
|
try {
|
|
173
|
-
|
|
174
|
+
return JSON.parse(raw);
|
|
174
175
|
}
|
|
175
176
|
catch {
|
|
176
|
-
throw new Error(`${
|
|
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
|
-
|
|
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`));
|
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.
|
|
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`
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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/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
|
-
|
|
33
|
-
|
|
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
|
|
39
|
+
function runArgsSilent(file, args) {
|
|
36
40
|
try {
|
|
37
|
-
(0, child_process_1.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
+
runArgsSilent(rt, ['volume', 'inspect', VOLUME]) || runArgs(rt, ['volume', 'create', VOLUME]);
|
|
90
94
|
console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
|
|
91
|
-
|
|
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
|
-
|
|
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 (!
|
|
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
|
|
@@ -151,33 +154,35 @@ async function runInit(opts, images) {
|
|
|
151
154
|
// path so the gateway reads it without knowing the host path. Read-only.
|
|
152
155
|
const fwFolder = cfg.firewallRulesFolder?.trim();
|
|
153
156
|
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
157
|
if (fwFolder)
|
|
158
158
|
console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
|
|
159
159
|
if (extFolder)
|
|
160
160
|
console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
// Build the container command as an argv array (runArgs → execFileSync, no
|
|
162
|
+
// shell). The folder paths below come from config and are operator-writable via
|
|
163
|
+
// the settings API, so they must never reach a shell as a string.
|
|
164
|
+
const dockerArgs = ['run', '-d', '--name', CONTAINER, '--network', runtime.defaultNetwork];
|
|
165
|
+
for (const opt of runtime.securityOpts)
|
|
166
|
+
dockerArgs.push('--security-opt', opt);
|
|
167
|
+
dockerArgs.push('-e', `HUDDLE_RUNTIME=${runtime.name}`);
|
|
168
|
+
dockerArgs.push('-e', `HUDDLE_OPERATOR_TOKEN=${operatorToken}`);
|
|
169
|
+
dockerArgs.push('-p', `${HOST_PORT}:3000`);
|
|
170
|
+
dockerArgs.push('-v', `${VOLUME}:/data`);
|
|
171
|
+
dockerArgs.push('-v', `${runtime.socketPath}:/var/run/docker.sock`);
|
|
172
|
+
dockerArgs.push('-v', `${hostTmpSockets}:/tmp/dc-sockets`);
|
|
173
|
+
dockerArgs.push('-v', `${config_1.CONFIG_DIR}:/huddle-home:rw`, '-e', 'HUDDLE_HOME_DIR=/huddle-home');
|
|
174
|
+
if (fwFolder)
|
|
175
|
+
dockerArgs.push('-v', `${fwFolder}:/firewall-rules:ro`);
|
|
176
|
+
if (extFolder)
|
|
177
|
+
dockerArgs.push('-v', `${extFolder}:/extensions:ro`);
|
|
178
|
+
dockerArgs.push(...(0, images_1.gatewayEnvArgs)(images));
|
|
179
|
+
dockerArgs.push(IMAGE);
|
|
180
|
+
runArgs(rt, dockerArgs);
|
|
176
181
|
// Attaching devcontainer-net after the container has started pollutes
|
|
177
182
|
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
178
183
|
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
179
184
|
// index.ts).
|
|
180
|
-
|
|
185
|
+
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, CONTAINER]);
|
|
181
186
|
console.log();
|
|
182
187
|
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
183
188
|
console.log();
|
package/package.json
CHANGED