@tangle-network/sdk-cli-runner 0.3.12 → 0.3.13
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/index.d.mts +27 -1
- package/dist/index.mjs +52 -15
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -363,6 +363,32 @@ type ProcessIdentity = {
|
|
|
363
363
|
};
|
|
364
364
|
declare function readProcessIdentity(pid: number): ProcessIdentity | undefined;
|
|
365
365
|
//#endregion
|
|
366
|
+
//#region src/privilege-drop.d.ts
|
|
367
|
+
/** `toolDir` holds the host's trusted coreutils, named by `trustedToolPath`. */
|
|
368
|
+
declare function configurePrivilegeDrop(options: {
|
|
369
|
+
executable: string;
|
|
370
|
+
everyDemotion: boolean;
|
|
371
|
+
toolDir?: string;
|
|
372
|
+
}): void;
|
|
373
|
+
/** A helper tool by name: the trusted tool directory's, else `fallback`. */
|
|
374
|
+
declare function trustedToolPath(name: string, fallback: string): string;
|
|
375
|
+
/** The identity a root spawn must drop to through `setpriv`, if any. */
|
|
376
|
+
declare function privilegeDropIdentity(isolatedIdentity: {
|
|
377
|
+
uid: number;
|
|
378
|
+
gid: number;
|
|
379
|
+
} | undefined, spawnIdentity: {
|
|
380
|
+
uid?: number;
|
|
381
|
+
gid?: number;
|
|
382
|
+
} | undefined): {
|
|
383
|
+
uid: number;
|
|
384
|
+
gid: number;
|
|
385
|
+
} | undefined;
|
|
386
|
+
/** `[executable, args]` that run `command` as `identity` through `setpriv`. */
|
|
387
|
+
declare function privilegeDropCommand(identity: {
|
|
388
|
+
uid: number;
|
|
389
|
+
gid: number;
|
|
390
|
+
}, command: string, args: readonly string[]): [string, string[]];
|
|
391
|
+
//#endregion
|
|
366
392
|
//#region src/raw-capture.d.ts
|
|
367
393
|
/** Hard encoded-byte bound across canonical JSON spool files, including live writers.
|
|
368
394
|
* Temporary trim copies and filesystem allocation are separate from this budget.
|
|
@@ -593,5 +619,5 @@ declare function mergeSpawnEnv(base: NodeJS.ProcessEnv, overrides: Record<string
|
|
|
593
619
|
*/
|
|
594
620
|
declare function createStreamParser<T>(config: StreamParserConfig<T>): StreamParser<T>;
|
|
595
621
|
//#endregion
|
|
596
|
-
export { BridgeClosedError, type CliExecOptions, type CliExecResult, type CliExitResult, type CliLaunch, type CliLaunchSpec, type CliLauncher, type CliProcess, type CliSpawnConfig, type CliStdinValue, HELD_SPARE_IDLE_MS, type HeldSpare, type HeldSpareRegistry, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, type RawCaptureProcess, type RpcBridge, type RpcBridgeConfig, type RpcCloseReason, type RpcNotificationHandler, type RpcRequestHandler, type RpcRequestOptions, RpcRequestTimeoutError, type StreamParserConfig, allowRetainedRawCapture, argAfter, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, withRawCaptureAttempt, yieldUntilAdopted };
|
|
622
|
+
export { BridgeClosedError, type CliExecOptions, type CliExecResult, type CliExitResult, type CliLaunch, type CliLaunchSpec, type CliLauncher, type CliProcess, type CliSpawnConfig, type CliStdinValue, HELD_SPARE_IDLE_MS, type HeldSpare, type HeldSpareRegistry, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, type RawCaptureProcess, type RpcBridge, type RpcBridgeConfig, type RpcCloseReason, type RpcNotificationHandler, type RpcRequestHandler, type RpcRequestOptions, RpcRequestTimeoutError, type StreamParserConfig, allowRetainedRawCapture, argAfter, configurePrivilegeDrop, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, privilegeDropCommand, privilegeDropIdentity, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, trustedToolPath, withRawCaptureAttempt, yieldUntilAdopted };
|
|
597
623
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -167,6 +167,52 @@ var CliDeadlines = class {
|
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
//#endregion
|
|
170
|
+
//#region src/privilege-drop.ts
|
|
171
|
+
/**
|
|
172
|
+
* How a root executor drops to a CLI's identity: `setpriv` sets the uid and gid,
|
|
173
|
+
* clears the supplementary groups Node's own `uid`/`gid` spawn options keep,
|
|
174
|
+
* and sets no-new-privileges before exec. By default it is the image's
|
|
175
|
+
* `/usr/bin/setpriv`, used only for isolated identities. A host that must run
|
|
176
|
+
* no image code as root names its own trusted `setpriv` and drops every
|
|
177
|
+
* root spawn that names a uid through it; a missing one refuses the spawn.
|
|
178
|
+
*/
|
|
179
|
+
let privilegeDrop = {
|
|
180
|
+
executable: "/usr/bin/setpriv",
|
|
181
|
+
everyDemotion: false
|
|
182
|
+
};
|
|
183
|
+
/** `toolDir` holds the host's trusted coreutils, named by `trustedToolPath`. */
|
|
184
|
+
function configurePrivilegeDrop(options) {
|
|
185
|
+
if (!isAbsolute(options.executable) || options.toolDir !== void 0 && !isAbsolute(options.toolDir)) throw new Error("Privilege-drop paths must be absolute");
|
|
186
|
+
privilegeDrop = { ...options };
|
|
187
|
+
}
|
|
188
|
+
/** A helper tool by name: the trusted tool directory's, else `fallback`. */
|
|
189
|
+
function trustedToolPath(name, fallback) {
|
|
190
|
+
return privilegeDrop.toolDir ? `${privilegeDrop.toolDir}/${name}` : fallback;
|
|
191
|
+
}
|
|
192
|
+
/** The identity a root spawn must drop to through `setpriv`, if any. */
|
|
193
|
+
function privilegeDropIdentity(isolatedIdentity, spawnIdentity) {
|
|
194
|
+
if (isolatedIdentity) return isolatedIdentity;
|
|
195
|
+
const { uid, gid } = spawnIdentity ?? {};
|
|
196
|
+
return privilegeDrop.everyDemotion && process.getuid?.() === 0 && uid !== void 0 && gid !== void 0 && uid > 0 && gid > 0 ? {
|
|
197
|
+
uid,
|
|
198
|
+
gid
|
|
199
|
+
} : void 0;
|
|
200
|
+
}
|
|
201
|
+
/** `[executable, args]` that run `command` as `identity` through `setpriv`. */
|
|
202
|
+
function privilegeDropCommand(identity, command, args) {
|
|
203
|
+
return [privilegeDrop.executable, [
|
|
204
|
+
"--reuid",
|
|
205
|
+
String(identity.uid),
|
|
206
|
+
"--regid",
|
|
207
|
+
String(identity.gid),
|
|
208
|
+
"--clear-groups",
|
|
209
|
+
"--no-new-privs",
|
|
210
|
+
"--",
|
|
211
|
+
command,
|
|
212
|
+
...args
|
|
213
|
+
]];
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
170
216
|
//#region src/raw-capture.ts
|
|
171
217
|
/** Hard encoded-byte bound across canonical JSON spool files, including live writers.
|
|
172
218
|
* Temporary trim copies and filesystem allocation are separate from this budget.
|
|
@@ -1330,20 +1376,11 @@ function assertRawCaptureStdio(config) {
|
|
|
1330
1376
|
}
|
|
1331
1377
|
function spawnChild(config, processEnv, detached, stdout) {
|
|
1332
1378
|
const { command, args, cwd, spawnOptions, isolatedIdentity } = config;
|
|
1333
|
-
|
|
1334
|
-
|
|
1379
|
+
if (isolatedIdentity !== void 0 && (process.platform !== "linux" || process.getuid?.() !== 0 || !Number.isSafeInteger(isolatedIdentity.uid) || isolatedIdentity.uid <= 0 || !Number.isSafeInteger(isolatedIdentity.gid) || isolatedIdentity.gid <= 0 || spawnOptions?.uid !== isolatedIdentity.uid || spawnOptions?.gid !== isolatedIdentity.gid)) throw new Error("Isolated CLI identity requires a matching root-owned Linux launch");
|
|
1380
|
+
const dropTo = privilegeDropIdentity(isolatedIdentity, spawnOptions);
|
|
1335
1381
|
const { uid: _uid, gid: _gid, ...safeSpawnOptions } = spawnOptions ?? {};
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
String(isolatedIdentity.uid),
|
|
1339
|
-
"--regid",
|
|
1340
|
-
String(isolatedIdentity.gid),
|
|
1341
|
-
"--clear-groups",
|
|
1342
|
-
"--no-new-privs",
|
|
1343
|
-
"--",
|
|
1344
|
-
command,
|
|
1345
|
-
...args
|
|
1346
|
-
] : args, {
|
|
1382
|
+
const [executable, argv] = dropTo ? privilegeDropCommand(dropTo, command, args) : [command, args];
|
|
1383
|
+
return spawn(executable, argv, {
|
|
1347
1384
|
cwd,
|
|
1348
1385
|
env: processEnv,
|
|
1349
1386
|
stdio: [
|
|
@@ -1352,7 +1389,7 @@ function spawnChild(config, processEnv, detached, stdout) {
|
|
|
1352
1389
|
"pipe"
|
|
1353
1390
|
],
|
|
1354
1391
|
detached,
|
|
1355
|
-
...
|
|
1392
|
+
...dropTo ? safeSpawnOptions : spawnOptions,
|
|
1356
1393
|
...stdout ? { stdio: stdout.stdio(spawnOptions?.stdio) } : {}
|
|
1357
1394
|
});
|
|
1358
1395
|
}
|
|
@@ -2449,6 +2486,6 @@ function shellQuote(value) {
|
|
|
2449
2486
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
2450
2487
|
}
|
|
2451
2488
|
//#endregion
|
|
2452
|
-
export { BridgeClosedError, HELD_SPARE_IDLE_MS, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, RpcRequestTimeoutError, allowRetainedRawCapture, argAfter, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, withRawCaptureAttempt, yieldUntilAdopted };
|
|
2489
|
+
export { BridgeClosedError, HELD_SPARE_IDLE_MS, InvalidAttachmentError, JsonRpcError, RAW_CAPTURE_ROOT, RAW_CAPTURE_TOTAL_CAP_BYTES, RpcRequestTimeoutError, allowRetainedRawCapture, argAfter, configurePrivilegeDrop, createDeferredParser, createHeldSpareRegistry, createStreamParser, execCli, launchCliProcess, launchDifferences, mergeSpawnEnv, openRawCapture, privilegeDropCommand, privilegeDropIdentity, readProcessIdentity, removeRawCapture, resolveRawCapturePath, restoreTurnPriority, shellQuote, spawnCliProcess, spawnRpcBridge, summarizeRawCapture, trimRawCapture, trustedToolPath, withRawCaptureAttempt, yieldUntilAdopted };
|
|
2453
2490
|
|
|
2454
2491
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/sdk-cli-runner",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
4
4
|
"description": "Generic CLI process spawning with stdin/stdout streaming and JSONL parsing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org"
|
|
27
27
|
},
|
|
28
28
|
"tangleRelease": {
|
|
29
|
-
"sourceSha": "
|
|
30
|
-
"mergedAt": "2026-11-
|
|
29
|
+
"sourceSha": "14e91b253ce23c02d58a4af90dcfd9395e7c5a54",
|
|
30
|
+
"mergedAt": "2026-11-18T16:09:13-08:00"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsdown",
|