barebox 0.6.0 → 0.7.0
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/CHANGELOG.md +20 -0
- package/README.md +2 -2
- package/barebox.context.md +9 -4
- package/package.json +1 -1
- package/primitives.json +1 -1
- package/src/cli.js +3 -1
- package/src/launcher.js +41 -28
- package/src/overlay.js +3 -3
- package/src/proxy.js +42 -5
- package/src/runtime.js +22 -0
- package/src/secrets.js +8 -0
- package/types/launcher.d.ts +4 -2
- package/types/runtime.d.ts +18 -0
- package/types/secrets.d.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
|
|
7
|
+
## [0.7.0] - 2026-11-01
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- The agent's `node` is the host's: the Node install that runs barebox (`process.execPath`, or `launch({ nodeExec })`) is bound read-only and its `bin` dir put first on the inside `PATH` when it lives outside `/usr`, `$HOME` and the project (nvm, fnm, asdf, a CI toolcache). An exec in a `bin/` dir binds the dir above it, where npm and global CLIs live; any other layout binds only its own dir. It is never bound when that dir is `/`, `$HOME` or above it (then it is not on `PATH` either, and `sbx run` says so on stderr).
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- A secret's placeholder in the URL path or query is refused `403 denied: secret.url` in every mode, before the gate. Keys are swapped in headers only; before, the placeholder was sent as is and the API answered 401 with no hint why.
|
|
16
|
+
- A runtime or project under the bound Node install is safe: the runtime is masked like one under `$HOME` (its `asks/`, `answers/` and `socks/` are not visible), a project there keeps its overlay writable, and `launch()` throws when the runtime IS the Node install dir (or `/etc`, `/usr`).
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Node's built-in `fetch` to an `http://` URL failed inside the sandbox (`UND_ERR_SOCKET`), local models such as Ollama included: with `NODE_USE_ENV_PROXY=1` Node tunnels plain http with `CONNECT`, and the proxy treated every tunnel as TLS. The first byte inside a tunnel now decides; plain HTTP is checked like any request (a placeholder there gets `403 denied: secret.scheme`). A certificate is minted only for a TLS tunnel; a plain one mints nothing. The same holds when the first bytes (a TLS ClientHello, or a plain request) arrive in the same write as the `CONNECT` line: the hello was dropped and the handshake never answered.
|
|
21
|
+
- `node` (and npm-installed CLIs) from nvm, fnm or a toolcache were `not found` inside the sandbox (exit 127).
|
|
22
|
+
|
|
23
|
+
### Security
|
|
24
|
+
|
|
25
|
+
- A locked drawer or `maskDirs` folder under `/etc` or `/usr` (or the bound Node install) is now hidden like one under `$HOME`; before, only paths under `$HOME` and the project were masked, so such a folder stayed readable.
|
|
26
|
+
|
|
7
27
|
## [0.6.0] - 2026-11-01
|
|
8
28
|
|
|
9
29
|
### Added
|
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ Put the key in `~/.config/barebox/config.json`, bound to its hosts:
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
Inside the sandbox `$STRIPE_API_KEY` is a random placeholder, new each run. The agent sends it as it would the key (`curl -H "Authorization: Bearer $STRIPE_API_KEY"`, `curl -u "$STRIPE_API_KEY:"`). The proxy swaps the real value into the request headers only after the request is allowed, and only for `api.stripe.com`. A denied request never leaves. The same placeholder sent to any other host is refused: `403 denied: secret.host`. A real value is swapped only into a request that goes upstream over TLS: a placeholder to a bound host over plain `http://` is refused `403 denied: secret.scheme`. The rest of your environment stays out too, except a short default list (`TERM`, `LANG`, `LC_*`, `TZ`, ...) and the names in `env.pass`; `env.pass` refuses names like `*_TOKEN` and `*_KEY` (use `secrets`).
|
|
91
|
+
Inside the sandbox `$STRIPE_API_KEY` is a random placeholder, new each run. The agent sends it as it would the key (`curl -H "Authorization: Bearer $STRIPE_API_KEY"`, `curl -u "$STRIPE_API_KEY:"`). The proxy swaps the real value into the request headers only after the request is allowed, and only for `api.stripe.com`. A denied request never leaves. The same placeholder sent to any other host is refused: `403 denied: secret.host`. A real value is swapped only into a request that goes upstream over TLS: a placeholder to a bound host over plain `http://` is refused `403 denied: secret.scheme`. The rest of your environment stays out too, except a short default list (`TERM`, `LANG`, `LC_*`, `TZ`, ...) and the names in `env.pass`; `env.pass` refuses names like `*_TOKEN` and `*_KEY` (use `secrets`; a harmless match such as `XKB_KEYMAP` goes in `env.set`). Keys are swapped in headers only: a placeholder in the URL is refused `403 denied: secret.url`. Details: `barebox.context.md`.
|
|
92
92
|
|
|
93
93
|
## Numbers
|
|
94
94
|
|
|
@@ -126,7 +126,7 @@ M0–M2 are the go/no-go. Later: macOS (`sandbox-exec` + APFS clones), Windows v
|
|
|
126
126
|
npm install barebox
|
|
127
127
|
```
|
|
128
128
|
|
|
129
|
-
Requires Node.js >= 22.21. Two production dependencies, [bareguard](https://npmjs.com/package/bareguard) (the gate) and [rwxmap](https://npmjs.com/package/rwxmap) (the labels), pinned exactly. Needs bubblewrap >= 0.11.0 for `--overlay` / `sbx diff|commit|rollback` (Ubuntu 24.04 ships 0.9.0: build from source or use a newer distro); plain runs work with older bwrap. CI builds bubblewrap 0.12.0 from a checksum-pinned source tarball
|
|
129
|
+
Requires Node.js >= 22.21. Two production dependencies, [bareguard](https://npmjs.com/package/bareguard) (the gate) and [rwxmap](https://npmjs.com/package/rwxmap) (the labels), pinned exactly. Needs bubblewrap >= 0.11.0 for `--overlay` / `sbx diff|commit|rollback` (Ubuntu 24.04 ships 0.9.0: build from source or use a newer distro); plain runs work with older bwrap. CI builds bubblewrap 0.12.0 from a checksum-pinned source tarball (`scripts/ci-runner-deps.sh`) and fails if any test is skipped. The host's Node runs inside the sandbox: one under `$HOME` (a default nvm) or `/usr` is already visible, and one outside both (a CI toolcache, a Node with `HOME` set elsewhere) is bound read-only, with its `bin` dir first on the inside `PATH`. A runtime or project under that bound install stays hidden or writable as it would elsewhere. The API is in [`barebox.context.md`](barebox.context.md) and `primitives.json` (both ship in the package); the `sbx` CLI comes with it.
|
|
130
130
|
|
|
131
131
|
## Try the POCs
|
|
132
132
|
|
package/barebox.context.md
CHANGED
|
@@ -158,7 +158,7 @@ private/loopback check, never link-local (cloud metadata).
|
|
|
158
158
|
## Keys the agent never holds
|
|
159
159
|
|
|
160
160
|
The sandbox does not get your environment. The agent sees only barebox's own
|
|
161
|
-
variables (`HOME`, `PATH`, the proxy and CA variables, `NODE_USE_ENV_PROXY=1`), a short default list
|
|
161
|
+
variables (`HOME`, `PATH`, the proxy and CA variables, `NODE_USE_ENV_PROXY=1`, so Node's `fetch` reaches `http://` and `https://` URLs, local models included, through the proxy), a short default list
|
|
162
162
|
(`TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`, `TZ`, `USER`, `LOGNAME`,
|
|
163
163
|
`SHELL`, `EDITOR`, `PAGER`), the host variables you name in `env.pass`, the
|
|
164
164
|
values in `env.set`, and one placeholder per secret. Nothing else reaches it,
|
|
@@ -195,7 +195,9 @@ values in `env.set`, and one placeholder per secret. Nothing else reaches it,
|
|
|
195
195
|
- A real value is swapped only into a request that goes upstream over TLS. A
|
|
196
196
|
placeholder to a bound host over plain http is refused in every mode, before
|
|
197
197
|
the gate: `403 denied: secret.scheme`. Nothing goes upstream.
|
|
198
|
-
- Headers only. A key in a body
|
|
198
|
+
- Headers only. A key in a body is not swapped. A placeholder in the URL (path
|
|
199
|
+
or query string) is refused in every mode, before the gate: `403 denied:
|
|
200
|
+
secret.url`. Nothing goes upstream.
|
|
199
201
|
- Audit: one `annotate` line per hit, `verdict: "secret"`,
|
|
200
202
|
`meta: { agent, rid, name, host, swapped }`, joined to the gate line by
|
|
201
203
|
`rid`. The value is never written to the audit, an ask file or an error body.
|
|
@@ -225,6 +227,9 @@ hands the real value to the agent.
|
|
|
225
227
|
|
|
226
228
|
`<runtime>/gate.jsonl` (`runtimePaths(runtime).audit`; `run()` returns it as
|
|
227
229
|
`audit`) is the only log, one JSON object per line, all in bareguard's shape.
|
|
230
|
+
It is never rotated. `sbx run` without `SBX_RUNTIME` gets a fresh runtime, so a
|
|
231
|
+
fresh log, each run; with a reused `SBX_RUNTIME` the file keeps growing: delete
|
|
232
|
+
it between runs (no proxy running) to start a new one.
|
|
228
233
|
- Decisions: bareguard's gate lines carry the action (`method`, `url`, `tool`,
|
|
229
234
|
`agent`, `rid`) and an `aid`.
|
|
230
235
|
- Response status: a `phase:"record"` line with the same `aid` and
|
|
@@ -275,7 +280,7 @@ Model endpoints are `r` (free in every mode): `api.anthropic.com`
|
|
|
275
280
|
`POST /v1/messages` and `/v1/messages/count_tokens`; `api.openai.com`
|
|
276
281
|
`POST /v1/chat/completions`, `/v1/responses` and `/v1/embeddings`; and on each
|
|
277
282
|
`localLlm` host:port `POST /api/chat`, `/api/generate`, `/api/embed`,
|
|
278
|
-
`/v1/chat/completions` and `/v1/completions` (http
|
|
283
|
+
`/v1/chat/completions` and `/v1/completions` (over http or https). Any other path on
|
|
279
284
|
those hosts is a normal `POST`.
|
|
280
285
|
|
|
281
286
|
Label folders are hidden inside the sandbox like the config file, so the agent
|
|
@@ -319,7 +324,7 @@ The overlay needs bubblewrap >= 0.11.0 for `--overlay` / `sbx diff|commit|rollba
|
|
|
319
324
|
- The upstream wall answers `403` for loopback, link-local (incl. `169.254.169.254`), the host's own addresses, private LAN ranges and unresolvable names. An IPv4 embedded in IPv6 is checked in every spelling: mapped, compat, uncompressed, NAT64 `64:ff9b::/96` (local-use `/48` denied outright) and 6to4 `2002::/16`; NAT64 and 6to4 of public sites stay reachable. Every DNS answer is checked and the dial is pinned to the checked IP; test-only options live under `unsafeTestOnly` (`allowLoopback`, `resolveUpstream`) and production never sets them.
|
|
320
325
|
- `createProxy` throws synchronously on an unopenable `logFile` (a directory, a missing parent, no permission) and releases the runtime. The runtime root, `asks/`, `answers/`, `held/` and `socks/` are owner-only (`0700`) whatever the umask. An existing runtime dir you own is tightened to `0700`; one you don't own (such as `/tmp`) is refused with an error naming the dir and its owner and suggesting a subdir like `/tmp/sbx`. The audit file (`logFile`, `gate.jsonl`) is set to `0600` every time a proxy starts. No request header and no body content is written to it: a body is logged as its length and SHA-256 only. The ask payload's `bodyPreview` (the first 4 KB, card numbers masked except the last 4) lives in the ask file only; other secrets inside a body still show there until bareguard redaction lands. Your `redact` hook shapes the `meta` of barebox's own annotate lines.
|
|
321
326
|
- One proxy per runtime: `createProxy` throws "in use by pid N" (`run()` rejects, `sbx run` exits 1) while a live proxy owns the runtime. The claim is held by the proxy process and the kernel frees it when the process dies, so a crashed proxy never blocks the runtime. Use another `SBX_RUNTIME`, or leave it unset for a fresh one.
|
|
322
|
-
- `launch()` starts the agent in the project dir, in a new session (no controlling terminal). Locked drawers are 21 credential stores (see `LOCKED_PATHS` in `src/launcher.js`); the agent's own model credentials in `~/.claude` stay readable (a known gap: its sign-in tokens refresh themselves, so `secrets` does not cover them). The host environment does not reach the inside: callers that relied on an inherited variable list it in `env.pass` (or pass `launch({ env })` / `extraEnv`). `launch()` finds `bwrap` on your `PATH` but starts it with a fixed `PATH`.
|
|
327
|
+
- `launch()` starts the agent in the project dir, in a new session (no controlling terminal). Locked drawers are 21 credential stores (see `LOCKED_PATHS` in `src/launcher.js`); the agent's own model credentials in `~/.claude` stay readable (a known gap: its sign-in tokens refresh themselves, so `secrets` does not cover them). The host environment does not reach the inside: callers that relied on an inherited variable list it in `env.pass` (or pass `launch({ env })` / `extraEnv`). `launch()` finds `bwrap` on your `PATH` but starts it with a fixed `PATH`. The sandbox sees `/usr`, `/etc`, `$HOME` and the project read-only; the Node you run barebox with is visible too: a Node outside those (nvm, a CI toolcache) has its install bound read-only and its dir first on the inside `PATH`, so `node` and global CLIs run inside. A node in a `bin/` dir binds the dir above it; any other layout binds only the node's own dir. It is never bound when that dir is `/`, `$HOME` or above it; then its dir is not on `PATH` either and `sbx run` prints `barebox: not exposing Node at <dir> ...` on stderr (the sandbox uses `/usr/bin/node` if present). `launch({ nodeExec })` overrides `process.execPath`. Locked drawers and `maskDirs` folders are hidden wherever they sit under any of these (`/etc` and the Node install included). So is the runtime tree: a runtime under any of them gets an empty mask, and a runtime that IS `/etc`, `/usr` or the Node install dir throws. A project under the Node install keeps its overlay (the install is bound before it).
|
|
323
328
|
- `sbx` exits 0 ok, 1 unknown id / refused / no live proxy / run failure, 2 usage; `sbx run` mirrors the agent's exit code.
|
|
324
329
|
- Any listening unix socket under `$HOME` (IDE IPC, rootless-container sockets) is reachable from inside the sandbox: a read-only bind does not block `connect(2)`; the locked-paths list is the lever.
|
|
325
330
|
|
package/package.json
CHANGED
package/primitives.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"when": "Reach for this to HARNESS-ONLY start one sandboxed agent run: it creates the sandbox the agent lives in. It does not decide anything; combine with the proxy for the front door and the gate (M3) for policy. Pass overlay:true for a writable tracing-paper run (M4). The agent starts in the project dir.",
|
|
35
35
|
"import": "import { launch } from 'barebox'",
|
|
36
36
|
"signature": "launch(opts: object) => ChildProcess",
|
|
37
|
-
"fails": "Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME` or the
|
|
37
|
+
"fails": "Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME`, the project dir, `/etc`, `/usr` or the bound Node install dir (its sockets could not be hidden from the agent), or with overlay on when the runtime sits inside the project or uncommitted changes linger. The child fails at runtime (nonzero exit) when `bwrap` or `socat` is missing inside, or when nothing listens on the agent socket.",
|
|
38
38
|
"example": "import { launch } from \"barebox\";\nconst child = launch({ runtime: \"/tmp/sbx\", agent: \"fx\", proj: \"/tmp/proj\", command: [\"bash\", \"-c\", \"echo hi\"] });\nawait new Promise((r) => child.on(\"close\", r)); // child.exitCode === 0"
|
|
39
39
|
},
|
|
40
40
|
{
|
package/src/cli.js
CHANGED
|
@@ -36,7 +36,7 @@ import { MODES } from './policy.js';
|
|
|
36
36
|
import { writeFileAtomic } from './holds.js';
|
|
37
37
|
import { run as sandboxRun } from './run.js';
|
|
38
38
|
import { diffOverlay, commitOverlay, rollbackOverlay } from './overlay.js';
|
|
39
|
-
import { assertAgentName, createRuntime, runtimePaths, runtimeLive, safe, shellQuote } from './runtime.js';
|
|
39
|
+
import { assertAgentName, createRuntime, hostNode, runtimePaths, runtimeLive, safe, shellQuote } from './runtime.js';
|
|
40
40
|
|
|
41
41
|
const USAGE = 'usage: sbx [--help] | pending | approve <id> | deny <id> [reason] | diff [--agent <name>] | commit [--agent <name>] [--skip-conflicts] | rollback [--agent <name>] | run [--mode ask|auto|trust] [--json] [--overlay] -- <cmd> [...]';
|
|
42
42
|
|
|
@@ -186,6 +186,8 @@ async function run(args) {
|
|
|
186
186
|
const json = values.json ?? false;
|
|
187
187
|
const overlay = values.overlay ?? false;
|
|
188
188
|
const runtime = process.env.SBX_RUNTIME || createRuntime();
|
|
189
|
+
const node = hostNode(process.execPath, process.env.HOME || '/root', process.cwd());
|
|
190
|
+
if (node.refused) err(`barebox: not exposing Node at ${node.dir} (${node.refused}); the sandbox uses /usr/bin/node if present`);
|
|
189
191
|
// Agent-controlled bytes, sanitized before they reach a terminal or a JSON consumer.
|
|
190
192
|
const clean = (o, keys) => {
|
|
191
193
|
const c = { ...o };
|
package/src/launcher.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { accessSync, constants, existsSync, lstatSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { join, relative, dirname, delimiter } from 'node:path';
|
|
8
|
-
import { assertAgentName, isInside, realPathOf, runtimePaths } from './runtime.js';
|
|
8
|
+
import { assertAgentName, hostNode, isInside, realPathOf, runtimePaths } from './runtime.js';
|
|
9
9
|
import { assertOverlaySupport, setupOverlay } from './overlay.js';
|
|
10
10
|
import { configPath } from './config.js';
|
|
11
11
|
|
|
@@ -47,28 +47,30 @@ const LOCKED_PATHS = [
|
|
|
47
47
|
'.cargo/credentials.toml',
|
|
48
48
|
];
|
|
49
49
|
|
|
50
|
+
const SYSTEM_PATH = ['/usr/bin', '/bin', '/usr/sbin'];
|
|
51
|
+
|
|
50
52
|
/**
|
|
51
53
|
* The bwrap args that mask one locked path, or none when it does not exist.
|
|
52
54
|
* A symlinked drawer (dotfile managers) is masked at its real target, which
|
|
53
55
|
* is where bwrap lands a mount anyway, so the content is shut at both
|
|
54
|
-
* spellings; a target outside
|
|
55
|
-
*
|
|
56
|
+
* spellings; a target outside every bound root is not in the sandbox at all,
|
|
57
|
+
* so there is nothing to mask.
|
|
56
58
|
*
|
|
57
|
-
* @param {string} abs the locked path (under
|
|
58
|
-
* @param {string}
|
|
59
|
-
* @param {string} proj project dir
|
|
59
|
+
* @param {string} abs the locked path (under a bound root to matter)
|
|
60
|
+
* @param {string[]} roots the paths the sandbox binds in: `$HOME`, the project, `/etc`, `/usr` and the Node install
|
|
60
61
|
* @returns {string[]} `--tmpfs <dir>` or `--dev-bind /dev/null <file>`, or `[]`
|
|
61
62
|
*/
|
|
62
|
-
function lockMask(abs,
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
function lockMask(abs, roots) {
|
|
64
|
+
const bound = (p) => roots.some((r) => isInside(r, p));
|
|
65
|
+
// Under no bound root: not in the sandbox at all.
|
|
66
|
+
if (!bound(abs)) return [];
|
|
65
67
|
let target = abs;
|
|
66
68
|
let st;
|
|
67
69
|
try {
|
|
68
70
|
st = lstatSync(abs);
|
|
69
71
|
if (st.isSymbolicLink()) {
|
|
70
72
|
target = realPathOf(abs);
|
|
71
|
-
if (!
|
|
73
|
+
if (!bound(target)) return [];
|
|
72
74
|
st = statSync(target);
|
|
73
75
|
}
|
|
74
76
|
} catch {
|
|
@@ -155,19 +157,20 @@ export function buildCaBundle(runtime, caFile) {
|
|
|
155
157
|
* @param {{ pass?: string[], set?: Record<string, string>, placeholders?: Record<string, string> }} [opts.env] the inside's environment (M5). The host environment never reaches it except: a short default list (`TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`, `TZ`, `USER`, `LOGNAME`, `SHELL`, `EDITOR`, `PAGER`), the host variables named in `pass`, the values in `set`, and one placeholder per secret under its own name (`placeholders`, name to value). Set in that order, then `extraEnv`.
|
|
156
158
|
* @param {string|null} [opts.socket] agent socket path, as returned by `proxy.addAgent` (default `<runtime>/socks/<agent>.sock`; the two must agree)
|
|
157
159
|
* @param {string|null} [opts.caFile] barebox CA cert path (from `proxy.caFile`); when set, the sandbox trusts it for HTTPS alongside the system roots
|
|
160
|
+
* @param {string} [opts.nodeExec] the node executable to run inside (default: this process's `process.execPath`). The install is a `bin/` layout's parent dir (npm and global CLIs live there) or, for any other layout, the exec's own dir. It is bound read-only with the exec's dir first on the inside PATH, unless already visible there (under `/usr`, `$HOME` or the project). Never bound when it is `/`, `$HOME` or above it: then it is not on PATH either (see `hostNode` in `src/runtime.js`). A runtime or project under the install is masked or mounted over it, so the bind never exposes either
|
|
158
161
|
* @param {string[]} [opts.maskDirs] extra folders hidden from the agent exactly like barebox's config dir (the `labels` folders: the agent must not read or rewrite a letter)
|
|
159
162
|
* @param {boolean} [opts.overlay] when true, mount a per-run overlay upper over the project (M4 tracing paper) instead of binding it read-only; diff/commit/rollback address it as `runtimePaths(runtime).overlay(agent)`
|
|
160
163
|
* @param {string[]} [opts.overlayIgnore] path segments invisible to the overlay (default `node_modules`; see overlay.js Q3)
|
|
161
164
|
* @returns {import('node:child_process').ChildProcess} the bwrap child (stdio piped); `close` gives its exit code
|
|
162
165
|
* @when Reach for this to HARNESS-ONLY start one sandboxed agent run: it creates the sandbox the agent lives in. It does not decide anything; combine with the proxy for the front door and the gate (M3) for policy. Pass overlay:true for a writable tracing-paper run (M4). The agent starts in the project dir.
|
|
163
|
-
* @fails Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME` or the
|
|
166
|
+
* @fails Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME`, the project dir, `/etc`, `/usr` or the bound Node install dir (its sockets could not be hidden from the agent), or with overlay on when the runtime sits inside the project or uncommitted changes linger. The child fails at runtime (nonzero exit) when `bwrap` or `socat` is missing inside, or when nothing listens on the agent socket.
|
|
164
167
|
* @example
|
|
165
168
|
* import { launch } from "barebox";
|
|
166
169
|
* const child = launch({ runtime: "/tmp/sbx", agent: "fx", proj: "/tmp/proj", command: ["bash", "-c", "echo hi"] });
|
|
167
170
|
* await new Promise((r) => child.on("close", r)); // child.exitCode === 0
|
|
168
171
|
*/
|
|
169
172
|
export function launch({ runtime, agent, proj, command, proxyPort = 3128,
|
|
170
|
-
extraEnv = {}, env = {}, socket = null, caFile = null, overlay = false, overlayIgnore, maskDirs = [] }) {
|
|
173
|
+
extraEnv = {}, env = {}, socket = null, caFile = null, overlay = false, overlayIgnore, maskDirs = [], nodeExec = process.execPath }) {
|
|
171
174
|
for (const [k, v] of Object.entries({ runtime, agent, proj })) {
|
|
172
175
|
if (typeof v !== 'string' || !v) throw new Error(`launch: ${k} must be a non-empty string`);
|
|
173
176
|
}
|
|
@@ -195,6 +198,12 @@ export function launch({ runtime, agent, proj, command, proxyPort = 3128,
|
|
|
195
198
|
ov = setupOverlay({ runtime, agent, proj, ignore: overlayIgnore });
|
|
196
199
|
}
|
|
197
200
|
const home = process.env.HOME || '/root';
|
|
201
|
+
// A Node outside /usr and $HOME (nvm, a CI toolcache) is bound read-only too, so the host's
|
|
202
|
+
// node and its global CLIs run inside.
|
|
203
|
+
const { bin: nodeBin, bind: nodeBind } = hostNode(nodeExec, home, proj);
|
|
204
|
+
// Every path the sandbox binds in from the host: the locked drawers and mask folders are
|
|
205
|
+
// hidden wherever they sit under one of these.
|
|
206
|
+
const roots = [home, proj, '/etc', '/usr', ...(nodeBind ? [nodeBind] : [])];
|
|
198
207
|
const args = [
|
|
199
208
|
'--unshare-pid', '--unshare-uts', '--unshare-ipc', '--unshare-net',
|
|
200
209
|
'--die-with-parent',
|
|
@@ -202,7 +211,11 @@ export function launch({ runtime, agent, proj, command, proxyPort = 3128,
|
|
|
202
211
|
'--ro-bind', '/usr', '/usr',
|
|
203
212
|
'--symlink', 'usr/lib64', '/lib64',
|
|
204
213
|
'--ro-bind', '/etc', '/etc',
|
|
205
|
-
//
|
|
214
|
+
// The Node install first: a project or runtime inside it must win over it.
|
|
215
|
+
// It never holds $HOME and is never inside $HOME, /usr or the project (then
|
|
216
|
+
// it is not bound), so the only overlap is a project or runtime under it.
|
|
217
|
+
...(nodeBind ? ['--ro-bind', nodeBind, nodeBind] : []),
|
|
218
|
+
// $HOME next, the project after: a project under $HOME would otherwise
|
|
206
219
|
// vanish under the home bind (bwrap mounts cover what is below them —
|
|
207
220
|
// the later mount wins where they overlap). The project mount (overlay
|
|
208
221
|
// or read-only) therefore lands on top of the read-only home.
|
|
@@ -222,12 +235,12 @@ export function launch({ runtime, agent, proj, command, proxyPort = 3128,
|
|
|
222
235
|
// Locked drawers AFTER the project mount: the tmpfs mask must land on top,
|
|
223
236
|
// or a project that contains one of these paths (a project that IS $HOME,
|
|
224
237
|
// or holds its own `.ssh`) would leak the real drawer through the overlay.
|
|
225
|
-
for (const p of LOCKED_PATHS) args.push(...lockMask(`${home}/${p}`,
|
|
238
|
+
for (const p of LOCKED_PATHS) args.push(...lockMask(`${home}/${p}`, roots));
|
|
226
239
|
// barebox's own config: settings the agent must neither read nor edit.
|
|
227
240
|
// Masked wherever it resolves (XDG_CONFIG_HOME may move it).
|
|
228
|
-
args.push(...lockMask(dirname(configPath(process.env)),
|
|
241
|
+
args.push(...lockMask(dirname(configPath(process.env)), roots));
|
|
229
242
|
// The label folders (the letters live there) get the same mask.
|
|
230
|
-
for (const d of maskDirs) args.push(...lockMask(d,
|
|
243
|
+
for (const d of maskDirs) args.push(...lockMask(d, roots));
|
|
231
244
|
// The runtime tree holds the file-checkpoint dirs (`asks/`, `answers/`
|
|
232
245
|
// — the approve/deny capability) and every agent's socket (identity). A
|
|
233
246
|
// read-only bind does NOT stop connect(2) to a unix socket, so wherever
|
|
@@ -246,21 +259,21 @@ export function launch({ runtime, agent, proj, command, proxyPort = 3128,
|
|
|
246
259
|
// resolved), so a runtime passed as a symlink from outside $HOME/proj
|
|
247
260
|
// can still land inside it and stay visible through the ro-binds — the
|
|
248
261
|
// mask below covers that spelling too.
|
|
249
|
-
|
|
250
|
-
const
|
|
262
|
+
// Every root the sandbox binds: (real path, the spelling bwrap sees).
|
|
263
|
+
const bases = roots.map((r) => [realPathOf(join(r)), join(r)]);
|
|
251
264
|
const realRt = realPathOf(join(runtime));
|
|
252
|
-
const realHm = realPathOf(hm);
|
|
253
|
-
const realPr = realPathOf(pr);
|
|
254
265
|
// One real-path comparison: a lexically-equal spelling resolves to the
|
|
255
266
|
// same real path, so it is subsumed here.
|
|
256
|
-
|
|
257
|
-
|
|
267
|
+
const same = bases.findIndex(([realBase]) => realRt === realBase);
|
|
268
|
+
if (same >= 0) {
|
|
269
|
+
const what = same === 0 ? 'HOME' : same === 1 ? 'the project dir' : roots[same] === nodeBind ? 'the Node install dir' : roots[same];
|
|
270
|
+
throw new Error(`launch: runtime must not be ${what} itself (its sockets cannot be hidden there)`);
|
|
258
271
|
}
|
|
259
|
-
// Mask the sandbox-visible spelling join(
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
for (const [realBase, baseSpelling] of
|
|
263
|
-
if (
|
|
272
|
+
// Mask the sandbox-visible spelling join(root, relative(realRoot, realRt)):
|
|
273
|
+
// where nothing is a symlink this IS the lexical path, so no separate
|
|
274
|
+
// lexical mask is needed.
|
|
275
|
+
for (const [realBase, baseSpelling] of bases) {
|
|
276
|
+
if (isInside(realBase, realRt)) {
|
|
264
277
|
const m = join(baseSpelling, relative(realBase, realRt));
|
|
265
278
|
if (!args.includes(m)) args.push('--tmpfs', m);
|
|
266
279
|
}
|
|
@@ -279,7 +292,7 @@ export function launch({ runtime, agent, proj, command, proxyPort = 3128,
|
|
|
279
292
|
}
|
|
280
293
|
args.push(
|
|
281
294
|
'--setenv', 'HOME', home,
|
|
282
|
-
'--setenv', 'PATH', '
|
|
295
|
+
'--setenv', 'PATH', (!nodeBin || SYSTEM_PATH.includes(nodeBin) ? SYSTEM_PATH : [nodeBin, ...SYSTEM_PATH]).join(':'),
|
|
283
296
|
'--setenv', 'HTTP_PROXY', `http://127.0.0.1:${proxyPort}`,
|
|
284
297
|
'--setenv', 'HTTPS_PROXY', `http://127.0.0.1:${proxyPort}`,
|
|
285
298
|
'--setenv', 'http_proxy', `http://127.0.0.1:${proxyPort}`,
|
package/src/overlay.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from 'node:fs';
|
|
19
19
|
import { join, dirname } from 'node:path';
|
|
20
20
|
import { fileURLToPath } from 'node:url';
|
|
21
|
-
import { assertAgentName, runtimeTempDir, runtimePaths, safe } from './runtime.js';
|
|
21
|
+
import { assertAgentName, hostNode, runtimeTempDir, runtimePaths, safe } from './runtime.js';
|
|
22
22
|
|
|
23
23
|
/** One reviewed file change: what the sandbox did at `path`, and whether the project changed underneath it mid-run.
|
|
24
24
|
*
|
|
@@ -468,8 +468,8 @@ function bwrapWalk({ lower, upper, work, ignore, scratch, stageDir = null, upper
|
|
|
468
468
|
// /usr). Its prefix is bound read-only when /usr does not already show it.
|
|
469
469
|
const node = realpathSync(process.execPath);
|
|
470
470
|
const underUsr = node === '/usr' || node.startsWith('/usr/');
|
|
471
|
-
|
|
472
|
-
const nodePrefix =
|
|
471
|
+
// Only the install dir: this trusted walker binds even `/` (see below), so `refused` is ignored.
|
|
472
|
+
const nodePrefix = hostNode(node, process.env.HOME || '/root').dir;
|
|
473
473
|
try {
|
|
474
474
|
// No output cap (stdout carries no data) and no time limit: the walk
|
|
475
475
|
// is finite (`lstat`, never following symlinks), and killing a commit's
|
package/src/proxy.js
CHANGED
|
@@ -23,7 +23,7 @@ import { ASK_BODY_LIMIT, DEFAULT_HOLD_MAX_BODY, bodyPreview, createHolds } from
|
|
|
23
23
|
import { claimRuntime, ensurePrivateDir, runtimePaths } from './runtime.js';
|
|
24
24
|
import { paymentPath, toolFor, buildTools, emptyMatcher } from './policy.js';
|
|
25
25
|
import { checkUpstream } from './wall.js';
|
|
26
|
-
import { findPlaceholders, applySecrets } from './secrets.js';
|
|
26
|
+
import { findPlaceholders, urlPlaceholders, applySecrets } from './secrets.js';
|
|
27
27
|
import { Gate } from 'bareguard';
|
|
28
28
|
|
|
29
29
|
const AGENT = Symbol('agent');
|
|
@@ -685,6 +685,15 @@ export function createProxy(opts) {
|
|
|
685
685
|
denyRes(cres, 403, 'denied: secret.scheme');
|
|
686
686
|
return;
|
|
687
687
|
}
|
|
688
|
+
// Keys are swapped in headers only: a placeholder in the URL is refused,
|
|
689
|
+
// not sent as a literal that the API would answer 401 for no visible reason.
|
|
690
|
+
const inUrl = secrets.length ? urlPlaceholders(url.pathname + url.search, secrets) : [];
|
|
691
|
+
if (inUrl.length) {
|
|
692
|
+
for (const name of inUrl) log({ ev: 'secret', agent, rid, name, host: url.hostname, swapped: false });
|
|
693
|
+
try { creq.resume(); } catch {}
|
|
694
|
+
denyRes(cres, 403, 'denied: secret.url');
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
688
697
|
/** The headers to forward: the real values in, one audit line per swap. @param {Record<string, string | string[] | undefined>} headers */
|
|
689
698
|
const withSecrets = (headers) => {
|
|
690
699
|
if (!found.length) return headers;
|
|
@@ -898,6 +907,9 @@ export function createProxy(opts) {
|
|
|
898
907
|
sock.removeListener('data', onData);
|
|
899
908
|
sock.setTimeout(0); // the http.Server owns idle from here
|
|
900
909
|
if (method === 'CONNECT') {
|
|
910
|
+
// Whoever removes the last data listener pauses: a flowing socket with no
|
|
911
|
+
// listener drops what arrives (a hello sent before the 200) and what is pushed back.
|
|
912
|
+
sock.pause();
|
|
901
913
|
handleConnect(sock, target, buf.subarray(i + 4), agent);
|
|
902
914
|
} else {
|
|
903
915
|
// Plain HTTP (absolute- or origin-form): same parser, same handler.
|
|
@@ -924,17 +936,42 @@ export function createProxy(opts) {
|
|
|
924
936
|
denyRaw(sock, 403, verdict.reason);
|
|
925
937
|
return;
|
|
926
938
|
}
|
|
939
|
+
if (closed || sock.destroyed) return;
|
|
940
|
+
try { sock.write('HTTP/1.1 200 Connection established\r\n\r\n'); }
|
|
941
|
+
catch { return; }
|
|
942
|
+
// One reader of the first byte: 0x16 is a TLS handshake (decrypt it);
|
|
943
|
+
// anything else is plain HTTP inside the tunnel (Node's fetch tunnels
|
|
944
|
+
// http:// URLs too) and goes to the server as it is, as `admit` does.
|
|
945
|
+
let first = rest;
|
|
946
|
+
if (!first.length) {
|
|
947
|
+
sock.setTimeout(clientIdleMs, () => sock.destroy());
|
|
948
|
+
first = await new Promise((resolve) => {
|
|
949
|
+
const done = (c) => { sock.off('data', done); sock.off('close', gone); sock.pause(); resolve(c); };
|
|
950
|
+
const gone = () => done(Buffer.alloc(0));
|
|
951
|
+
sock.on('data', done);
|
|
952
|
+
sock.on('close', gone);
|
|
953
|
+
sock.resume(); // paused by admit
|
|
954
|
+
});
|
|
955
|
+
sock.setTimeout(0);
|
|
956
|
+
if (!first.length || closed || sock.destroyed) return;
|
|
957
|
+
}
|
|
958
|
+
sock.unshift(first); // paused: admit paused it, and `done` pauses again
|
|
959
|
+
if (first[0] !== 0x16) {
|
|
960
|
+
sock.resume(); // the http server only adds a data listener
|
|
961
|
+
server.emit('connection', sock);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
// The cert is minted only for a TLS tunnel. The 200 is already sent, so a
|
|
965
|
+
// failure cannot answer 502: it is logged as the deny it would have been.
|
|
927
966
|
let creds;
|
|
928
967
|
try {
|
|
929
968
|
creds = await certFor(certDir, host);
|
|
930
969
|
} catch (e) {
|
|
931
|
-
|
|
970
|
+
log({ ev: 'deny', agent: agentOf(sock), code: 502, note: `no cert for ${host}: ${e.message}` });
|
|
971
|
+
sock.destroy();
|
|
932
972
|
return;
|
|
933
973
|
}
|
|
934
974
|
if (closed || sock.destroyed) return;
|
|
935
|
-
try { sock.write('HTTP/1.1 200 Connection established\r\n\r\n'); }
|
|
936
|
-
catch { return; }
|
|
937
|
-
if (rest.length) sock.unshift(rest);
|
|
938
975
|
const st = new tls.TLSSocket(sock, { isServer: true, key: creds.key, cert: creds.cert });
|
|
939
976
|
st[AGENT] = agent;
|
|
940
977
|
st[SECURE] = true;
|
package/src/runtime.js
CHANGED
|
@@ -67,6 +67,28 @@ export function isInside(base, p) {
|
|
|
67
67
|
return realP.startsWith(prefix);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Where the host's node sits and what of it to bind so it runs inside the sandbox. An exec in a
|
|
72
|
+
* `bin/` dir (nvm, fnm, toolcache, distro) has its install one dir up, where npm and the global
|
|
73
|
+
* CLIs live; any other layout is its own dir. Never `/`, `$HOME` or an ancestor of it: binding
|
|
74
|
+
* that would hand the sandbox the whole host or every user's home, so it is `refused` and
|
|
75
|
+
* neither bound nor put on PATH.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} execPath absolute path of the node executable
|
|
78
|
+
* @param {string} home the sandbox $HOME
|
|
79
|
+
* @param {string} [proj] the project dir, already visible inside
|
|
80
|
+
* @returns {{dir: string, bin: string|null, bind: string|null, refused: string|null}} `dir` the install folder; `bin` the PATH entry (null when refused); `bind` the dir to bind read-only (null when refused or already under `/usr`, `$HOME` or the project); `refused` a short reason or null
|
|
81
|
+
*/
|
|
82
|
+
export function hostNode(execPath, home, proj) {
|
|
83
|
+
const bin = path.dirname(execPath);
|
|
84
|
+
const dir = path.basename(bin) === 'bin' ? path.dirname(bin) : bin;
|
|
85
|
+
if (isInside(dir, home)) { // `/` is inside-of-everything: it lands here too
|
|
86
|
+
return { dir, bin: null, bind: null, refused: 'it contains $HOME or is /' };
|
|
87
|
+
}
|
|
88
|
+
const visible = ['/usr', home, ...(proj ? [proj] : [])].some((r) => isInside(r, dir));
|
|
89
|
+
return { dir, bin, bind: visible ? null : dir, refused: null };
|
|
90
|
+
}
|
|
91
|
+
|
|
70
92
|
/**
|
|
71
93
|
* Create a short-lived runtime dir: a short `sbx-` temp dir, keeping unix
|
|
72
94
|
* socket paths under the ~108-char limit.
|
package/src/secrets.js
CHANGED
|
@@ -66,6 +66,14 @@ function swapIn(v, s) {
|
|
|
66
66
|
return v;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Which secrets' placeholders sit in a request URL (path and query). Keys are swapped in headers only.
|
|
71
|
+
* @param {string} pathAndQuery @param {Secret[]} secrets @returns {string[]} the secrets' names
|
|
72
|
+
*/
|
|
73
|
+
export function urlPlaceholders(pathAndQuery, secrets) {
|
|
74
|
+
return secrets.filter((s) => pathAndQuery.includes(s.placeholder)).map((s) => s.name);
|
|
75
|
+
}
|
|
76
|
+
|
|
69
77
|
/**
|
|
70
78
|
* Which placeholders a request carries, and whether each is headed for a host its secret is bound to.
|
|
71
79
|
* Each header value is searched as a substring and, for `Basic <base64>`, decoded.
|
package/types/launcher.d.ts
CHANGED
|
@@ -30,18 +30,19 @@ export function buildCaBundle(runtime: string, caFile: string): string;
|
|
|
30
30
|
* @param {{ pass?: string[], set?: Record<string, string>, placeholders?: Record<string, string> }} [opts.env] the inside's environment (M5). The host environment never reaches it except: a short default list (`TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`, `TZ`, `USER`, `LOGNAME`, `SHELL`, `EDITOR`, `PAGER`), the host variables named in `pass`, the values in `set`, and one placeholder per secret under its own name (`placeholders`, name to value). Set in that order, then `extraEnv`.
|
|
31
31
|
* @param {string|null} [opts.socket] agent socket path, as returned by `proxy.addAgent` (default `<runtime>/socks/<agent>.sock`; the two must agree)
|
|
32
32
|
* @param {string|null} [opts.caFile] barebox CA cert path (from `proxy.caFile`); when set, the sandbox trusts it for HTTPS alongside the system roots
|
|
33
|
+
* @param {string} [opts.nodeExec] the node executable to run inside (default: this process's `process.execPath`). The install is a `bin/` layout's parent dir (npm and global CLIs live there) or, for any other layout, the exec's own dir. It is bound read-only with the exec's dir first on the inside PATH, unless already visible there (under `/usr`, `$HOME` or the project). Never bound when it is `/`, `$HOME` or above it: then it is not on PATH either (see `hostNode` in `src/runtime.js`). A runtime or project under the install is masked or mounted over it, so the bind never exposes either
|
|
33
34
|
* @param {string[]} [opts.maskDirs] extra folders hidden from the agent exactly like barebox's config dir (the `labels` folders: the agent must not read or rewrite a letter)
|
|
34
35
|
* @param {boolean} [opts.overlay] when true, mount a per-run overlay upper over the project (M4 tracing paper) instead of binding it read-only; diff/commit/rollback address it as `runtimePaths(runtime).overlay(agent)`
|
|
35
36
|
* @param {string[]} [opts.overlayIgnore] path segments invisible to the overlay (default `node_modules`; see overlay.js Q3)
|
|
36
37
|
* @returns {import('node:child_process').ChildProcess} the bwrap child (stdio piped); `close` gives its exit code
|
|
37
38
|
* @when Reach for this to HARNESS-ONLY start one sandboxed agent run: it creates the sandbox the agent lives in. It does not decide anything; combine with the proxy for the front door and the gate (M3) for policy. Pass overlay:true for a writable tracing-paper run (M4). The agent starts in the project dir.
|
|
38
|
-
* @fails Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME` or the
|
|
39
|
+
* @fails Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME`, the project dir, `/etc`, `/usr` or the bound Node install dir (its sockets could not be hidden from the agent), or with overlay on when the runtime sits inside the project or uncommitted changes linger. The child fails at runtime (nonzero exit) when `bwrap` or `socat` is missing inside, or when nothing listens on the agent socket.
|
|
39
40
|
* @example
|
|
40
41
|
* import { launch } from "barebox";
|
|
41
42
|
* const child = launch({ runtime: "/tmp/sbx", agent: "fx", proj: "/tmp/proj", command: ["bash", "-c", "echo hi"] });
|
|
42
43
|
* await new Promise((r) => child.on("close", r)); // child.exitCode === 0
|
|
43
44
|
*/
|
|
44
|
-
export function launch({ runtime, agent, proj, command, proxyPort, extraEnv, env, socket, caFile, overlay, overlayIgnore, maskDirs }: {
|
|
45
|
+
export function launch({ runtime, agent, proj, command, proxyPort, extraEnv, env, socket, caFile, overlay, overlayIgnore, maskDirs, nodeExec }: {
|
|
45
46
|
runtime: string;
|
|
46
47
|
agent: string;
|
|
47
48
|
proj: string;
|
|
@@ -55,6 +56,7 @@ export function launch({ runtime, agent, proj, command, proxyPort, extraEnv, env
|
|
|
55
56
|
} | undefined;
|
|
56
57
|
socket?: string | null | undefined;
|
|
57
58
|
caFile?: string | null | undefined;
|
|
59
|
+
nodeExec?: string | undefined;
|
|
58
60
|
maskDirs?: string[] | undefined;
|
|
59
61
|
overlay?: boolean | undefined;
|
|
60
62
|
overlayIgnore?: string[] | undefined;
|
package/types/runtime.d.ts
CHANGED
|
@@ -23,6 +23,24 @@ export function realPathOf(p: string): string;
|
|
|
23
23
|
* @returns {boolean} containment on real paths
|
|
24
24
|
*/
|
|
25
25
|
export function isInside(base: string, p: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Where the host's node sits and what of it to bind so it runs inside the sandbox. An exec in a
|
|
28
|
+
* `bin/` dir (nvm, fnm, toolcache, distro) has its install one dir up, where npm and the global
|
|
29
|
+
* CLIs live; any other layout is its own dir. Never `/`, `$HOME` or an ancestor of it: binding
|
|
30
|
+
* that would hand the sandbox the whole host or every user's home, so it is `refused` and
|
|
31
|
+
* neither bound nor put on PATH.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} execPath absolute path of the node executable
|
|
34
|
+
* @param {string} home the sandbox $HOME
|
|
35
|
+
* @param {string} [proj] the project dir, already visible inside
|
|
36
|
+
* @returns {{dir: string, bin: string|null, bind: string|null, refused: string|null}} `dir` the install folder; `bin` the PATH entry (null when refused); `bind` the dir to bind read-only (null when refused or already under `/usr`, `$HOME` or the project); `refused` a short reason or null
|
|
37
|
+
*/
|
|
38
|
+
export function hostNode(execPath: string, home: string, proj?: string): {
|
|
39
|
+
dir: string;
|
|
40
|
+
bin: string | null;
|
|
41
|
+
bind: string | null;
|
|
42
|
+
refused: string | null;
|
|
43
|
+
};
|
|
26
44
|
/**
|
|
27
45
|
* Create a short-lived runtime dir: a short `sbx-` temp dir, keeping unix
|
|
28
46
|
* socket paths under the ~108-char limit.
|
package/types/secrets.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export function loadSecrets(config?: Record<string, {
|
|
|
11
11
|
value?: string;
|
|
12
12
|
hosts: string[];
|
|
13
13
|
}>, env?: NodeJS.ProcessEnv): Secret[];
|
|
14
|
+
/**
|
|
15
|
+
* Which secrets' placeholders sit in a request URL (path and query). Keys are swapped in headers only.
|
|
16
|
+
* @param {string} pathAndQuery @param {Secret[]} secrets @returns {string[]} the secrets' names
|
|
17
|
+
*/
|
|
18
|
+
export function urlPlaceholders(pathAndQuery: string, secrets: Secret[]): string[];
|
|
14
19
|
/**
|
|
15
20
|
* Which placeholders a request carries, and whether each is headed for a host its secret is bound to.
|
|
16
21
|
* Each header value is searched as a substring and, for `Basic <base64>`, decoded.
|