@bakers-build/addon-runtime-bwrap 0.9.1-next.5 → 0.9.1-next.6

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.
Files changed (2) hide show
  1. package/dist/src/backend.js +36 -30
  2. package/package.json +4 -4
@@ -1,8 +1,7 @@
1
- import { execFileSync } from 'node:child_process';
2
1
  import { accessSync, constants, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
3
2
  import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
4
3
  import { fileURLToPath } from 'node:url';
5
- import { gitSandboxPaths, quarantinePlanted, shellQuote, } from '@bakers-build/core';
4
+ import { shellQuote } from '@bakers-build/core';
6
5
  const SYSTEM = [
7
6
  '/usr',
8
7
  '/bin',
@@ -47,24 +46,33 @@ function softwarePaths(env) {
47
46
  /** Build an explicit filesystem view; no blanket bind of the host root or home. */
48
47
  function argv(input, options, deps) {
49
48
  const ws = resolve(input.workspacePath);
50
- const git = (flag) => execFileSync('git', ['-C', ws, 'rev-parse', '--path-format=absolute', flag], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
51
- const common = git('--git-common-dir');
52
- const gitDir = git('--git-dir');
53
- if (common === gitDir)
54
- throw new Error('runtime-bwrap requires a linked Git worktree; the main checkout stays outside the run');
55
- const worktreeConfig = join(gitDir, 'config.worktree');
56
- if (!existsSync(worktreeConfig))
57
- writeFileSync(worktreeConfig, '');
58
- const gitPaths = gitSandboxPaths(ws);
59
- const protectedPaths = [...gitPaths.protect, join(ws, '.git'), deps.cliRoot];
60
- for (const path of input.writePaths ?? []) {
49
+ const gitDir = input.gitDir;
50
+ if (gitDir && within(realpathSync(gitDir), realpathSync(ws)))
51
+ throw new Error('runtime-bwrap: the run Git directory must stay outside the workspace');
52
+ const protectedPaths = [
53
+ resolve(deps.cachePath),
54
+ ...(gitDir ? [gitDir] : []),
55
+ ...(input.sharedObjects ? [input.sharedObjects] : []),
56
+ join(ws, '.git'),
57
+ deps.cliRoot,
58
+ ...(options.readPaths ?? []),
59
+ ...(input.readPaths ?? []),
60
+ ];
61
+ const binds = input.bindPaths ?? [];
62
+ for (const { target } of binds)
63
+ if (!within(resolve(target), resolve(input.homePath)))
64
+ throw new Error(`runtime-bwrap: shared file target outside the run home ${target}`);
65
+ for (const path of [
66
+ ...(input.writePaths ?? []),
67
+ ...binds.map(({ source }) => source),
68
+ ]) {
61
69
  if (!isAbsolute(path) ||
62
70
  protectedPaths.some((root) => within(realpathSync(path), existsSync(root) ? realpathSync(root) : resolve(root)) ||
63
71
  within(existsSync(root) ? realpathSync(root) : resolve(root), realpathSync(path))))
64
72
  throw new Error(`runtime-bwrap: protected write path ${path}`);
65
73
  }
66
74
  const mounts = new Map();
67
- const mount = (path, write) => {
75
+ const check = (path) => {
68
76
  if (!isAbsolute(path) ||
69
77
  path === '/' ||
70
78
  (deps.env.HOME && within(deps.env.HOME, path)))
@@ -75,13 +83,18 @@ function argv(input, options, deps) {
75
83
  if (actual === '/' ||
76
84
  (deps.env.HOME && within(realpathSync(deps.env.HOME), actual)))
77
85
  throw new Error(`runtime-bwrap: refusing broad path ${path}`);
86
+ };
87
+ const mount = (path, write) => {
88
+ check(path);
78
89
  mounts.set(path, write);
79
90
  };
91
+ for (const { source } of binds)
92
+ check(source);
80
93
  for (const path of [
81
94
  ...SYSTEM.filter(existsSync),
82
95
  ...softwarePaths(deps.env),
83
96
  deps.cliRoot,
84
- common,
97
+ ...(input.sharedObjects ? [input.sharedObjects] : []),
85
98
  ...(options.readPaths ?? []),
86
99
  ...(input.readPaths ?? []),
87
100
  ])
@@ -89,12 +102,10 @@ function argv(input, options, deps) {
89
102
  for (const path of [
90
103
  ws,
91
104
  input.homePath,
92
- ...gitPaths.write,
93
105
  ...(input.writePaths ?? []),
94
106
  ])
95
107
  mount(path, true);
96
- for (const path of protectedPaths.filter(existsSync))
97
- mount(path, false);
108
+ mount(deps.cliRoot, false);
98
109
  const bindings = [...mounts].sort(([a], [b]) => a.split(sep).length - b.split(sep).length || a.localeCompare(b));
99
110
  return [
100
111
  '--unshare-user',
@@ -118,6 +129,10 @@ function argv(input, options, deps) {
118
129
  path,
119
130
  path,
120
131
  ]),
132
+ // The only Git the run sees; bwrap creates the empty mount point on the host.
133
+ ...(gitDir ? ['--bind', gitDir, join(ws, '.git')] : []),
134
+ // Shared host files over their placeholders, after the run home is mounted.
135
+ ...binds.flatMap(({ source, target }) => ['--bind', source, target]),
121
136
  '--chdir',
122
137
  ws,
123
138
  '--',
@@ -153,6 +168,8 @@ export function bwrapRuntime(options, deps) {
153
168
  XDG_CONFIG_HOME: join(homePath, '.config'),
154
169
  XDG_DATA_HOME: join(homePath, '.local/share'),
155
170
  };
171
+ if (within(realpathSync(deps.cachePath), realpathSync(input.workspacePath)))
172
+ throw new Error('runtime-bwrap: private state must stay outside the worktree');
156
173
  const planPath = `${homePath}.launch.json`;
157
174
  writeFileSync(planPath, JSON.stringify({
158
175
  bwrap: deps.bwrapPath ?? '/usr/bin/bwrap',
@@ -196,18 +213,7 @@ export function bwrapRuntime(options, deps) {
196
213
  throw new Error('runtime-bwrap: launcher did not stop; retaining the home');
197
214
  }
198
215
  }
199
- if (existsSync(planPath)) {
200
- const plan = JSON.parse(readFileSync(planPath, 'utf8'));
201
- const common = execFileSync('git', [
202
- '-C',
203
- plan.workspacePath,
204
- 'rev-parse',
205
- '--path-format=absolute',
206
- '--git-common-dir',
207
- ], { encoding: 'utf8' }).trim();
208
- await quarantinePlanted(plan.workspacePath, common);
209
- rmSync(planPath);
210
- }
216
+ rmSync(planPath, { force: true });
211
217
  rmSync(homePath, { recursive: true, force: true });
212
218
  rmSync(pidPath, { force: true });
213
219
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-runtime-bwrap",
3
- "version": "0.9.1-next.5",
3
+ "version": "0.9.1-next.6",
4
4
  "description": "Isolate complete agent runs with an external Bubblewrap sandbox.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -23,11 +23,11 @@
23
23
  "directory": "bakers-cli/addons/runtime-bwrap"
24
24
  },
25
25
  "peerDependencies": {
26
- "@bakers-build/conductor": "^0.9.1-next.5",
27
- "@bakers-build/core": "^0.9.1-next.5"
26
+ "@bakers-build/conductor": "^0.9.1-next.6",
27
+ "@bakers-build/core": "^0.9.1-next.6"
28
28
  },
29
29
  "bakersBuild": {
30
- "commit": "d9242cad6cabee1faf010b5d46ac1bac33f6e0a1",
30
+ "commit": "e7d9921d51d5c045f29ca7e35d1e6a348e6ddf08",
31
31
  "channel": "next"
32
32
  }
33
33
  }