@infosupport/huddle-cli 0.0.0-experiment-109.54.1 → 0.0.0-experiment-109.58.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/api.js +8 -1
- package/dist/index.js +1 -4
- package/dist/node.js +66 -7
- package/dist/sbx.js +0 -5
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -16,9 +16,16 @@ const node_1 = require("./node");
|
|
|
16
16
|
//
|
|
17
17
|
// An explicit --url or HUDDLE_URL replaces the list entirely — the operator named
|
|
18
18
|
// an address, and silently talking to a different one would be worse than failing.
|
|
19
|
+
//
|
|
20
|
+
// HUDDLE_PORT, when set, still has to flow through here: it is the same env var
|
|
21
|
+
// `huddle init`/`huddle node` read for a custom port (init.ts's HOST_PORT), so a
|
|
22
|
+
// custom port that stuck for the command that started Huddle Node must also
|
|
23
|
+
// stick for every command that talks to it afterwards — otherwise every command
|
|
24
|
+
// after `HUDDLE_PORT=<n> huddle init` probes the default port and never finds it.
|
|
25
|
+
const port = process.env.HUDDLE_PORT?.trim() || node_1.DEFAULT_NODE_PORT;
|
|
19
26
|
let candidates = (process.env.HUDDLE_URL
|
|
20
27
|
? [process.env.HUDDLE_URL]
|
|
21
|
-
: (0, node_1.nodeProbeUrls)(
|
|
28
|
+
: (0, node_1.nodeProbeUrls)(port)).map(normalizeBaseUrl);
|
|
22
29
|
let baseUrl = candidates[0];
|
|
23
30
|
class ApiError extends Error {
|
|
24
31
|
status;
|
package/dist/index.js
CHANGED
|
@@ -441,15 +441,12 @@ async function main() {
|
|
|
441
441
|
else if (subCmd === 'log') {
|
|
442
442
|
await (0, sbx_1.runSbxLog)({ name: positional[2] ?? flagString(flags, 'name') });
|
|
443
443
|
}
|
|
444
|
-
else if (subCmd === 'ingest') {
|
|
445
|
-
await (0, sbx_1.runSbxIngest)();
|
|
446
|
-
}
|
|
447
444
|
else if (subCmd === 'ssh-setup' || subCmd === 'ssh') {
|
|
448
445
|
await (0, sbx_1.runSbxSshSetup)();
|
|
449
446
|
}
|
|
450
447
|
else {
|
|
451
448
|
console.error(`Unknown sbx subcommand: ${subCmd}`);
|
|
452
|
-
console.error('Usage: huddle sbx <status|list|start|rm|reconcile|trust-ca|trust-host|ssh-setup|log
|
|
449
|
+
console.error('Usage: huddle sbx <status|list|start|rm|reconcile|trust-ca|trust-host|ssh-setup|log>');
|
|
453
450
|
process.exit(1);
|
|
454
451
|
}
|
|
455
452
|
return;
|
package/dist/node.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.nodeProbeUrls = nodeProbeUrls;
|
|
|
40
40
|
exports.readNodePid = readNodePid;
|
|
41
41
|
exports.readNodeControlHost = readNodeControlHost;
|
|
42
42
|
exports.isNodePidAlive = isNodePidAlive;
|
|
43
|
+
exports.pidLooksLikeHuddleNode = pidLooksLikeHuddleNode;
|
|
43
44
|
exports.pingNode = pingNode;
|
|
44
45
|
exports.waitForNode = waitForNode;
|
|
45
46
|
exports.stopNode = stopNode;
|
|
@@ -387,6 +388,31 @@ function isNodePidAlive() {
|
|
|
387
388
|
return false;
|
|
388
389
|
}
|
|
389
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Best-effort check that `pid` still names a Huddle Node process, not a pid the
|
|
393
|
+
* OS has since recycled for something unrelated. A pid file's only real
|
|
394
|
+
* guarantee is "this was Huddle Node's pid at the moment we wrote it" — pids
|
|
395
|
+
* wrap around, and once they do, isNodePidAlive() alone would say "yes, alive"
|
|
396
|
+
* about a completely different process. That matters twice here: stopNode()
|
|
397
|
+
* must not SIGTERM whatever now holds that pid, and startNodeDetached() must
|
|
398
|
+
* not treat an arbitrary process answering on the port as Huddle Node just
|
|
399
|
+
* because a stale pid file also happens to resolve to a live process.
|
|
400
|
+
*
|
|
401
|
+
* /proc/<pid>/cmdline is Linux-only. Elsewhere (macOS, Windows) this degrades
|
|
402
|
+
* to "assume yes" — the behavior every caller already had before this check
|
|
403
|
+
* existed — rather than blocking a platform that cannot answer the question.
|
|
404
|
+
*/
|
|
405
|
+
function pidLooksLikeHuddleNode(pid) {
|
|
406
|
+
try {
|
|
407
|
+
const cmdline = fs_1.default.readFileSync(`/proc/${pid}/cmdline`, 'utf8');
|
|
408
|
+
return cmdline.includes('huddle-node') || cmdline.includes(path_1.default.join('gateway', 'dist', 'index.js'));
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
// ENOENT means either "no /proc" (not Linux) or "pid is already gone" —
|
|
412
|
+
// neither is this function's to decide, so don't block the caller on it.
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
390
416
|
/**
|
|
391
417
|
* Is Huddle Node answering? /api/auth/status is the probe: it needs no operator
|
|
392
418
|
* token (api.ts keeps it public so the portal can find out whether login is
|
|
@@ -426,11 +452,17 @@ async function stopNode() {
|
|
|
426
452
|
const pid = readNodePid();
|
|
427
453
|
if (pid === null)
|
|
428
454
|
return false;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
455
|
+
// Guard against a stale pid file: if the OS has recycled this pid for an
|
|
456
|
+
// unrelated process since Huddle Node last wrote it, signaling it would kill
|
|
457
|
+
// that unrelated process instead of cleaning up Huddle Node. Skip straight to
|
|
458
|
+
// clearing the stale record rather than sending SIGTERM blind.
|
|
459
|
+
if (pidLooksLikeHuddleNode(pid)) {
|
|
460
|
+
try {
|
|
461
|
+
process.kill(pid, 'SIGTERM');
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
// Already gone. Clearing the pid file below is still the right cleanup.
|
|
465
|
+
}
|
|
434
466
|
}
|
|
435
467
|
try {
|
|
436
468
|
fs_1.default.unlinkSync(exports.NODE_PID_FILE);
|
|
@@ -488,6 +520,22 @@ async function startNodeDetached(opts = {}) {
|
|
|
488
520
|
if (!entry)
|
|
489
521
|
throw new MissingNodeEntryError(nodeEntryCandidates(__dirname)[0]);
|
|
490
522
|
if (await pingNode(port)) {
|
|
523
|
+
// A 200 on the port alone is not proof it's Huddle Node: /api/auth/status
|
|
524
|
+
// is deliberately unauthenticated (so the portal can ask "do I need to log
|
|
525
|
+
// in?"), which means any local process squatting the port before Huddle
|
|
526
|
+
// Node started would satisfy pingNode() too. init.ts hands the operator
|
|
527
|
+
// token to whatever this function says is "already running", so trusting
|
|
528
|
+
// that alone would let a squatter collect it. Require the pid THIS CLI
|
|
529
|
+
// itself recorded — only it can write NODE_PID_FILE, so a squatter cannot
|
|
530
|
+
// forge an entry there — to still look like Huddle Node before treating
|
|
531
|
+
// the port as genuinely owned.
|
|
532
|
+
const recordedPid = readNodePid();
|
|
533
|
+
if (recordedPid === null || !pidLooksLikeHuddleNode(recordedPid)) {
|
|
534
|
+
throw new Error(`Something is already answering on port ${port}, but it does not match the Huddle Node this CLI ` +
|
|
535
|
+
`started (no matching pid in ${exports.NODE_PID_FILE}).\n` +
|
|
536
|
+
` Refusing to treat it as Huddle Node and hand it credentials. Stop whatever is bound to that port ` +
|
|
537
|
+
`and re-run, or use a different port with --port.`);
|
|
538
|
+
}
|
|
491
539
|
const runningControlHost = normalizeControlHost(readNodeControlHost() ?? undefined);
|
|
492
540
|
if (runningControlHost === requestedControlHost) {
|
|
493
541
|
return { pid: readNodePid() ?? 0, entry: '(already running)', port, reused: true };
|
|
@@ -501,11 +549,22 @@ async function startNodeDetached(opts = {}) {
|
|
|
501
549
|
` Stop it manually (pid in ${exports.NODE_PID_FILE}) and re-run.`);
|
|
502
550
|
}
|
|
503
551
|
}
|
|
504
|
-
fs_1.default.mkdirSync(config_1.CONFIG_DIR, { recursive: true });
|
|
552
|
+
fs_1.default.mkdirSync(config_1.CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
505
553
|
fs_1.default.mkdirSync(nodeDataDir(opts), { recursive: true, mode: 0o700 });
|
|
506
554
|
// Append, not truncate: the log of the run that just failed is usually the
|
|
507
555
|
// thing you need after a restart.
|
|
508
|
-
|
|
556
|
+
//
|
|
557
|
+
// 0o600: this file is Huddle Node's own stdout/stderr, which can include the
|
|
558
|
+
// operator token (auth.ts prints it on first boot so the operator can log
|
|
559
|
+
// in). The mode only applies at creation, so an already-existing log from
|
|
560
|
+
// before this fix is re-tightened with chmod too — belt-and-suspenders
|
|
561
|
+
// against a background process's output otherwise landing in a
|
|
562
|
+
// world-readable file other local users can read the token out of.
|
|
563
|
+
const log = fs_1.default.openSync(exports.NODE_LOG_FILE, 'a', 0o600);
|
|
564
|
+
try {
|
|
565
|
+
fs_1.default.chmodSync(exports.NODE_LOG_FILE, 0o600);
|
|
566
|
+
}
|
|
567
|
+
catch { /* best effort, e.g. unsupported on this platform */ }
|
|
509
568
|
const launch = nodeLaunch(entry);
|
|
510
569
|
const child = (0, child_process_1.spawn)(launch.command, launch.args, {
|
|
511
570
|
env,
|
package/dist/sbx.js
CHANGED
|
@@ -42,7 +42,6 @@ exports.runSbxList = runSbxList;
|
|
|
42
42
|
exports.runSbxStart = runSbxStart;
|
|
43
43
|
exports.runSbxRemove = runSbxRemove;
|
|
44
44
|
exports.runSbxLog = runSbxLog;
|
|
45
|
-
exports.runSbxIngest = runSbxIngest;
|
|
46
45
|
exports.runSbxTrustCa = runSbxTrustCa;
|
|
47
46
|
exports.runSbxTrustHost = runSbxTrustHost;
|
|
48
47
|
exports.runSbxSshSetup = runSbxSshSetup;
|
|
@@ -145,10 +144,6 @@ async function runSbxLog(opts) {
|
|
|
145
144
|
if (r.denied.length === 0)
|
|
146
145
|
console.log((0, utils_1.dim)(' (parser matched nothing — paste the raw JSON above so the parser can be tuned)'));
|
|
147
146
|
}
|
|
148
|
-
async function runSbxIngest() {
|
|
149
|
-
const r = await (0, api_1.post)('/api/sbx/ingest', {});
|
|
150
|
-
console.log(`Ingested ${r.added} blocked request(s) from sbx → pending in Huddle.`);
|
|
151
|
-
}
|
|
152
147
|
async function runSbxTrustCa(opts) {
|
|
153
148
|
if (!opts.name) {
|
|
154
149
|
console.error('Usage: huddle sbx trust-ca <name>');
|
package/package.json
CHANGED