barebox 0.2.0 → 0.4.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 +85 -2
- package/README.md +11 -11
- package/barebox.context.md +91 -18
- package/package.json +2 -2
- package/primitives.json +40 -4
- package/src/certs.js +24 -3
- package/src/cli.js +348 -35
- package/src/holds.js +529 -58
- package/src/index.js +2 -0
- package/src/launcher.js +149 -50
- package/src/overlay-walk.js +49 -0
- package/src/overlay.js +1064 -0
- package/src/proxy.js +171 -310
- package/src/run.js +232 -0
- package/src/runtime.js +295 -0
- package/src/wall.js +217 -0
- package/types/certs.d.ts +2 -0
- package/types/holds.d.ts +168 -14
- package/types/index.d.ts +2 -0
- package/types/launcher.d.ts +13 -4
- package/types/overlay-walk.d.ts +1 -0
- package/types/overlay.d.ts +228 -0
- package/types/proxy.d.ts +43 -83
- package/types/run.d.ts +192 -0
- package/types/runtime.d.ts +131 -0
- package/types/wall.d.ts +30 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check an agent name before it reaches the filesystem.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} name agent name
|
|
5
|
+
* @returns {void} throws on `../` and friends
|
|
6
|
+
*/
|
|
7
|
+
export function assertAgentName(name: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve symlinks through the nearest existing ancestor: socket paths may
|
|
10
|
+
* not exist yet, so `realpathSync` on the full path would throw. Walks up
|
|
11
|
+
* to the first existing ancestor, resolves that, then re-attaches the rest.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} p any path, existing or not
|
|
14
|
+
* @returns {string} the real (symlink-free) spelling of `p`
|
|
15
|
+
*/
|
|
16
|
+
export function realPathOf(p: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* True when `p` is `base` or lives under it, compared as real (symlink-free)
|
|
19
|
+
* paths, so a symlinked spelling cannot smuggle a path out.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} base container path
|
|
22
|
+
* @param {string} p path to test
|
|
23
|
+
* @returns {boolean} containment on real paths
|
|
24
|
+
*/
|
|
25
|
+
export function isInside(base: string, p: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Create a short-lived runtime dir: a short `sbx-` temp dir, keeping unix
|
|
28
|
+
* socket paths under the ~108-char limit.
|
|
29
|
+
*
|
|
30
|
+
* @returns {string} the new runtime dir
|
|
31
|
+
*/
|
|
32
|
+
export function createRuntime(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Create a temp dir inside the runtime tree: `mkdtemp` is a runtime-layout
|
|
35
|
+
* writer, so it lives here, not in `overlay.js`. Used for the merged-view
|
|
36
|
+
* mount (`merged`) and the walker manifest dir (`walk`).
|
|
37
|
+
*
|
|
38
|
+
* @param {string} scratch overlay record dir (`overlay/<agent>`)
|
|
39
|
+
* @param {string} prefix dir prefix (`merged`, `walk`)
|
|
40
|
+
* @returns {string} the new dir
|
|
41
|
+
*/
|
|
42
|
+
export function runtimeTempDir(scratch: string, prefix: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Make a runtime dir owner-only whatever the umask: `mode` is masked by
|
|
45
|
+
* the umask and doesn't apply to an existing dir, hence the `chmod`. An
|
|
46
|
+
* existing dir you own is tightened to 0700; one you don't own (`/tmp`,
|
|
47
|
+
* root-owned, shared) is refused, since it can't be made private.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} dir dir to create or fix up
|
|
50
|
+
* @returns {void}
|
|
51
|
+
* @throws {Error} when the dir exists and is owned by another uid
|
|
52
|
+
*/
|
|
53
|
+
export function ensurePrivateDir(dir: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* The abstract-socket name of a runtime's claim lock. Hashes the real path,
|
|
56
|
+
* device and inode, so a symlinked path finds the same lock and a recreated
|
|
57
|
+
* dir gets a new one.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} runtime runtime dir
|
|
60
|
+
* @returns {string} the abstract socket name
|
|
61
|
+
*/
|
|
62
|
+
export function lockName(runtime: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* True when a live proxy owns the runtime: something answers on its lock.
|
|
65
|
+
* Never binds, so it can never steal the claim from a proxy that's starting.
|
|
66
|
+
* A runtime that doesn't exist is not live.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} runtime runtime dir
|
|
69
|
+
* @returns {Promise<boolean>} whether the lock connects
|
|
70
|
+
*/
|
|
71
|
+
export function runtimeLive(runtime: string): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Claim one runtime for one live proxy: the single enforcer of "one proxy
|
|
74
|
+
* owns a runtime". The claim is an abstract unix socket the proxy binds for
|
|
75
|
+
* as long as it lives (Linux). The kernel frees it when the process dies,
|
|
76
|
+
* SIGKILL included, so a claim is never stale: nothing is judged, taken
|
|
77
|
+
* over or deleted by hand. The name hashes the real path, device and inode,
|
|
78
|
+
* so a symlinked path finds the same lock and a recreated dir gets a new one.
|
|
79
|
+
* The bind result is synchronous (`server.listening` right after `listen`),
|
|
80
|
+
* so a second claim, in this process or another, throws before the caller
|
|
81
|
+
* touches the runtime. The lock is `unref`'d: it never keeps a process alive.
|
|
82
|
+
* The owner file `{"pid"}` is written by the lock holder only, to name it in
|
|
83
|
+
* the in-use message.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} runtime runtime dir to claim
|
|
86
|
+
* @returns {() => void} `release()`: unlinks the owner file only when it holds our pid, then closes the lock; idempotent per claim
|
|
87
|
+
*/
|
|
88
|
+
export function claimRuntime(runtime: string): () => void;
|
|
89
|
+
/**
|
|
90
|
+
* Strip terminal control before printing agent-controlled bytes (ask URLs,
|
|
91
|
+
* rules, body previews, overlay paths): an escape sequence smuggled into a
|
|
92
|
+
* preview could otherwise rewrite the approver's terminal line before
|
|
93
|
+
* approval, and bidi controls in an agent-chosen filename could flip how a
|
|
94
|
+
* reviewed path reads.
|
|
95
|
+
*
|
|
96
|
+
* @param {unknown} s value to print
|
|
97
|
+
* @returns {string} printable text with no VT sequences, C0/C1 controls, or bidi controls
|
|
98
|
+
*/
|
|
99
|
+
export function safe(s: unknown): string;
|
|
100
|
+
/**
|
|
101
|
+
* Quote a path for pasting into a shell: safe spellings come back
|
|
102
|
+
* unchanged, anything else is single-quoted with `'` escaped.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} s path to quote
|
|
105
|
+
* @returns {string} shell-safe spelling
|
|
106
|
+
*/
|
|
107
|
+
export function shellQuote(s: string): string;
|
|
108
|
+
/**
|
|
109
|
+
* Every path in a runtime dir. The one place that names them.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} runtime runtime dir
|
|
112
|
+
* @returns {{ socket: (agent: string) => string, asksDir: string, answersDir: string, askFile: (id: string) => string, answerFile: (id: string) => string, certsDir: string, caBundle: string, audit: string, owner: string, overlay: (agent: string) => { base: string, upper: string, work: string, manifest: string } }} layout
|
|
113
|
+
*/
|
|
114
|
+
export function runtimePaths(runtime: string): {
|
|
115
|
+
socket: (agent: string) => string;
|
|
116
|
+
asksDir: string;
|
|
117
|
+
answersDir: string;
|
|
118
|
+
askFile: (id: string) => string;
|
|
119
|
+
answerFile: (id: string) => string;
|
|
120
|
+
certsDir: string;
|
|
121
|
+
caBundle: string;
|
|
122
|
+
audit: string;
|
|
123
|
+
owner: string;
|
|
124
|
+
overlay: (agent: string) => {
|
|
125
|
+
base: string;
|
|
126
|
+
upper: string;
|
|
127
|
+
work: string;
|
|
128
|
+
manifest: string;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
export const AGENT_RE: RegExp;
|
package/types/wall.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why `ip` (already resolved) is denied, or null when it may go through.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} rawIp resolved destination IP
|
|
5
|
+
* @param {boolean} allowLoopback test-only opt-in for loopback + unspecified
|
|
6
|
+
* @returns {string|null} `loopback` / `unspecified` / `link-local` / `host-local` / `private`, or null
|
|
7
|
+
*/
|
|
8
|
+
export function denyReasonForIp(rawIp: string, allowLoopback: boolean): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* The wall: resolve every answer, then default-deny loopback/link-local/
|
|
11
|
+
* host-local/private unless the test-only opt-ins allow it. Denies when ANY
|
|
12
|
+
* answer is walled, denies unresolvable names, and pins every checked IP so
|
|
13
|
+
* the dial below tries them in order without resolving a second time (no
|
|
14
|
+
* rebinding, with fallback when the first address refuses).
|
|
15
|
+
*
|
|
16
|
+
* @param {string} host CONNECT/request hostname
|
|
17
|
+
* @param {{ allowLoopback: boolean, resolveUpstream?: (host: string) => Promise<string[] | string | null> }} gate
|
|
18
|
+
* @returns {Promise<{ ok: true, ips: string[] } | { ok: false, ip: string, reason: string }>}
|
|
19
|
+
*/
|
|
20
|
+
export function checkUpstream(host: string, gate: {
|
|
21
|
+
allowLoopback: boolean;
|
|
22
|
+
resolveUpstream?: (host: string) => Promise<string[] | string | null>;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
ok: true;
|
|
25
|
+
ips: string[];
|
|
26
|
+
} | {
|
|
27
|
+
ok: false;
|
|
28
|
+
ip: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
}>;
|