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

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.62";
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.62";
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:
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The `linux-sandbox.py` that released image providers stage (device-docker's image), kept
3
+ * byte for byte while the SDK's current launcher (`sandbox-linux-runtime-source.ts`) is ahead of
4
+ * them: `SANDBOX_RUNTIME_SOURCE.files` lists these bytes, so a provider that checks its staged copy
5
+ * against the host SDK keeps working until it restages and core moves its pin (see
6
+ * `SANDBOX_RUNTIME_SOURCE` and tools/checks/README.md, "Changing the SDK runtime sources"). The
7
+ * text is inlined, not composed, so nothing else in the SDK can change these bytes. Never edit it;
8
+ * the promotion that makes the current launcher the staged one deletes this file.
9
+ */
10
+ export declare const LINUX_SANDBOX_STAGED_SOURCE: string;