@infosupport/huddle-cli 0.0.0-experiment-66.28.1 → 0.0.0-experiment-66.29.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 +6 -6
- package/dist/init.js +7 -7
- package/dist/migrate.js +42 -2
- package/dist/runtime.js +37 -37
- package/package.json +1 -1
package/dist/firewall.js
CHANGED
|
@@ -59,11 +59,11 @@ async function reviewRule(rule, idx, total) {
|
|
|
59
59
|
async function resolveRule(rule, status, scope) {
|
|
60
60
|
await (0, api_1.post)(`/api/rules/${rule.id}/resolve`, { status, scope });
|
|
61
61
|
}
|
|
62
|
-
//
|
|
63
|
-
// (
|
|
64
|
-
// `/_packaging/*/nuget/v3/*`
|
|
65
|
-
// GUID).
|
|
66
|
-
//
|
|
62
|
+
// Creates a custom firewall rule. Supports wildcards: `*.` in the domain
|
|
63
|
+
// (e.g. `*.pkgs.dev.azure.com`) and `*` in the path pattern (e.g.
|
|
64
|
+
// `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a changing
|
|
65
|
+
// GUID). Defaults to 'allow'; --deny creates a block rule. Without --container
|
|
66
|
+
// the rule is global.
|
|
67
67
|
async function runFirewallAdd(opts) {
|
|
68
68
|
const domain = (opts.domain ?? '').trim();
|
|
69
69
|
if (!domain) {
|
|
@@ -108,7 +108,7 @@ async function runFirewallExport(opts) {
|
|
|
108
108
|
const json = JSON.stringify(doc, null, 2);
|
|
109
109
|
if (opts.out) {
|
|
110
110
|
fs_1.default.writeFileSync(opts.out, `${json}\n`);
|
|
111
|
-
//
|
|
111
|
+
// Progress to stderr so a pure `--out` run leaks nothing to stdout.
|
|
112
112
|
console.error((0, utils_1.green)(`[OK] Exported ${doc.rules.length} rule(s) to ${opts.out}`));
|
|
113
113
|
}
|
|
114
114
|
else {
|
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
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
//
|
|
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
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
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
|
|
472
|
-
//
|
|
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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* symlink/shim
|
|
24
|
-
* `docker --version`. Podman's `info
|
|
25
|
-
* Host.ServiceIsRemote; Docker's info
|
|
26
|
-
*
|
|
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
|
-
*
|
|
49
|
-
* context
|
|
50
|
-
* (dockerd/moby
|
|
51
|
-
* `Endpoints.docker.Host`
|
|
52
|
-
*
|
|
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
|
|
55
|
-
*
|
|
56
|
-
* tcp:// / ssh:// remote),
|
|
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`
|
|
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
|
-
//
|
|
76
|
-
// shell
|
|
77
|
-
// inspect` is
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
// ($(), backticks, ;, |,
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
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
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
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)
|
|
125
|
-
//
|
|
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-
|
|
151
|
-
//
|
|
152
|
-
// is,
|
|
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