barebox 0.5.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 +42 -0
- package/README.md +19 -4
- package/barebox.context.md +81 -8
- package/package.json +2 -2
- package/primitives.json +11 -2
- package/src/cli.js +5 -3
- package/src/config.js +53 -2
- package/src/index.js +1 -0
- package/src/labels.js +6 -0
- package/src/launcher.js +82 -33
- package/src/overlay.js +3 -3
- package/src/policy.js +4 -1
- package/src/proxy.js +76 -8
- package/src/run.js +11 -3
- package/src/runtime.js +22 -0
- package/src/secrets.js +121 -0
- package/types/config.d.ts +20 -2
- package/types/index.d.ts +1 -0
- package/types/labels.d.ts +6 -0
- package/types/launcher.d.ts +11 -3
- package/types/proxy.d.ts +5 -0
- package/types/run.d.ts +30 -2
- package/types/runtime.d.ts +18 -0
- package/types/secrets.d.ts +68 -0
package/types/config.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export function configPath(env?: NodeJS.ProcessEnv): string;
|
|
|
9
9
|
* Read the config file over the defaults. No file means defaults.
|
|
10
10
|
*
|
|
11
11
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
12
|
-
* @returns {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
12
|
+
* @returns {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
13
13
|
* @throws {Error} naming the file (and the key) on invalid JSON, an unknown key or a bad value
|
|
14
14
|
*/
|
|
15
15
|
export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
@@ -19,6 +19,15 @@ export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
|
19
19
|
labels: string[];
|
|
20
20
|
tenants: Record<string, string[]>;
|
|
21
21
|
heldBodyMaxMB?: number;
|
|
22
|
+
env?: {
|
|
23
|
+
pass?: string[];
|
|
24
|
+
set?: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
secrets?: Record<string, {
|
|
27
|
+
fromEnv?: string;
|
|
28
|
+
value?: string;
|
|
29
|
+
hosts: string[];
|
|
30
|
+
}>;
|
|
22
31
|
};
|
|
23
32
|
/**
|
|
24
33
|
* Settings for one `sbx run`: a CLI flag beats the file, the file beats the default.
|
|
@@ -26,7 +35,7 @@ export function loadConfig(env?: NodeJS.ProcessEnv): {
|
|
|
26
35
|
* @param {object} [flags] values given on the command line
|
|
27
36
|
* @param {string} [flags.mode] `--mode`
|
|
28
37
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
29
|
-
* @returns {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
38
|
+
* @returns {{ mode: string, holdTimeoutSec: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
30
39
|
* @throws {Error} as {@link loadConfig}
|
|
31
40
|
*/
|
|
32
41
|
export function resolveConfig(flags?: {
|
|
@@ -38,4 +47,13 @@ export function resolveConfig(flags?: {
|
|
|
38
47
|
labels: string[];
|
|
39
48
|
tenants: Record<string, string[]>;
|
|
40
49
|
heldBodyMaxMB?: number;
|
|
50
|
+
env?: {
|
|
51
|
+
pass?: string[];
|
|
52
|
+
set?: Record<string, string>;
|
|
53
|
+
};
|
|
54
|
+
secrets?: Record<string, {
|
|
55
|
+
fromEnv?: string;
|
|
56
|
+
value?: string;
|
|
57
|
+
hosts: string[];
|
|
58
|
+
}>;
|
|
41
59
|
};
|
package/types/index.d.ts
CHANGED
package/types/labels.d.ts
CHANGED
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
* @param {NodeJS.ProcessEnv} [env] environment for `$HOME`
|
|
10
10
|
* @returns {{ matcher: ReturnType<typeof matcherFrom>, tools: Record<string, any>, dirs: string[] }} `dirs` are the absolute folders (the launcher masks them)
|
|
11
11
|
* @throws {Error} naming the file or folder on a missing gate or review file, a duplicate key, an unknown tenant vendor or a bad sidecar
|
|
12
|
+
* @when Reach for this to build the `labels` value `run()` and `createProxy()` take: it reads rwxmap label folders once at startup and returns the request matcher, the tools table (letters from each gate file) and the absolute folders.
|
|
13
|
+
* @fails Throws, naming the file or folder, on a folder with no review file, a review file without its gate file, a duplicate key across vendors, a tenants vendor no folder defines, an unreadable folder, or a label file written before rwxmap 0.8.0.
|
|
14
|
+
* @example
|
|
15
|
+
* import { loadLabels, run } from "barebox";
|
|
16
|
+
* const labels = loadLabels({ labels: ["/home/me/labels/jira"], tenants: { jira: ["https://acme.atlassian.net"] } });
|
|
17
|
+
* await run({ proj: "/tmp/proj", command: ["bash", "-c", "true"], labels });
|
|
12
18
|
*/
|
|
13
19
|
export function loadLabels({ labels, tenants }: {
|
|
14
20
|
labels?: string[] | undefined;
|
package/types/launcher.d.ts
CHANGED
|
@@ -26,29 +26,37 @@ export function buildCaBundle(runtime: string, caFile: string): string;
|
|
|
26
26
|
* @param {string} opts.proj project directory, bound read-only
|
|
27
27
|
* @param {string[]} opts.command argv to run inside, for example `["python3", "agent.py"]`
|
|
28
28
|
* @param {number} [opts.proxyPort] front-door port inside the sandbox (default 3128)
|
|
29
|
-
* @param {object} [opts.extraEnv] extra environment entries for the inside
|
|
29
|
+
* @param {object} [opts.extraEnv] extra environment entries for the inside, set last (they win)
|
|
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`.
|
|
30
31
|
* @param {string|null} [opts.socket] agent socket path, as returned by `proxy.addAgent` (default `<runtime>/socks/<agent>.sock`; the two must agree)
|
|
31
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
|
|
32
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)
|
|
33
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)`
|
|
34
36
|
* @param {string[]} [opts.overlayIgnore] path segments invisible to the overlay (default `node_modules`; see overlay.js Q3)
|
|
35
37
|
* @returns {import('node:child_process').ChildProcess} the bwrap child (stdio piped); `close` gives its exit code
|
|
36
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.
|
|
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
|
|
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.
|
|
38
40
|
* @example
|
|
39
41
|
* import { launch } from "barebox";
|
|
40
42
|
* const child = launch({ runtime: "/tmp/sbx", agent: "fx", proj: "/tmp/proj", command: ["bash", "-c", "echo hi"] });
|
|
41
43
|
* await new Promise((r) => child.on("close", r)); // child.exitCode === 0
|
|
42
44
|
*/
|
|
43
|
-
export function launch({ runtime, agent, proj, command, proxyPort, extraEnv, socket, caFile, overlay, overlayIgnore, maskDirs }: {
|
|
45
|
+
export function launch({ runtime, agent, proj, command, proxyPort, extraEnv, env, socket, caFile, overlay, overlayIgnore, maskDirs, nodeExec }: {
|
|
44
46
|
runtime: string;
|
|
45
47
|
agent: string;
|
|
46
48
|
proj: string;
|
|
47
49
|
command: string[];
|
|
48
50
|
proxyPort?: number | undefined;
|
|
49
51
|
extraEnv?: object;
|
|
52
|
+
env?: {
|
|
53
|
+
pass?: string[];
|
|
54
|
+
set?: Record<string, string>;
|
|
55
|
+
placeholders?: Record<string, string>;
|
|
56
|
+
} | undefined;
|
|
50
57
|
socket?: string | null | undefined;
|
|
51
58
|
caFile?: string | null | undefined;
|
|
59
|
+
nodeExec?: string | undefined;
|
|
52
60
|
maskDirs?: string[] | undefined;
|
|
53
61
|
overlay?: boolean | undefined;
|
|
54
62
|
overlayIgnore?: string[] | undefined;
|
package/types/proxy.d.ts
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* so tests pass this; production never should.
|
|
19
19
|
* @property {(host: string) => Promise<string[] | string | null>} [unsafeTestOnly.resolveUpstream]
|
|
20
20
|
* DNS stub: replaces the wall's resolver so rebinding is testable. Production omits it.
|
|
21
|
+
* @property {import('./secrets.js').Secret[]} [secrets] the loaded secrets (`loadSecrets`): a request carrying a secret's placeholder in a header gets the real value there only after the gate allowed it and only for a bound host; for any other host it is refused `403 denied: secret.host`. The value never reaches the audit file, an ask or an error body.
|
|
21
22
|
* @property {number} [clientIdleMs] kill a client tunnel idle this long; never fires mid-request (default 60000)
|
|
22
23
|
* @property {(entry: Record<string, unknown>) => Record<string, unknown>} [redact] log redaction hook, applied after built-in secret scrubbing; its result becomes the `meta` of an `annotate` line (default: identity)
|
|
23
24
|
*/
|
|
@@ -152,6 +153,10 @@ export type ProxyOptions = {
|
|
|
152
153
|
*/
|
|
153
154
|
resolveUpstream?: ((host: string) => Promise<string[] | string | null>) | undefined;
|
|
154
155
|
} | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* the loaded secrets (`loadSecrets`): a request carrying a secret's placeholder in a header gets the real value there only after the gate allowed it and only for a bound host; for any other host it is refused `403 denied: secret.host`. The value never reaches the audit file, an ask or an error body.
|
|
158
|
+
*/
|
|
159
|
+
secrets?: import("./secrets.js").Secret[] | undefined;
|
|
155
160
|
/**
|
|
156
161
|
* kill a client tunnel idle this long; never fires mid-request (default 60000)
|
|
157
162
|
*/
|
package/types/run.d.ts
CHANGED
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
* @property {object} [unsafeTestOnly] TEST-ONLY escape hatch, forwarded to the proxy (see `createProxy`): everything under it weakens the sandbox wall
|
|
33
33
|
* @property {NodeJS.WritableStream} [stdout] where the agent's stdout goes (default process.stdout)
|
|
34
34
|
* @property {NodeJS.WritableStream} [stderr] where the agent's stderr goes (default process.stderr)
|
|
35
|
+
* @property {Record<string, { fromEnv?: string, value?: string, hosts: string[] }>} [secrets] keys the agent never holds (M5), the config `secrets` shape: the sandbox gets a random placeholder under each NAME; the proxy swaps in the real value on an allowed request to one of its `hosts` (see `createProxy`). A `fromEnv` variable missing from this process's environment rejects the run, naming the secret
|
|
36
|
+
* @property {{ pass?: string[], set?: Record<string, string> }} [env] the sandbox's environment (M5), the config `env` shape: the host environment never reaches it except a short default list (`TERM`, `LANG`, `LC_*`, `TZ`, ...), the host variables named in `pass` and the values in `set` (see `launch`)
|
|
35
37
|
* @property {boolean} [overlay] when true, mount a per-run overlay upper over the project (M4 tracing paper) instead of binding it read-only; the result's `diff` lists the run's changes for commit/rollback
|
|
36
38
|
* @property {string[]} [overlayIgnore] path segments invisible to the overlay (default `node_modules`; see overlay.js Q3)
|
|
37
39
|
*/
|
|
@@ -53,16 +55,18 @@
|
|
|
53
55
|
* @param {object|null} [opts.unsafeTestOnly] TEST-ONLY escape hatch, forwarded to the proxy (see `createProxy`)
|
|
54
56
|
* @param {NodeJS.WritableStream|null} [opts.stdout] where the agent's stdout goes (default process.stdout)
|
|
55
57
|
* @param {NodeJS.WritableStream|null} [opts.stderr] where the agent's stderr goes (default process.stderr)
|
|
58
|
+
* @param {Record<string, { fromEnv?: string, value?: string, hosts: string[] }>|null} [opts.secrets] keys the agent never holds (M5), the config `secrets` shape; see {@link RunOptions}
|
|
59
|
+
* @param {{ pass?: string[], set?: Record<string, string> }|null} [opts.env] the sandbox's environment (M5), the config `env` shape; see {@link RunOptions}
|
|
56
60
|
* @param {boolean} [opts.overlay] when true, mount a per-run overlay upper over the project instead of binding it read-only; the result's `diff` lists the run's changes for commit/rollback
|
|
57
61
|
* @param {string[]} [opts.overlayIgnore] path segments invisible to the overlay (default `node_modules`; see overlay.js Q3)
|
|
58
62
|
* @returns {Promise<{ exit: number, asks: AskRecord[], audit: string, diff: import('./overlay.js').OverlayChange[], runtime: string }>} the agent process exit code, the collected ask records, the JSONL audit log path, the run's overlay diff (M4), and the runtime dir addressing it
|
|
59
63
|
* @when Reach for this to HARNESS-ONLY run one sandboxed agent start-to-finish in a single call: it starts the proxy, sandboxes the command, answers holds, and returns the exit code with the ask and audit trail (plus the overlay diff once M4 exists).
|
|
60
|
-
* @fails Rejects on a missing/unreadable `proj`, an empty `command`, a bad `mode`, a misshapen `onAsk`, a proxy that never becomes ready, a `launch` that throws (uncommitted overlay changes, a runtime inside the project — the proxy is closed first), or an overlay diff that cannot be read. The agent's own nonzero exit is returned as `exit`, never thrown.
|
|
64
|
+
* @fails Rejects on a missing/unreadable `proj`, an empty `command`, a bad `mode`, a misshapen `onAsk`, a `secrets` entry with no value (a `fromEnv` variable missing from this process's environment; the message names the secret, never a value), a proxy that never becomes ready, a `launch` that throws (uncommitted overlay changes, a runtime inside the project — the proxy is closed first), or an overlay diff that cannot be read. The agent's own nonzero exit is returned as `exit`, never thrown.
|
|
61
65
|
* @example
|
|
62
66
|
* import { run } from "barebox";
|
|
63
67
|
* const { exit, asks, audit } = await run({ proj: "/tmp/proj", command: ["bash", "-c", "echo hi"] });
|
|
64
68
|
*/
|
|
65
|
-
export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeoutMs, heldBodyMaxBytes, allowLocal, labels, unsafeTestOnly, stdout, stderr, overlay, overlayIgnore }: {
|
|
69
|
+
export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeoutMs, heldBodyMaxBytes, allowLocal, labels, unsafeTestOnly, stdout, stderr, overlay, overlayIgnore, secrets, env }: {
|
|
66
70
|
proj: string;
|
|
67
71
|
command: string[];
|
|
68
72
|
mode?: string | undefined;
|
|
@@ -81,6 +85,15 @@ export function run({ proj, command, mode, onAsk, onEvent, runtime, agent, timeo
|
|
|
81
85
|
unsafeTestOnly?: object | null;
|
|
82
86
|
stdout?: NodeJS.WritableStream | null | undefined;
|
|
83
87
|
stderr?: NodeJS.WritableStream | null | undefined;
|
|
88
|
+
secrets?: Record<string, {
|
|
89
|
+
fromEnv?: string;
|
|
90
|
+
value?: string;
|
|
91
|
+
hosts: string[];
|
|
92
|
+
}> | null | undefined;
|
|
93
|
+
env?: {
|
|
94
|
+
pass?: string[];
|
|
95
|
+
set?: Record<string, string>;
|
|
96
|
+
} | null | undefined;
|
|
84
97
|
overlay?: boolean | undefined;
|
|
85
98
|
overlayIgnore?: string[] | undefined;
|
|
86
99
|
}): Promise<{
|
|
@@ -203,6 +216,21 @@ export type RunOptions = {
|
|
|
203
216
|
* where the agent's stderr goes (default process.stderr)
|
|
204
217
|
*/
|
|
205
218
|
stderr?: NodeJS.WritableStream | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* keys the agent never holds (M5), the config `secrets` shape: the sandbox gets a random placeholder under each NAME; the proxy swaps in the real value on an allowed request to one of its `hosts` (see `createProxy`). A `fromEnv` variable missing from this process's environment rejects the run, naming the secret
|
|
221
|
+
*/
|
|
222
|
+
secrets?: Record<string, {
|
|
223
|
+
fromEnv?: string;
|
|
224
|
+
value?: string;
|
|
225
|
+
hosts: string[];
|
|
226
|
+
}> | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* the sandbox's environment (M5), the config `env` shape: the host environment never reaches it except a short default list (`TERM`, `LANG`, `LC_*`, `TZ`, ...), the host variables named in `pass` and the values in `set` (see `launch`)
|
|
229
|
+
*/
|
|
230
|
+
env?: {
|
|
231
|
+
pass?: string[];
|
|
232
|
+
set?: Record<string, string>;
|
|
233
|
+
} | undefined;
|
|
206
234
|
/**
|
|
207
235
|
* when true, mount a per-run overlay upper over the project (M4 tracing paper) instead of binding it read-only; the result's `diff` lists the run's changes for commit/rollback
|
|
208
236
|
*/
|
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.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the secrets from the config shape and give each a fresh placeholder.
|
|
3
|
+
*
|
|
4
|
+
* @param {Record<string, { fromEnv?: string, value?: string, hosts: string[] }>} [config] the config `secrets` object
|
|
5
|
+
* @param {NodeJS.ProcessEnv} [env] where `fromEnv` is read (default `process.env`)
|
|
6
|
+
* @returns {Secret[]} one entry per secret, new placeholders on every call (so per run)
|
|
7
|
+
* @throws {Error} naming the secret (never a value) when it has no value or no hosts
|
|
8
|
+
*/
|
|
9
|
+
export function loadSecrets(config?: Record<string, {
|
|
10
|
+
fromEnv?: string;
|
|
11
|
+
value?: string;
|
|
12
|
+
hosts: string[];
|
|
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[];
|
|
19
|
+
/**
|
|
20
|
+
* Which placeholders a request carries, and whether each is headed for a host its secret is bound to.
|
|
21
|
+
* Each header value is searched as a substring and, for `Basic <base64>`, decoded.
|
|
22
|
+
*
|
|
23
|
+
* @param {Headers} headers the request headers
|
|
24
|
+
* @param {string} host the request's hostname (no port)
|
|
25
|
+
* @param {Secret[]} secrets from {@link loadSecrets}
|
|
26
|
+
* @returns {{ name: string, header: string, bound: boolean }[]} one entry per (secret, header)
|
|
27
|
+
*/
|
|
28
|
+
export function findPlaceholders(headers: Headers, host: string, secrets: Secret[]): {
|
|
29
|
+
name: string;
|
|
30
|
+
header: string;
|
|
31
|
+
bound: boolean;
|
|
32
|
+
}[];
|
|
33
|
+
/**
|
|
34
|
+
* The headers with every bound placeholder replaced by its real value. A new
|
|
35
|
+
* object; the input (which the agent's request owns) is never changed.
|
|
36
|
+
* Placeholders of a secret not bound to `host` stay as they are.
|
|
37
|
+
*
|
|
38
|
+
* @param {Headers} headers the request headers
|
|
39
|
+
* @param {string} host the request's hostname (no port)
|
|
40
|
+
* @param {Secret[]} secrets from {@link loadSecrets}
|
|
41
|
+
* @returns {Headers} new headers
|
|
42
|
+
*/
|
|
43
|
+
export function applySecrets(headers: Headers, host: string, secrets: Secret[]): Headers;
|
|
44
|
+
/**
|
|
45
|
+
* One loaded secret.
|
|
46
|
+
*/
|
|
47
|
+
export type Secret = {
|
|
48
|
+
/**
|
|
49
|
+
* the variable name the sandbox sees the placeholder under
|
|
50
|
+
*/
|
|
51
|
+
name: string;
|
|
52
|
+
/**
|
|
53
|
+
* the real value; never leaves the proxy except in an allowed request's header
|
|
54
|
+
*/
|
|
55
|
+
value: string;
|
|
56
|
+
/**
|
|
57
|
+
* hostnames (no port) the real value may be sent to
|
|
58
|
+
*/
|
|
59
|
+
hosts: string[];
|
|
60
|
+
/**
|
|
61
|
+
* `sbx-ph-<16 hex>`, fresh per call
|
|
62
|
+
*/
|
|
63
|
+
placeholder: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Request headers as node reads them: lowercase names, string or string[] values.
|
|
67
|
+
*/
|
|
68
|
+
export type Headers = Record<string, string | string[] | undefined>;
|