@capybara-hq/plugin-sdk 0.1.0-rc.61 → 0.1.0-rc.63

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.
@@ -5,7 +5,9 @@
5
5
  * browser profile directories, other tool credential stores (cargo, 1Password, Vault, Terraform,
6
6
  * Claude, Codex, keyrings, pass, rclone, s3cmd), mise's config directory and the config files it
7
7
  * loads from the home (an `[env]` section may hold tokens; globbed names like `~/mise.<env>.toml`
8
- * are not listed), Maven and Gradle credential files, and shell histories. One source for
8
+ * are not listed), Maven and Gradle credential files, database and X11 credential files, and
9
+ * shell and REPL histories. Secrets a shell start file exports (`export TOKEN=…` in `~/.bashrc`)
10
+ * are not covered: start files stay readable so sandboxed shells behave as the owner's. One source for
9
11
  * the device, which denies them (and its own state directory), and the kernel, which never proposes
10
12
  * an approval for a path under one. Full access and auto mode run as the owner and do not apply
11
13
  * them: the command review does.
@@ -5,7 +5,9 @@
5
5
  * browser profile directories, other tool credential stores (cargo, 1Password, Vault, Terraform,
6
6
  * Claude, Codex, keyrings, pass, rclone, s3cmd), mise's config directory and the config files it
7
7
  * loads from the home (an `[env]` section may hold tokens; globbed names like `~/mise.<env>.toml`
8
- * are not listed), Maven and Gradle credential files, and shell histories. One source for
8
+ * are not listed), Maven and Gradle credential files, database and X11 credential files, and
9
+ * shell and REPL histories. Secrets a shell start file exports (`export TOKEN=…` in `~/.bashrc`)
10
+ * are not covered: start files stay readable so sandboxed shells behave as the owner's. One source for
9
11
  * the device, which denies them (and its own state directory), and the kernel, which never proposes
10
12
  * an approval for a path under one. Full access and auto mode run as the owner and do not apply
11
13
  * them: the command review does.
@@ -74,8 +76,40 @@ export const DEVICE_DENIED_SECRET_PATHS = Object.freeze([
74
76
  "~/.gradle/gradle.properties",
75
77
  "~/.gradle/develocity/keys.properties",
76
78
  "~/.gradle/enterprise/keys.properties",
79
+ // Database, X11 session and other credential files directly in the home (machine reach on
80
+ // Linux grants the files beside a denied path one by one)
81
+ "~/.pgpass",
82
+ "~/.my.cnf",
83
+ "~/.Xauthority",
84
+ "~/.ICEauthority",
85
+ "~/.config/hub",
86
+ "~/.boto",
87
+ "~/.dockercfg",
88
+ "~/.smbcredentials",
89
+ "~/.terraformrc",
90
+ "~/.yarnrc.yml",
91
+ "~/.databrickscfg",
92
+ "~/.passwd-s3fs",
93
+ "~/.erlang.cookie",
94
+ "~/.curlrc",
95
+ "~/.wgetrc",
96
+ "~/.claude.json",
97
+ // shell and REPL histories (commands with inlined secrets)
77
98
  "~/.bash_history",
78
99
  "~/.zsh_history",
100
+ "~/.psql_history",
101
+ "~/.mysql_history",
102
+ "~/.python_history",
103
+ "~/.node_repl_history",
104
+ "~/.sqlite_history",
105
+ "~/.histfile",
106
+ "~/.zhistory",
107
+ "~/.sh_history",
108
+ "~/.lesshst",
109
+ "~/.viminfo",
110
+ "~/.rediscli_history",
111
+ "~/.irb_history",
112
+ "~/.Rhistory",
79
113
  ]);
80
114
  /**
81
115
  * The device program's default state directory (`$XDG_CONFIG_HOME/capybara-device` when that is
@@ -295,6 +295,13 @@ export interface DeviceProvider {
295
295
  /**
296
296
  * Applies new limits to a running instance without recreating it (optional). `recreate` asks
297
297
  * the kernel to destroy the instance and create one on the same files instead.
298
+ *
299
+ * `updated` means the instance now enforces `limits.network`, and no later rebuild of the
300
+ * instance (resume, auto-start, a lost egress component) can enforce a wider network than this
301
+ * one. For a narrowing (a host removed, or a kind that allows less), answer `updated` only once
302
+ * no connection to a removed host survives and no new one can open; otherwise answer `recreate`
303
+ * or throw. A thrown `update` is the kernel's to handle (recreate, or quarantine and retry on the
304
+ * next use), so a repeated call with the same limits must be safe.
298
305
  */
299
306
  update?(h: SandboxHandle, limits: SandboxLimits, signal: AbortSignal): Promise<"updated" | "recreate">;
300
307
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.1.0-rc.61";
1
+ export declare const SDK_VERSION = "0.1.0-rc.63";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -33,7 +33,7 @@ export * from "./permissions.js";
33
33
  export * from "./plugin-manifest.js";
34
34
  export * from "./plugin-package.js";
35
35
  export * from "./push.js";
36
- export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
36
+ export { SANDBOX_RUNTIME_SOURCE, type SandboxRuntimeFeature, type SandboxRuntimeFile, } from "./sandbox-runtime-source.js";
37
37
  export { isSandboxHomeWriteDenied, isSandboxMoveDenied, isSandboxWriteDenied, SANDBOX_GIT_ALLOWED_DIRECTORIES, SANDBOX_GIT_ALLOWED_FILES, SANDBOX_GIT_DENIED_INTERNALS, SANDBOX_HOME_WRITE_DENIES, SANDBOX_MANDATORY_WRITE_DENIES, SANDBOX_PROTECTED_PATH_NAMES, SANDBOX_RESERVED_NAME_PREFIX, SANDBOX_RUNTIME_DIRECTORIES, SANDBOX_SYSTEM_WRITE_DENIES, sandboxRuntimeDirectoryOf, } from "./sandbox-write-denies.js";
38
38
  export * from "./secret.js";
39
39
  export * from "./setup-check.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const SDK_VERSION = "0.1.0-rc.61";
1
+ export const SDK_VERSION = "0.1.0-rc.63";
2
2
  export * from "./agent-template.js";
3
3
  export * from "./avatar-presets.js";
4
4
  export * from "./bootstrap.js";
@@ -33,7 +33,7 @@ export * from "./permissions.js";
33
33
  export * from "./plugin-manifest.js";
34
34
  export * from "./plugin-package.js";
35
35
  export * from "./push.js";
36
- export { SANDBOX_RUNTIME_SOURCE } from "./sandbox-runtime-source.js";
36
+ export { SANDBOX_RUNTIME_SOURCE, } from "./sandbox-runtime-source.js";
37
37
  export { isSandboxHomeWriteDenied, isSandboxMoveDenied, isSandboxWriteDenied, SANDBOX_GIT_ALLOWED_DIRECTORIES, SANDBOX_GIT_ALLOWED_FILES, SANDBOX_GIT_DENIED_INTERNALS, SANDBOX_HOME_WRITE_DENIES, SANDBOX_MANDATORY_WRITE_DENIES, SANDBOX_PROTECTED_PATH_NAMES, SANDBOX_RESERVED_NAME_PREFIX, SANDBOX_RUNTIME_DIRECTORIES, SANDBOX_SYSTEM_WRITE_DENIES, sandboxRuntimeDirectoryOf, } from "./sandbox-write-denies.js";
38
38
  export * from "./secret.js";
39
39
  export * from "./setup-check.js";
@@ -3,7 +3,9 @@
3
3
  * beside `native-files.py` by a trusted consumer that verifies both digests.
4
4
  *
5
5
  * Transport: `python3 -I linux-sandbox.py probe` prints the capability report. Otherwise one JSON
6
- * request on stdin: `{mode: "exec" | "native", roots: {read, write: [{path, fd, dev, ino}]},
6
+ * request on stdin: `{mode: "exec" | "native", roots: {read, write: [{path, fd, dev, ino}],
7
+ * readFiles? (exec only: single regular files granted read without their directory; one
8
+ * renamed, deleted or hard-linked since the pin is skipped, a wrong type or identity refused)},
7
9
  * network: {kind: "none" | "environment"} | {kind: "endpoints", endpoints: [{address, port}]},
8
10
  * reportFd, cwd?, env?, argv (exec), timeoutMs? (exec), native (native-files request),
9
11
  * nativeFd? (exec: an inherited, consumer-verified descriptor of native-files.py, e.g. a sealed
@@ -13,7 +15,9 @@
13
15
  * every root, shared by all operations of the device; see native-files.py DeviceFilesLock)}`.
14
16
  * Root descriptors are pinned once by the consumer and inherited; the launcher verifies their
15
17
  * identity and never reopens a root pathname. Landlock rules, broker metadata checks and the
16
- * native helper all use those same descriptors. JSON events (`launch`, `exit`, `refused`) go to
18
+ * native helper all use those same descriptors. A file root (`readFiles`) is an O_PATH, no-follow
19
+ * descriptor of the regular file itself; it becomes one Landlock rule granting file reads only
20
+ * (no directory listing, no execution) and never reaches the broker or the native helper. JSON events (`launch`, `exit`, `refused`) go to
17
21
  * reportFd, which the restricted child cannot write. SIGTERM cancels the whole owned tree.
18
22
  * Full access never uses this launcher: it has no restricted filters.
19
23
  *
@@ -505,10 +509,18 @@ def install_filter(table, program, listener):
505
509
  # ---- roots and Landlock -------------------------------------------------------------------
506
510
 
507
511
  def verify_roots(native, request):
508
- """Validates pinned descriptors against their recorded identity without reopening paths."""
509
- result = {"read": [], "write": []}
512
+ """Validates pinned descriptors against their recorded identity without reopening paths.
513
+ Read and write roots are directories; a file root (readFiles, exec mode only) is a regular
514
+ file whose descriptor the consumer opened O_PATH | O_NOFOLLOW, so a symbolic link, directory,
515
+ FIFO, socket or device given as a file root is refused here, as is a wrong recorded identity.
516
+ A file root whose pinned file no longer sits at its path (renamed or deleted since the pin:
517
+ editors and atomic saves do this) or has more than one name (a hard link could share a denied
518
+ file's inode) is skipped: no rule, no refusal, the path stays unreadable."""
519
+ result = {"read": [], "write": [], "readFiles": []}
510
520
  seen = []
511
- for kind in ("read", "write"):
521
+ if request.get("roots", {}).get("readFiles") and request.get("mode") != "exec":
522
+ raise Refused("INVALID_REQUEST", "File roots serve exec mode only")
523
+ for kind in ("read", "write", "readFiles"):
512
524
  for entry in request.get("roots", {}).get(kind, []):
513
525
  path, fd = entry.get("path"), entry.get("fd")
514
526
  if not isinstance(path, str) or type(fd) is not int or not native.valid_path(path) \
@@ -520,10 +532,18 @@ def verify_roots(native, request):
520
532
  except OSError:
521
533
  raise Refused("ROOT_CHANGED", "A pinned root descriptor is not available")
522
534
  identity = [entry.get("dev"), entry.get("ino")]
523
- if not stat.S_ISDIR(info.st_mode) or identity != [info.st_dev, info.st_ino] \
535
+ os.set_inheritable(fd, False)
536
+ if kind == "readFiles":
537
+ if not stat.S_ISREG(info.st_mode):
538
+ raise Refused("ROOT_CHANGED", "A pinned file root is not a regular file")
539
+ if identity != [info.st_dev, info.st_ino]:
540
+ raise Refused("ROOT_CHANGED", "A pinned root no longer names its recorded object")
541
+ if where != path or info.st_nlink != 1:
542
+ # renamed, deleted or given a second name since the pin: grant nothing for it
543
+ continue
544
+ elif not stat.S_ISDIR(info.st_mode) or identity != [info.st_dev, info.st_ino] \
524
545
  or where != path:
525
546
  raise Refused("ROOT_CHANGED", "A pinned root no longer names its recorded object")
526
- os.set_inheritable(fd, False)
527
547
  result[kind].append({"path": path, "fd": fd})
528
548
  seen.append({"kind": kind, "path": path, "fd": fd, "dev": info.st_dev,
529
549
  "ino": info.st_ino})
@@ -548,6 +568,10 @@ def landlock_ruleset(roots, system_roots, network_mediated, brokered_writes=Fals
548
568
  for root in roots["write"]:
549
569
  # Brokered: the command reads its write roots; the broker performs every write.
550
570
  rule(root["fd"], FS_READ if brokered_writes else FS_ALL)
571
+ for root in roots["readFiles"]:
572
+ # The file's own inode, read only: no READ_DIR (a file has no listing to grant, and its
573
+ # directory gets no rule from it) and no EXECUTE.
574
+ rule(root["fd"], FS_READ_FILE)
551
575
  opened = []
552
576
  try:
553
577
  for path in system_roots:
@@ -1884,8 +1908,9 @@ def device_files_lock(request, roots, system_roots):
1884
1908
  raise Refused("INVALID_REQUEST", "The files lock descriptor is not open")
1885
1909
  if not stat.S_ISREG(info.st_mode) or not where.startswith("/") or where.endswith(" (deleted)"):
1886
1910
  raise Refused("INVALID_REQUEST", "The files lock is not a regular file")
1887
- reach = [r["path"] for r in roots["read"] + roots["write"]] + list(system_roots)
1888
- for entry in roots["read"] + roots["write"]:
1911
+ granted = roots["read"] + roots["write"] + roots["readFiles"]
1912
+ reach = [r["path"] for r in granted] + list(system_roots)
1913
+ for entry in granted:
1889
1914
  try:
1890
1915
  reach.append(os.readlink("/proc/self/fd/%d" % entry["fd"]))
1891
1916
  except OSError:
@@ -1,3 +1,16 @@
1
+ /**
2
+ * A capability of a runtime file that a consumer may use only when the file it runs declares it.
3
+ * `fileReadRoots`: `linux-sandbox.py` accepts exact file read roots (`roots.readFiles`, exec mode).
4
+ */
5
+ export type SandboxRuntimeFeature = "fileReadRoots";
6
+ /** One runtime file: its exact bytes and their sha256 (hex). */
7
+ export interface SandboxRuntimeFile {
8
+ readonly name: string;
9
+ readonly source: string;
10
+ readonly sha256: string;
11
+ /** What this revision supports beyond the bundle's base protocol; absent means nothing more. */
12
+ readonly features?: readonly SandboxRuntimeFeature[];
13
+ }
1
14
  /**
2
15
  * Immutable runtime bytes for trusted consumer staging (requires Python 3). Consumers verify every
3
16
  * hash before use, stage the files together in a directory the operation user cannot write, and
@@ -8,12 +21,27 @@
8
21
  * notification broker). It decides nothing about authority; its `probe` reports whether the
9
22
  * running kernel, architecture and container policy support restricted execution, and every
10
23
  * unsupported case reports unavailable. Shipping these bytes is not a provider support claim.
24
+ *
25
+ * Two sets, because an image provider (device-docker) builds the bytes into its image in another
26
+ * repository and release, while the host SDK moves with the kernel:
27
+ *
28
+ * - `files`: the staged set, exactly what released image providers stage and check against the
29
+ * host SDK. It changes only in the core change that moves `marketplace.commit` and the
30
+ * device-docker pin to an image staging it.
31
+ * - `current`: the newest runtime. A consumer that carries the bytes itself (capybara-device sends
32
+ * them inline with every request) runs these, and uses a capability only when the file it runs
33
+ * declares it in `features`; an image provider restages from these.
34
+ * - `accepted`: by file name, every digest a staged copy may have: `files` and `current`, plus at
35
+ * most one previous revision kept for instances built from an earlier image. Only SDK-shipped
36
+ * digests are listed; nothing configures this.
37
+ *
38
+ * A runtime change therefore lands in three steps (tools/checks/README.md, "Changing the SDK
39
+ * runtime sources"): `current` first, then the provider restages, then core promotes `current` to
40
+ * `files` with the pin. Between changes, as now, `current` is `files`.
11
41
  */
12
42
  export declare const SANDBOX_RUNTIME_SOURCE: {
13
43
  readonly version: number;
14
- readonly files: readonly {
15
- readonly name: string;
16
- readonly source: string;
17
- readonly sha256: string;
18
- }[];
44
+ readonly files: readonly SandboxRuntimeFile[];
45
+ readonly current: readonly SandboxRuntimeFile[];
46
+ readonly accepted: Readonly<Record<string, readonly string[]>>;
19
47
  };
@@ -1,5 +1,42 @@
1
1
  import { LINUX_SANDBOX_SOURCE } from "./sandbox-linux-runtime-source.js";
2
2
  import { NATIVE_FILES_SOURCE } from "./sandbox-native-runtime-source.js";
3
+ const NATIVE_FILES = Object.freeze({
4
+ name: "native-files.py",
5
+ source: NATIVE_FILES_SOURCE,
6
+ sha256: "c1712198af4ffedc0b48f789c28ed4233dc9008521b897300731c4f903168950",
7
+ });
8
+ const LINUX_SANDBOX = Object.freeze({
9
+ name: "linux-sandbox.py",
10
+ source: LINUX_SANDBOX_SOURCE,
11
+ sha256: "ceb5bb0971437978a7695091792bfafcf3dbf2e7c74e8425d8aceb76e442f848",
12
+ features: Object.freeze(["fileReadRoots"]),
13
+ });
14
+ const STAGED = Object.freeze([NATIVE_FILES, LINUX_SANDBOX]);
15
+ const CURRENT = STAGED;
16
+ /**
17
+ * Digests of earlier revisions a staged copy may still have (one previous revision at most):
18
+ * device containers made from an earlier image keep their staged runtime until recreated. The
19
+ * launcher before exact file read roots (core#742); the next runtime change drops it.
20
+ */
21
+ const PREVIOUS = Object.freeze([
22
+ Object.freeze({
23
+ name: "linux-sandbox.py",
24
+ sha256: "4e046df902dc644532ada9f2a3bef30a983daf7d1f238bd46dcd16524d96c66c",
25
+ }),
26
+ ]);
27
+ function acceptedDigests(...sets) {
28
+ const out = {};
29
+ for (const set of sets)
30
+ for (const file of set) {
31
+ const list = out[file.name] ?? [];
32
+ if (!list.includes(file.sha256))
33
+ list.push(file.sha256);
34
+ out[file.name] = list;
35
+ }
36
+ for (const name of Object.keys(out))
37
+ Object.freeze(out[name]);
38
+ return Object.freeze(out);
39
+ }
3
40
  /**
4
41
  * Immutable runtime bytes for trusted consumer staging (requires Python 3). Consumers verify every
5
42
  * hash before use, stage the files together in a directory the operation user cannot write, and
@@ -10,19 +47,27 @@ import { NATIVE_FILES_SOURCE } from "./sandbox-native-runtime-source.js";
10
47
  * notification broker). It decides nothing about authority; its `probe` reports whether the
11
48
  * running kernel, architecture and container policy support restricted execution, and every
12
49
  * unsupported case reports unavailable. Shipping these bytes is not a provider support claim.
50
+ *
51
+ * Two sets, because an image provider (device-docker) builds the bytes into its image in another
52
+ * repository and release, while the host SDK moves with the kernel:
53
+ *
54
+ * - `files`: the staged set, exactly what released image providers stage and check against the
55
+ * host SDK. It changes only in the core change that moves `marketplace.commit` and the
56
+ * device-docker pin to an image staging it.
57
+ * - `current`: the newest runtime. A consumer that carries the bytes itself (capybara-device sends
58
+ * them inline with every request) runs these, and uses a capability only when the file it runs
59
+ * declares it in `features`; an image provider restages from these.
60
+ * - `accepted`: by file name, every digest a staged copy may have: `files` and `current`, plus at
61
+ * most one previous revision kept for instances built from an earlier image. Only SDK-shipped
62
+ * digests are listed; nothing configures this.
63
+ *
64
+ * A runtime change therefore lands in three steps (tools/checks/README.md, "Changing the SDK
65
+ * runtime sources"): `current` first, then the provider restages, then core promotes `current` to
66
+ * `files` with the pin. Between changes, as now, `current` is `files`.
13
67
  */
14
68
  export const SANDBOX_RUNTIME_SOURCE = Object.freeze({
15
69
  version: 2,
16
- files: Object.freeze([
17
- Object.freeze({
18
- name: "native-files.py",
19
- source: NATIVE_FILES_SOURCE,
20
- sha256: "c1712198af4ffedc0b48f789c28ed4233dc9008521b897300731c4f903168950",
21
- }),
22
- Object.freeze({
23
- name: "linux-sandbox.py",
24
- source: LINUX_SANDBOX_SOURCE,
25
- sha256: "4e046df902dc644532ada9f2a3bef30a983daf7d1f238bd46dcd16524d96c66c",
26
- }),
27
- ]),
70
+ files: STAGED,
71
+ current: CURRENT,
72
+ accepted: acceptedDigests(STAGED, CURRENT, PREVIOUS),
28
73
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-sdk",
3
- "version": "0.1.0-rc.61",
3
+ "version": "0.1.0-rc.63",
4
4
  "description": "Capybara plugin SDK: the types and pure functions plugins are written against",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {