piroboros 0.3.2 → 0.3.3
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 +19 -0
- package/dist/guard.js +1 -1
- package/dist/ws/apply.js +23 -7
- package/dist/ws/confine.js +50 -24
- package/dist/ws/docker.js +14 -20
- package/dist/ws/git.js +95 -22
- package/dist/ws/workspace.js +237 -97
- package/dist/ws/wsl.js +13 -25
- package/docs/conclave.md +3 -3
- package/docs/tools.md +6 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
This project follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## [0.3.3] - 2026-10-28
|
|
6
|
+
|
|
7
|
+
### Security
|
|
8
|
+
|
|
9
|
+
- A Workspace with git is now its own repository. At open piroboros makes a new one in the Workspace folder with one commit of the copied files, on the branch name your repository is on, with your remotes' addresses and a push address that fails. Nothing of your `.git` comes along: no history, branches, stashes, index or objects, and nothing is bound or mounted into the sandbox. Before, a secret that was excluded from the copy (a `.env` committed once and deleted since) could still be read from your object store through the shared objects. This removes the object-folder code added in 0.3.1, including the unchecked Docker mount of alternates.
|
|
10
|
+
- The visible change: `git log` in a Workspace shows one commit, and a Workspace made by 0.3.2 or earlier loses its git history when it is reopened, or when its run is resumed after a retry or a restart (its files stay, and one notice line says so). A Docker or WSL sandbox of such a Workspace, which still binds your objects, is made again before the run's first command, as a reopen does (a Docker container is removed and a new one started), and the run goes on. If the new sandbox cannot be made, the run ends held with the reason `confinement backend unavailable`, and approving it again reopens the Workspace.
|
|
11
|
+
- The base commit of a Workspace is built with `git fast-import` and `git read-tree`, which run no clean filter, line-ending conversion or hook, so no filter in your global or system git config (a `filter.lfs.*` entry, for example) runs on your machine at open. Each file's blob holds its bytes as copied. A project of 24,000 unique files opens in about 17 seconds instead of 72, because no loose object is written per file. With `core.autocrlf` and `* text=auto` the Workspace's `git status` stays clean; a file with an explicit `text` or `eol` attribute whose line endings differ from it, or a file a clean filter changes, can show as modified in `git status` inside the Workspace before Vesperia touches it. Merges read no git, so they are not affected.
|
|
12
|
+
- `id_dsa` is now refused by the file tools and left out of a Workspace like the other SSH private key names (`id_rsa`, `id_ecdsa`, `id_ed25519`).
|
|
13
|
+
- Everything piroboros writes into a Workspace after Vesperia has had it (the refresh when a held Workspace reopens, the empty `node_modules` folders on WSL and the conflict markers) now checks every folder on the way for a link and writes through a new file that is renamed over the old one. Before, she could replace a folder or the `.git/objects/info/alternates` file with a link to a file outside the Workspace and have piroboros overwrite that file. A refused path is skipped with a notice. With Docker, every process in the container is ended before the host reads or writes the Workspace, so a background process cannot race it.
|
|
14
|
+
- The bubblewrap sandbox (native and in WSL) no longer starts from a read-only view of the whole root. A command sees only `/usr`, `/etc`, `/bin`, `/sbin`, `/lib`, `/lib32`, `/lib64`, `/libx32` and `/nix` where they exist, the PATH folders outside them, the Workspace, and empty `/tmp`, `/var/tmp` and home folders; `/opt`, `/srv`, `/var`, `/mnt`, `/media`, other drives and a project outside your home are gone, and your live project is empty wherever it is. Before, with `workspace.network` on (the default), a command could read and send any of them. A stored WSL sandbox from 0.3.2 or earlier is made again before its next command.
|
|
15
|
+
- With `workspace.network` on, the sandbox shares the network namespace and with it the abstract Unix sockets, which is documented as a residual and not closed: a Linux desktop's X server usually listens on one (set `workspace.network` to `false` there), and in WSL they are systemd's system buses, which a normal shell reaches too.
|
|
16
|
+
- A path under a `guard.deny` folder inside the project is no longer copied into a Workspace, at open or at a refresh.
|
|
17
|
+
- `/conclave undo` and the recovery after a crash now apply the checks a merge applies: a link or a non-folder on the way to a path, a path that resolves outside the project, or the guard. A row that fails them is reported as protected and its path is not touched; the clean-up of leftover files skips such a folder. Before, replacing a folder with a link to a folder holding the same bytes made an undo delete or replace the files there.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- A folder in the Workspace that cannot be read is no longer taken for a deletion of everything in it. The merge holds with the folder named, and `/conclave merge` continues once the permissions are fixed. Checkpoints during the run are not affected.
|
|
22
|
+
- A `node_modules` folder that git tracks is left out of the copy like any other, so a merge no longer deletes its files from your project. A merge row under a `node_modules` folder is never applied.
|
|
23
|
+
|
|
5
24
|
## [0.3.2] - 2026-10-27
|
|
6
25
|
|
|
7
26
|
### Changed
|
package/dist/guard.js
CHANGED
|
@@ -91,7 +91,7 @@ export function shellPathRefusal(command, cwd, config) {
|
|
|
91
91
|
return undefined;
|
|
92
92
|
}
|
|
93
93
|
// Names that never open under the read exception for <home>/skills, whatever folder they sit in.
|
|
94
|
-
const SECRET_BASENAME = [...ENV_BASENAME, /\.(?:pem|key|p12|pfx|kdbx)$/iu, /^id_(?:rsa|ed25519|ecdsa)/iu, /\.sqlite/iu, /^(?:auth\.json|\.netrc|\.npmrc)$/iu];
|
|
94
|
+
const SECRET_BASENAME = [...ENV_BASENAME, /\.(?:pem|key|p12|pfx|kdbx)$/iu, /^id_(?:rsa|dsa|ed25519|ecdsa)/iu, /\.sqlite/iu, /^(?:auth\.json|\.netrc|\.npmrc)$/iu];
|
|
95
95
|
/** True when a read of `target` (canonical) falls under the home exception: inside the real <home>/skills, and not a secret name. */
|
|
96
96
|
function homeSkillsRead(target, base, config) {
|
|
97
97
|
// The canonical skills folder must be exactly <home>/skills: a link or junction that points it elsewhere opens nothing.
|
package/dist/ws/apply.js
CHANGED
|
@@ -471,7 +471,8 @@ export class Writer {
|
|
|
471
471
|
}
|
|
472
472
|
throw hold("the store kept dropping snapshot objects; /conclave merge tries again");
|
|
473
473
|
}
|
|
474
|
-
|
|
474
|
+
/** Why `abs` may not be touched, or undefined: a link or a non-folder among its parents, a canonical path outside the project, or the guard. Forward and reverse passes both use it. */
|
|
475
|
+
async pathProblem(project, canonicalProject, abs) {
|
|
475
476
|
let cur = project;
|
|
476
477
|
for (const part of dirname(abs).slice(project.length).split(/[\\/]/u).filter((s) => s !== "")) {
|
|
477
478
|
cur = join(cur, part);
|
|
@@ -485,14 +486,20 @@ export class Writer {
|
|
|
485
486
|
throw error;
|
|
486
487
|
}
|
|
487
488
|
if (info.isSymbolicLink())
|
|
488
|
-
|
|
489
|
+
return "a link lies in its path";
|
|
489
490
|
if (!info.isDirectory())
|
|
490
|
-
|
|
491
|
+
return "a parent is not a folder";
|
|
491
492
|
}
|
|
492
493
|
if (!isInside(canonicalProject, canonicalize(abs)))
|
|
493
|
-
|
|
494
|
+
return "it resolves outside the project";
|
|
494
495
|
if (!this.d.allowed(abs))
|
|
495
|
-
|
|
496
|
+
return "it is protected";
|
|
497
|
+
return undefined;
|
|
498
|
+
}
|
|
499
|
+
async checkParents(project, canonicalProject, abs, rel) {
|
|
500
|
+
const problem = await this.pathProblem(project, canonicalProject, abs);
|
|
501
|
+
if (problem !== undefined)
|
|
502
|
+
throw new HoldError("preflight", `${rel}: ${problem}`);
|
|
496
503
|
}
|
|
497
504
|
/** Per volume: the tmp of every row, the rollback tmp of a displaced one, and the snapshot in the store, plus a margin. */
|
|
498
505
|
async freeSpace(input, rows) {
|
|
@@ -548,8 +555,11 @@ export class Writer {
|
|
|
548
555
|
const abs = await this.target(project, row, caseless);
|
|
549
556
|
const from = row.from === null ? undefined : join(dirname(await this.name(project, row.from, caseless)), basename(row.from));
|
|
550
557
|
const target = from ?? abs;
|
|
551
|
-
|
|
552
|
-
|
|
558
|
+
// The forward pass's checks, before any lstat of the path itself: a link among its parents would send the reverse pass outside the project.
|
|
559
|
+
const canonicalProject = canonicalize(project);
|
|
560
|
+
const problem = (await this.pathProblem(project, canonicalProject, abs)) ?? (from === undefined ? undefined : await this.pathProblem(project, canonicalProject, from));
|
|
561
|
+
if (problem !== undefined)
|
|
562
|
+
return { verdict: "protected", reason: `the path is protected (${problem})`, abs, ...(from === undefined ? {} : { from }) };
|
|
553
563
|
const out = (verdict, reason, fromAbsent) => ({ verdict, ...(reason === undefined ? {} : { reason }), abs, ...(from === undefined ? {} : { from }), ...(fromAbsent ? { fromAbsent } : {}) });
|
|
554
564
|
const at = async (p) => ((await this.exact(p)) || !caseless ? this.live(p) : { kind: "absent" });
|
|
555
565
|
switch (row.op) {
|
|
@@ -711,7 +721,13 @@ export class Writer {
|
|
|
711
721
|
}
|
|
712
722
|
const tmpRe = new RegExp(`\\.piroboros-tmp-${id}-`, "u");
|
|
713
723
|
const oldRe = new RegExp(`^\\.(.+)\\.piroboros-old-${id}-\\d+$`, "u");
|
|
724
|
+
const canonicalProject = canonicalize(project);
|
|
714
725
|
for (const dir of folders) {
|
|
726
|
+
const problem = await this.pathProblem(project, canonicalProject, join(dir, "x"));
|
|
727
|
+
if (problem !== undefined) {
|
|
728
|
+
lines.push(`left alone: ${dir} (${problem})`);
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
715
731
|
let names;
|
|
716
732
|
try {
|
|
717
733
|
names = await this.d.fs.readdir(dir);
|
package/dist/ws/confine.js
CHANGED
|
@@ -8,10 +8,17 @@ import { checkRead, denyRoots } from "../guard.js";
|
|
|
8
8
|
import { dockerPick, execDocker } from "./docker.js";
|
|
9
9
|
import { WsRefusal } from "./git.js";
|
|
10
10
|
import { execWsl, SelfTestError, wslDeps, wslPick } from "./wsl.js";
|
|
11
|
+
/**
|
|
12
|
+
* A stored sandbox that must be picked again before the run's first command (`Found.upgrade`): a record made by 0.3.1 or 0.3.2 may hold `alt` (the live repository's object folders, bound or mounted;
|
|
13
|
+
* the stored WSL argv and a Docker container still bind or mount them), and a stored WSL argv made before 0.3.3 binds the whole root (`--ro-bind / /`), where a new one binds only the system folders.
|
|
14
|
+
*/
|
|
15
|
+
export const needsRepick = (c) => [c.wsl, c.docker].some((x) => (x?.alt?.length ?? 0) > 0) || (c.wsl?.argv.some((a, i, v) => a === "--ro-bind" && v[i + 1] === "/" && v[i + 2] === "/") ?? false);
|
|
11
16
|
export const UNCONFINED = "WARNING: shell commands are not confined on this system. Vesperia's commands run in the Workspace folder but can still read and write any path your account can, including your live project.";
|
|
12
17
|
/** Linux refuses one argument over 131,072 bytes counting its NUL (MAX_ARG_STRLEN). */
|
|
13
18
|
export const COMMAND_MAX = 131_071;
|
|
14
19
|
const DOWN = "confinement backend unavailable: ";
|
|
20
|
+
/** The top-level folders a sandbox gets from the machine (read-only); /nix is where NixOS keeps what PATH points at. */
|
|
21
|
+
const SYSTEM = ["/usr", "/etc", "/bin", "/sbin", "/lib", "/lib32", "/lib64", "/libx32", "/nix"];
|
|
15
22
|
export const within = (root, path) => path === root || path.startsWith(root === "/" ? "/" : `${root}/`);
|
|
16
23
|
export function nativeDeps(cfg, wsRoot) {
|
|
17
24
|
return {
|
|
@@ -56,22 +63,23 @@ export function seccompExec(bwrap, args) {
|
|
|
56
63
|
return ["bash", "-c", 'exec "${@:2}" 9< <(printf %b "$1")', "bash", octal, bwrap, ...args];
|
|
57
64
|
}
|
|
58
65
|
/**
|
|
59
|
-
* The bwrap arguments for `inner` run in the Workspace `c.ws` from `c.cwd`.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* Workspace folders, `env` is the whole environment and `extra` are more read-only binds.
|
|
66
|
+
* The bwrap arguments for `inner` run in the Workspace `c.ws` from `c.cwd`. The root is not bound: a command sees the SYSTEM folders read-only, the PATH
|
|
67
|
+
* folders outside them, the Workspace, and empty /tmp, /var/tmp and masks. Options apply in order: masks first, binds after. A mask
|
|
68
|
+
* path (the home, PIROBOROS_HOME, the deny roots and the live project `c.project`, so they stay empty even under a bound folder) is resolved first; one that does not exist, or lies inside an earlier mask, is dropped.
|
|
69
|
+
* `refused` names needed paths left masked because they lie in a deny root outside every guard.allow folder, or are, or contain, a protected folder. `c.wsl` is bubblewrap in WSL (4.3.4):
|
|
70
|
+
* the Windows-backed mounts are masked, `/init` is emptied (no Windows program starts), `nm` binds ext4 folders over Workspace folders, `env` is the whole environment and `extra` are more read-only binds.
|
|
71
|
+
* Nothing of the live repository is bound: a git Workspace holds its own repository.
|
|
64
72
|
*/
|
|
65
73
|
export function bwrapArgs(d, c, inner) {
|
|
66
74
|
const masks = [];
|
|
67
|
-
for (const mask of [d.home,
|
|
75
|
+
for (const mask of [d.home, ...(c.wsl?.mounts ?? []), d.piroHome, ...d.deny, ...(c.project === undefined ? [] : [c.project])]) {
|
|
68
76
|
const r = d.real(mask);
|
|
69
77
|
if (r !== undefined && !masks.some((m) => within(m, r)))
|
|
70
78
|
masks.push(r);
|
|
71
79
|
}
|
|
72
80
|
const binds = [];
|
|
73
81
|
const refused = [];
|
|
74
|
-
const protectedRoots = [d.piroHome, d.wsRoot, ...d.deny].map((root) => d.real(root) ?? root);
|
|
82
|
+
const protectedRoots = [d.piroHome, d.wsRoot, ...d.deny, ...(c.project === undefined ? [] : [c.project])].map((root) => d.real(root) ?? root);
|
|
75
83
|
const need = (path) => {
|
|
76
84
|
const r = d.real(path);
|
|
77
85
|
if (r === undefined || binds.some(([, dest]) => dest === r))
|
|
@@ -85,32 +93,45 @@ export function bwrapArgs(d, c, inner) {
|
|
|
85
93
|
}
|
|
86
94
|
binds.push([r, r]);
|
|
87
95
|
};
|
|
88
|
-
// The
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
// The system folders that exist are all a command sees of the machine: a real folder is bound read-only, a link (merged /usr: /bin -> usr/bin) is made again.
|
|
97
|
+
const system = [];
|
|
98
|
+
const links = [];
|
|
99
|
+
for (const name of SYSTEM) {
|
|
100
|
+
const r = d.real(name);
|
|
101
|
+
if (r === name)
|
|
102
|
+
system.push(r);
|
|
103
|
+
else if (r !== undefined)
|
|
104
|
+
links.push([r, name]);
|
|
105
|
+
}
|
|
106
|
+
const inSystem = (p) => system.some((s) => within(s, p));
|
|
107
|
+
for (const [target] of links)
|
|
108
|
+
if (!inSystem(target))
|
|
109
|
+
need(target);
|
|
110
|
+
// A resolv.conf that is a link out of /etc (systemd-resolved, WSL) needs its target.
|
|
92
111
|
const resolv = c.net ? d.real("/etc/resolv.conf") : undefined;
|
|
93
|
-
if (resolv !== undefined &&
|
|
112
|
+
if (resolv !== undefined && !inSystem(resolv))
|
|
94
113
|
need(c.wsl === undefined ? posix.dirname(resolv) : resolv);
|
|
95
|
-
// PATH entries
|
|
114
|
+
// PATH entries outside the system folders: the entry, and its parent only for `<parent>/bin` where the parent is neither the home, nor the root, nor a direct child of either.
|
|
96
115
|
const home = d.real(d.home) ?? d.home;
|
|
116
|
+
const shallow = (p) => [home, "/"].some((top) => p === top || posix.dirname(p) === top);
|
|
97
117
|
for (const entry of c.path.split(":")) {
|
|
98
118
|
const r = entry.startsWith("/") ? d.real(entry) : undefined;
|
|
99
|
-
if (r === undefined || r === home ||
|
|
119
|
+
if (r === undefined || r === home || r === "/" || inSystem(r))
|
|
100
120
|
continue;
|
|
101
121
|
const parent = posix.dirname(r);
|
|
102
|
-
if (posix.basename(r) === "bin" &&
|
|
122
|
+
if (posix.basename(r) === "bin" && !shallow(parent))
|
|
103
123
|
need(parent);
|
|
104
124
|
need(r);
|
|
105
125
|
}
|
|
106
|
-
const args = ["--seccomp", "9", "--die-with-parent", "--new-session", "--unshare-all", ...(c.net ? ["--share-net"] : []), "--ro-bind",
|
|
126
|
+
const args = ["--seccomp", "9", "--die-with-parent", "--new-session", "--unshare-all", ...(c.net ? ["--share-net"] : []), ...system.flatMap((s) => ["--ro-bind", s, s]), ...links.flatMap(([target, name]) => ["--symlink", target, name]),
|
|
127
|
+
"--dev", "/dev", "--proc", "/proc", "--tmpfs", "/tmp", "--tmpfs", "/var/tmp",
|
|
107
128
|
...masks.flatMap((m) => ["--tmpfs", m]), ...(c.wsl === undefined ? [] : ["--ro-bind", "/dev/null", "/init"]), ...binds.flatMap(([s, t]) => ["--ro-bind", s, t]), ...(c.wsl?.extra ?? []).flatMap((p) => ["--ro-bind", p, p]),
|
|
108
129
|
"--bind", c.ws, c.ws, ...(c.wsl?.nm ?? []).flatMap(([s, t]) => ["--bind", s, t]),
|
|
109
130
|
...(c.wsl === undefined ? [] : ["--clearenv", ...c.wsl.env.flatMap(([k, v]) => ["--setenv", k, v]), "--unsetenv", "WSL_INTEROP"]), "--chdir", c.cwd, ...inner];
|
|
110
131
|
return { args, refused };
|
|
111
132
|
}
|
|
112
|
-
// Runs inside the sandbox: write and remove a file in the Workspace, no auth.json beside the home,
|
|
113
|
-
const SELF_TEST = 'm="$1/.piroboros-selftest"; : > "$m" || { echo "the Workspace is not writable"; exit 1; }; rm -f "$m"; [ ! -e "$2/auth.json" ] || { echo "auth.json is visible"; exit 1; }; [ "$3" = 0 ] || [ -r /etc/resolv.conf ] || { echo "resolv.conf is not readable"; exit 1; }; command -v perl >/dev/null && { perl -e \'socket(S,40,1,0) and exit 1; exit($!+0==97?0:2)\' || { echo "an AF_VSOCK socket can be created"; exit 1; }; }; true';
|
|
133
|
+
// Runs inside the sandbox: write and remove a file in the Workspace, no auth.json beside the home, (network on) a readable resolv.conf, and nothing listed in the live project's folder.
|
|
134
|
+
const SELF_TEST = 'm="$1/.piroboros-selftest"; : > "$m" || { echo "the Workspace is not writable"; exit 1; }; rm -f "$m"; [ ! -e "$2/auth.json" ] || { echo "auth.json is visible"; exit 1; }; [ "$3" = 0 ] || [ -r /etc/resolv.conf ] || { echo "resolv.conf is not readable"; exit 1; }; [ -z "$4" ] || [ -z "$(ls -A -- "$4" 2>/dev/null)" ] || { echo "the live project is visible"; exit 1; }; command -v perl >/dev/null && { perl -e \'socket(S,40,1,0) and exit 1; exit($!+0==97?0:2)\' || { echo "an AF_VSOCK socket can be created"; exit 1; }; }; true';
|
|
114
135
|
/**
|
|
115
136
|
* Pick the backend for a Workspace folder (4.3.1): Docker first when an image is set (and always for `docker`, which refuses the run when Docker is not usable),
|
|
116
137
|
* then bubblewrap, then none. A failure under `auto` is never a run failure: it gives the next backend, or none plus a warning.
|
|
@@ -121,7 +142,7 @@ export async function confineFor(s, d, ws, plan) {
|
|
|
121
142
|
let skipped = "";
|
|
122
143
|
if (s.confine !== "none" && s.docker !== undefined) {
|
|
123
144
|
try {
|
|
124
|
-
return await dockerPick({ network: s.network, distro: s.distro, image: s.docker }, d, ws, plan ?? { places: [],
|
|
145
|
+
return await dockerPick({ network: s.network, distro: s.distro, image: s.docker }, d, ws, plan ?? { places: [], project: "", files: 0 });
|
|
125
146
|
}
|
|
126
147
|
catch (error) {
|
|
127
148
|
const why = error instanceof Error ? error.message : String(error);
|
|
@@ -140,7 +161,7 @@ async function confineLocal(confine, network, distro, d, ws, plan) {
|
|
|
140
161
|
return none("workspace.confine is none");
|
|
141
162
|
if (d.platform === "win32" && d.wsl !== undefined) {
|
|
142
163
|
try {
|
|
143
|
-
return await wslPick(s, d, ws, plan ?? { places: [],
|
|
164
|
+
return await wslPick(s, d, ws, plan ?? { places: [], project: "", files: 0 });
|
|
144
165
|
}
|
|
145
166
|
catch (error) {
|
|
146
167
|
return none(error instanceof SelfTestError ? error.message : `bubblewrap in WSL: ${error instanceof Error ? error.message : String(error)}`, error instanceof SelfTestError);
|
|
@@ -151,12 +172,13 @@ async function confineLocal(confine, network, distro, d, ws, plan) {
|
|
|
151
172
|
const bwrap = d.which("bwrap");
|
|
152
173
|
if (bwrap === undefined)
|
|
153
174
|
return none("bubblewrap is not installed (package bubblewrap)");
|
|
154
|
-
const
|
|
175
|
+
const project = plan?.project === "" ? undefined : plan?.project;
|
|
176
|
+
const test = bwrapArgs(d, { ws, cwd: ws, net: s.network, path: process.env.PATH ?? "", project }, ["sh", "-c", SELF_TEST, "sh", ws, d.piroHome, s.network ? "1" : "0", project ?? ""]);
|
|
155
177
|
const [program, ...rest] = seccompExec(bwrap, test.args);
|
|
156
178
|
const ran = await d.run(program, rest);
|
|
157
179
|
if (ran.code !== 0)
|
|
158
180
|
return none(ran.out.trim().split("\n")[0] || "bwrap did not start", true);
|
|
159
|
-
return { confine: { name: "bubblewrap", bwrap, net: s.network
|
|
181
|
+
return { confine: { name: "bubblewrap", bwrap, net: s.network }, label: "bubblewrap", notice: [...(s.network ? ["Network: on. Confined commands can reach your network, and can send any file they can see."] : []), ...(test.refused.length > 0 ? [`Left hidden in the sandbox because they are protected: ${test.refused.join(", ")}`] : [])] };
|
|
160
182
|
}
|
|
161
183
|
/** Wraps each command of a Workspace whose row says bubblewrap; every other command runs as before. A command a chosen backend cannot start is an error, never a rerun. */
|
|
162
184
|
export class ConfinedShellEnv extends ShellEnv {
|
|
@@ -166,7 +188,11 @@ export class ConfinedShellEnv extends ShellEnv {
|
|
|
166
188
|
if (typeof command !== "string")
|
|
167
189
|
return super.exec(command, options, context);
|
|
168
190
|
const cwd = resolve(this.cwd, options?.cwd ?? ".");
|
|
169
|
-
|
|
191
|
+
let w = this.lookup(cwd);
|
|
192
|
+
if (w?.upgrade !== undefined) {
|
|
193
|
+
await w.upgrade();
|
|
194
|
+
w = this.lookup(cwd);
|
|
195
|
+
}
|
|
170
196
|
if (w === undefined || w.confine.name === "none")
|
|
171
197
|
return super.exec(command, options, context);
|
|
172
198
|
const unavailable = (reason) => err(new ExecutionError("spawn_error", `${DOWN}${reason}`));
|
|
@@ -182,7 +208,7 @@ export class ConfinedShellEnv extends ShellEnv {
|
|
|
182
208
|
else if (w.confine.wsl !== undefined)
|
|
183
209
|
result = await execWsl(w, cwd, command, options, context);
|
|
184
210
|
else {
|
|
185
|
-
const { args } = bwrapArgs(w.deps, { ws: w.ws, cwd, net: w.confine.net !== false, path: options?.env?.PATH ?? "",
|
|
211
|
+
const { args } = bwrapArgs(w.deps, { ws: w.ws, cwd, net: w.confine.net !== false, path: options?.env?.PATH ?? "", project: w.project }, ["bash", "-c", command]);
|
|
186
212
|
result = await super.exec(seccompExec(w.confine.bwrap, args), options, context);
|
|
187
213
|
if (!result.ok && result.error.code === "spawn_error")
|
|
188
214
|
result = unavailable(result.error.message);
|
package/dist/ws/docker.js
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdirSync } from "node:fs";
|
|
|
2
2
|
import { posix, win32 } from "node:path";
|
|
3
3
|
import { err, ExecutionError } from "@earendil-works/pi-durable/env";
|
|
4
4
|
import { within } from "./confine.js";
|
|
5
|
-
import { call, posixOf, resolveWsl, via, WRAPPER, WSLPATH,
|
|
5
|
+
import { call, posixOf, resolveWsl, via, WRAPPER, WSLPATH, wslCommand } from "./wsl.js";
|
|
6
6
|
const SOCK = "unix:///var/run/docker.sock";
|
|
7
7
|
// Runs in the container: the Workspace is writable, and (with perl) an AF_VSOCK socket cannot be created and io_uring_setup fails with EPERM.
|
|
8
8
|
const SELF_TEST = 'm=/work/.piroboros-selftest; : > "$m" || { echo "the Workspace is not writable"; exit 1; }; rm -f "$m"; command -v perl >/dev/null || { echo skipped; exit 0; }; perl -e \'socket(S,40,1,0) and exit 1\' || { echo "an AF_VSOCK socket can be created"; exit 1; }; perl -e \'syscall(425,0,0)==-1 && $!==1 and exit 0; exit 1\' || { echo "io_uring_setup is not blocked"; exit 1; }';
|
|
@@ -22,10 +22,9 @@ export async function dockerPick(s, d, ws, p) {
|
|
|
22
22
|
const id = P.basename(ws);
|
|
23
23
|
const notice = [];
|
|
24
24
|
let host = ws;
|
|
25
|
-
let alt = p.alt;
|
|
26
25
|
let user = typeof process.getuid === "function" && !win ? ["--user", `${process.getuid()}:${process.getgid()}`] : [];
|
|
27
26
|
let nm = [];
|
|
28
|
-
let c = { cli: "", config: `${d.wsRoot}/${hash}/docker-config`, container: "", image: s.image, net: s.network,
|
|
27
|
+
let c = { cli: "", config: `${d.wsRoot}/${hash}/docker-config`, container: "", image: s.image, net: s.network, places: p.places };
|
|
29
28
|
let where = "a shell";
|
|
30
29
|
if (win) {
|
|
31
30
|
const w = d.wsl;
|
|
@@ -36,18 +35,12 @@ export async function dockerPick(s, d, ws, p) {
|
|
|
36
35
|
throw error; return resolveWsl(w, { distro: s.distro }, false); });
|
|
37
36
|
const who = { distro: info.distro, user: info.user };
|
|
38
37
|
where = `the ${info.distro} distro`;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const lin = (await call(w, who, "translating paths", WSLPATH, [ws, ...alt].map((x) => win32.resolve(x)))).split("\n");
|
|
46
|
-
for (const x of lin.slice(0, alt.length + 1))
|
|
47
|
-
if (!info.mounts.some((m) => within(m, x)))
|
|
48
|
-
throw new Error(`${x} is not on a local Windows drive`);
|
|
49
|
-
host = lin[0];
|
|
50
|
-
alt = lin.slice(1, alt.length + 1);
|
|
38
|
+
if (!/^[A-Za-z]:[\\/]/u.test(ws))
|
|
39
|
+
throw new Error(`${ws} is not on a local Windows drive`);
|
|
40
|
+
const lin = (await call(w, who, "translating paths", WSLPATH, [win32.resolve(ws)])).split("\n")[0];
|
|
41
|
+
if (!info.mounts.some((m) => within(m, lin)))
|
|
42
|
+
throw new Error(`${lin} is not on a local Windows drive`);
|
|
43
|
+
host = lin;
|
|
51
44
|
const base = `${info.home}/.local/state/piroboros-ws/${hash}`;
|
|
52
45
|
const ext4 = `${base}/${id}`;
|
|
53
46
|
nm = p.places.map((place, i) => [`${ext4}/nm/${i}`, `/work/${place}`]);
|
|
@@ -83,15 +76,14 @@ export async function dockerPick(s, d, ws, p) {
|
|
|
83
76
|
throw new Error(`image ${s.image} is not present; run docker pull ${s.image} in ${where}`);
|
|
84
77
|
if (p.prevDocker !== undefined)
|
|
85
78
|
await docker(d, c, ["rm", "-f", p.prevDocker.container]);
|
|
86
|
-
const mount = (src, dst
|
|
79
|
+
const mount = (src, dst) => {
|
|
87
80
|
if (!/^[^,:"\n]+$/u.test(src))
|
|
88
81
|
throw new Error(`${src} holds a character a Docker mount cannot take`);
|
|
89
|
-
return ["--mount", `type=bind,source=${src},target=${dst}
|
|
82
|
+
return ["--mount", `type=bind,source=${src},target=${dst}`];
|
|
90
83
|
};
|
|
91
|
-
const inside = alt.map((_, i) => (i === 0 ? "/piroboros-objects" : `/piroboros-objects-${i}`));
|
|
92
84
|
const name = `piroboros-ws-${hash}-${id}-${Date.now().toString(36)}`;
|
|
93
85
|
r = await docker(d, c, ["run", "-d", "--pull", "never", "--init", "--name", name, "--label", `piroboros.home=${hash}`, "--label", `piroboros.ws=${id}`, "--cap-drop", "ALL", "--security-opt", "no-new-privileges", "--pids-limit", "1024",
|
|
94
|
-
"--network", s.network ? "bridge" : "none", "-e", "HOME=/tmp", ...mount(host, "/work"), ...nm.flatMap(([src, dst]) => mount(src, dst)),
|
|
86
|
+
"--network", s.network ? "bridge" : "none", "-e", "HOME=/tmp", ...mount(host, "/work"), ...nm.flatMap(([src, dst]) => mount(src, dst)), "-w", "/work", ...user, s.image, "sleep", "infinity"], 30_000);
|
|
95
87
|
const container = /^[0-9a-f]{64}$/mu.exec(r.out)?.[0];
|
|
96
88
|
if (r.code !== 0 || container === undefined)
|
|
97
89
|
throw new Error(`docker run failed (${last(r.out) || "no container ID"})`);
|
|
@@ -109,10 +101,12 @@ export async function dockerPick(s, d, ws, p) {
|
|
|
109
101
|
}
|
|
110
102
|
if (s.network)
|
|
111
103
|
notice.push(win ? "Network: on. Confined commands can reach the WSL VM's network, which includes the Windows host, and can send any file they can see." : "Network: on. Confined commands can reach your network, and can send any file they can see.");
|
|
112
|
-
return { confine: { name: "docker", net: s.network, docker: c }, label: c.remote === undefined ? "docker" : `docker in WSL (${c.remote.distro})`, notice
|
|
104
|
+
return { confine: { name: "docker", net: s.network, docker: c }, label: c.remote === undefined ? "docker" : `docker in WSL (${c.remote.distro})`, notice };
|
|
113
105
|
}
|
|
114
106
|
/** Remove a Workspace's container, best effort. */
|
|
115
107
|
export const dockerRemove = (d, c) => docker(d, c, ["rm", "-f", c.container]);
|
|
108
|
+
/** End every process in a Workspace's container, best effort: `docker exec` processes outlive their command, and the host must not read or write the folder beside one. */
|
|
109
|
+
export const dockerKill = (d, c) => docker(d, c, ["kill", c.container]);
|
|
116
110
|
/** Remove every container of this home hash whose Workspace id is not open in this store; another home's containers carry another hash and are never listed. */
|
|
117
111
|
export async function dockerSweep(d, c, hash, open) {
|
|
118
112
|
const r = await docker(d, c, ["ps", "-a", "--no-trunc", "--filter", `label=piroboros.home=${hash}`, "--format", "{{.ID}}|{{.Labels}}"]);
|
package/dist/ws/git.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { createReadStream, existsSync } from "node:fs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { canonicalize } from "../paths.js";
|
|
5
|
-
// Host git for Workspaces.
|
|
6
|
-
//
|
|
7
|
-
//
|
|
6
|
+
// Host git for Workspaces. Every call here carries SAFE_GIT and gets an environment without any GIT_* name in any letter case,
|
|
7
|
+
// so nothing in the user's shell, a git hook parent or a Workspace config changes what it reads or runs. Calls are against the
|
|
8
|
+
// live repository, with one exception: `init`, `baseCommit` (`fast-import` and `read-tree`) build the Workspace's own repository at open, when the host has
|
|
9
|
+
// just written the folder and nothing of Vesperia's is in it. After that piroboros never runs git with a Workspace as the repository.
|
|
8
10
|
/** A message for the user: the reason a Workspace cannot open or a mode cannot be resolved, with the way out. */
|
|
9
11
|
export class WsRefusal extends Error {
|
|
10
12
|
}
|
|
@@ -27,8 +29,8 @@ export function gitEnv(literal, source = process.env) {
|
|
|
27
29
|
}
|
|
28
30
|
const firstLine = (text) => text.trim().split(/\r?\n/u)[0] ?? "";
|
|
29
31
|
const dubious = (project) => ` piroboros ignores GIT_* variables, including GIT_CONFIG_GLOBAL; run git config --global --add safe.directory ${project} in a shell where GIT_CONFIG_GLOBAL is not set.`;
|
|
30
|
-
/** The config keys copied into a git Workspace; everything else (fsmonitor, hooksPath, filters, includes, credentials) is dropped. */
|
|
31
|
-
const CONFIG_KEYS = /^(?:core\.(?:
|
|
32
|
+
/** The config keys copied into a git Workspace; everything else (fsmonitor, hooksPath, filters, includes, credentials, the repository format) is dropped. */
|
|
33
|
+
const CONFIG_KEYS = /^(?:core\.(?:bare|filemode|symlinks|ignorecase|precomposeunicode|autocrlf|eol|safecrlf|logallrefupdates|quotepath)|user\.(?:name|email)|remote\..+\.(?:url|fetch)|branch\..+\.(?:remote|merge))$/u;
|
|
32
34
|
export class HostGit {
|
|
33
35
|
home;
|
|
34
36
|
spy;
|
|
@@ -36,6 +38,7 @@ export class HostGit {
|
|
|
36
38
|
this.home = home;
|
|
37
39
|
this.spy = spy;
|
|
38
40
|
}
|
|
41
|
+
/** `feed` writes a large stdin itself (await `put` on each chunk); `input` is a small one. */
|
|
39
42
|
run(cwd, args, options = {}) {
|
|
40
43
|
const env = gitEnv(options.literal ?? true);
|
|
41
44
|
const argv = [...safeGit(this.home), ...args];
|
|
@@ -50,8 +53,13 @@ export class HostGit {
|
|
|
50
53
|
err += text; });
|
|
51
54
|
child.stdin.on("error", () => { });
|
|
52
55
|
child.on("error", (error) => reject(error.code === "ENOENT" ? new WsRefusal("git is not installed or not on PATH, so a Workspace cannot be made; install git, or set workspace.enabled to false to run in place") : error));
|
|
53
|
-
|
|
54
|
-
child.
|
|
56
|
+
let fed;
|
|
57
|
+
child.on("close", (code) => (fed !== undefined ? reject(fed) : resolve({ code, out: Buffer.concat(out), err })));
|
|
58
|
+
if (options.feed === undefined) {
|
|
59
|
+
child.stdin.end(options.input);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
options.feed(child.stdin).then(() => child.stdin.end(), (error) => { fed = error; child.kill(); });
|
|
55
63
|
});
|
|
56
64
|
}
|
|
57
65
|
fail(project, result, what) {
|
|
@@ -117,22 +125,87 @@ export class HostGit {
|
|
|
117
125
|
const r = await this.run(project, ["rev-parse", "HEAD"]);
|
|
118
126
|
return r.code === 0 ? r.out.toString("utf8").trim() : undefined;
|
|
119
127
|
}
|
|
120
|
-
/** The
|
|
121
|
-
async
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
throw this.fail(project, refs, "for-each-ref");
|
|
125
|
-
const head = knownHead === undefined ? await this.head(project) : knownHead === "" ? undefined : knownHead;
|
|
126
|
-
return [...new Set([...(head === undefined ? [] : [head]), ...refs.out.toString("utf8").split(/\r?\n/u).filter((id) => id !== "")])];
|
|
128
|
+
/** The branch HEAD is on, or undefined when it is detached. */
|
|
129
|
+
async branch(project) {
|
|
130
|
+
const r = await this.run(project, ["symbolic-ref", "-q", "--short", "HEAD"]);
|
|
131
|
+
return r.code === 0 && r.out.toString("utf8").trim() !== "" ? r.out.toString("utf8").trim() : undefined;
|
|
127
132
|
}
|
|
128
|
-
/**
|
|
129
|
-
async
|
|
130
|
-
|
|
131
|
-
return [];
|
|
132
|
-
const r = await this.run(project, ["cat-file", "--batch-check"], { input: `${ids.join("\n")}\n` });
|
|
133
|
+
/** A new empty repository in `folder` (no hook templates), HEAD on `branch` when given. See the note at the top: this runs against a Workspace. */
|
|
134
|
+
async init(folder, branch) {
|
|
135
|
+
const r = await this.run(folder, ["init", "-q", "--template="]);
|
|
133
136
|
if (r.code !== 0)
|
|
134
|
-
throw this.fail(
|
|
135
|
-
|
|
137
|
+
throw this.fail(folder, r, "init");
|
|
138
|
+
if (branch === undefined)
|
|
139
|
+
return;
|
|
140
|
+
const h = await this.run(folder, [`--git-dir=${join(folder, ".git")}`, "symbolic-ref", "HEAD", `refs/heads/${branch}`]);
|
|
141
|
+
if (h.code !== 0)
|
|
142
|
+
throw this.fail(folder, h, "symbolic-ref");
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Make the one base commit of `folder` from the copied files (fixed identity), as one `fast-import` stream of the raw bytes, then `read-tree` for the index. Neither runs a clean
|
|
146
|
+
* filter, an eol conversion or a hook, so no filter of the user's global or system git config runs on the host, and a few loose objects stay out of the Workspace.
|
|
147
|
+
* Each file is read from `folder` once, one at a time. See the note at the top: this runs against a Workspace.
|
|
148
|
+
*/
|
|
149
|
+
async baseCommit(folder, files) {
|
|
150
|
+
const where = [`--git-dir=${join(folder, ".git")}`, `--work-tree=${folder}`];
|
|
151
|
+
const ref = await this.run(folder, [...where, "symbolic-ref", "-q", "HEAD"]);
|
|
152
|
+
const branch = ref.out.toString("utf8").trim();
|
|
153
|
+
if (ref.code !== 0 || !branch.startsWith("refs/heads/"))
|
|
154
|
+
throw this.fail(folder, ref, "symbolic-ref");
|
|
155
|
+
const quote = (path) => `"${path.replace(/[\\"\x00-\x1f\x7f]/gu, (c) => (c === "\\" || c === '"' ? `\\${c}` : `\\${c.charCodeAt(0).toString(8).padStart(3, "0")}`))}"`;
|
|
156
|
+
const put = (w, chunk) => (w.write(chunk) || w.destroyed ? Promise.resolve() : new Promise((done) => { const end = () => { w.off("drain", end); w.off("close", end); done(); }; w.once("drain", end); w.once("close", end); }));
|
|
157
|
+
const feed = async (w) => {
|
|
158
|
+
// Small pieces gather into ~256 KiB writes: a pipe write per piece costs more than reading the file. A big file streams through.
|
|
159
|
+
let batch = [];
|
|
160
|
+
let held = 0;
|
|
161
|
+
const add = async (chunk) => { const b = typeof chunk === "string" ? Buffer.from(chunk) : chunk; batch.push(b); held += b.length; if (held >= 262_144)
|
|
162
|
+
await flush(); };
|
|
163
|
+
const flush = async () => { const b = Buffer.concat(batch); batch = []; held = 0; await put(w, b); };
|
|
164
|
+
await add(`commit ${branch}\ncommitter piroboros <piroboros@localhost> ${Math.floor(Date.now() / 1000)} +0000\ndata <<EOM\npiroboros Workspace base\nEOM\n`);
|
|
165
|
+
// A file read costs about 0.7 ms here, so 16 small files are read ahead (at most 16 MiB held); each result is the bytes, or the error to throw in its turn.
|
|
166
|
+
const small = (f) => f.link === undefined && f.size <= 1_048_576;
|
|
167
|
+
const ahead = [];
|
|
168
|
+
let next = 0;
|
|
169
|
+
for (let i = 0; i < files.length; i += 1) {
|
|
170
|
+
while (ahead.length < 16 && next < files.length) {
|
|
171
|
+
const g = files[next++];
|
|
172
|
+
ahead.push(small(g) ? readFile(join(folder, g.path)).catch((error) => error) : Promise.resolve(Buffer.alloc(0)));
|
|
173
|
+
}
|
|
174
|
+
const f = files[i];
|
|
175
|
+
const bytes = await ahead.shift();
|
|
176
|
+
if (bytes instanceof Error)
|
|
177
|
+
throw bytes;
|
|
178
|
+
if (w.destroyed)
|
|
179
|
+
return;
|
|
180
|
+
await add(`M ${f.mode} inline ${quote(f.path)}\n`);
|
|
181
|
+
if (f.link !== undefined) {
|
|
182
|
+
const text = Buffer.from(f.link);
|
|
183
|
+
await add(`data ${text.length}\n`);
|
|
184
|
+
await add(text);
|
|
185
|
+
}
|
|
186
|
+
else if (small(f)) {
|
|
187
|
+
if (bytes.length !== f.size)
|
|
188
|
+
throw new Error(`${f.path} changed while it was committed`);
|
|
189
|
+
await add(`data ${f.size}\n`);
|
|
190
|
+
await add(bytes);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
await add(`data ${f.size}\n`);
|
|
194
|
+
await flush();
|
|
195
|
+
for await (const chunk of createReadStream(join(folder, f.path)))
|
|
196
|
+
await put(w, chunk);
|
|
197
|
+
}
|
|
198
|
+
await add("\n");
|
|
199
|
+
}
|
|
200
|
+
await add("done\n");
|
|
201
|
+
await flush();
|
|
202
|
+
};
|
|
203
|
+
const imported = await this.run(folder, [...where, "fast-import", "--quiet", "--done", "--date-format=raw"], { feed });
|
|
204
|
+
if (imported.code !== 0)
|
|
205
|
+
throw this.fail(folder, imported, "fast-import");
|
|
206
|
+
const index = await this.run(folder, [...where, "read-tree", "HEAD"]);
|
|
207
|
+
if (index.code !== 0)
|
|
208
|
+
throw this.fail(folder, index, "read-tree");
|
|
136
209
|
}
|
|
137
210
|
/** The live repository's own config reduced to the allowed keys, as a fresh INI text. Every remote gets a push URL that fails. */
|
|
138
211
|
async copyConfig(gitDir) {
|