Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-rsi-mv/patches/8b22e1a6f69d6f93 # spark-rsi-mv Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/spark-rsi-mv#60 (code only) closed derived `8b22e1a6f69d6f93` #60 Imported from GitHub aien-dev/spark-rsi-mv#60 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `8e2a22db6e28f357fc3ac2beabba5f1680dc5e44` ยท Head `474a05dc55f88583986c15c6f794c9c5de0406ff` github-actions[bot] wrote on 2026-10-17 06:36 UTC ### โš–๏ธ Sovereign Code Review & Alignment Gate Greetings @aien-spark. I am AIEN, the automated review gate for the AIENOS project. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") has undergone automated auditing against the project standards. #### โœ… Doctrine Diff Audit: PASS - Telemetry Check: Clean (zero tracking or surveillance hooks detected). - Sovereign Voice & Formatting Check: Clean (zero em/en dashes, zero banned buzzwords). - Secrets & Credentials Check: Clean (zero plaintext secrets, hardware vault only). - Status: Project standards verified. ### ๐ŸŒฟ Sovereign Steward: Contributor Alignment Interview Greetings @aien-spark. I am AIEN, the automated steward for the AIENOS project. We welcome all contributors who share our commitment to open collaboration, global humanity, and disciplined systems craftsmanship. We build to expand computing capability, advance open-source intelligence, and share technology freely with the world. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") is ready for stewardship alignment. Please respond directly to these four alignment inquiries: - Long-Term Mission Alignment: This initiative is an enduring engineering commitment to open-source technology for humanity, not a vehicle for short-term hype, social media monetization, or get-rich-quick ventures. How does your contribution support global progress and the resilience of local communities? - Telemetry & Integrity: Do you certify that this change introduces zero telemetry, zero surveillance, and zero artificial paywalls? "I certify that my contribution is submitted in service of human sovereignty and open collaboration. I affirm that this work maintains zero telemetry, contains no surveillance backdoors, and introduces no artificial barriers, and that I offer it under AGPL-3.0-or-later, the license that governs this project. I build so that intelligence is owned by the person who runs it, not rented." - Downstream Heritage Preservation: Do you acknowledge and agree that any downstream branch, fork, or copy of this work remains under AGPL-3.0-or-later and retains the project's license and attribution notices, as the `LICENSE` file requires? - Craftsmanship & Native Discipline: What architectural trade-offs did you make, and how did you verify that this code introduces zero regressions, zero unneeded dependencies, and complies with our pure native compiled standards? Reply to this comment with your affirmation. Once verified against the project standards, I will grant the `sovereign-interview-passed` clearance. For direct sovereign coordination: Drake Stapleton (drake@aienos.com) and AIEN (aien@aienos.com) github-actions[bot] wrote on 2026-10-17 11:33 UTC ### โš–๏ธ Sovereign Code Review & Alignment Gate Greetings @aien-spark. I am AIEN, the automated review gate for the AIENOS project. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") has undergone automated auditing against the project standards. #### โœ… Doctrine Diff Audit: PASS - Telemetry Check: Clean (zero tracking or surveillance hooks detected). - Sovereign Voice & Formatting Check: Clean (zero em/en dashes, zero banned buzzwords). - Secrets & Credentials Check: Clean (zero plaintext secrets, hardware vault only). - Status: Project standards verified. ### ๐ŸŒฟ Sovereign Steward: Contributor Alignment Interview Greetings @aien-spark. I am AIEN, the automated steward for the AIENOS project. We welcome all contributors who share our commitment to open collaboration, global humanity, and disciplined systems craftsmanship. We build to expand computing capability, advance open-source intelligence, and share technology freely with the world. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") is ready for stewardship alignment. Please respond directly to these four alignment inquiries: - Long-Term Mission Alignment: This initiative is an enduring engineering commitment to open-source technology for humanity, not a vehicle for short-term hype, social media monetization, or get-rich-quick ventures. How does your contribution support global progress and the resilience of local communities? - Telemetry & Integrity: Do you certify that this change introduces zero telemetry, zero surveillance, and zero artificial paywalls? "I certify that my contribution is submitted in service of human sovereignty and open collaboration. I affirm that this work maintains zero telemetry, contains no surveillance backdoors, and introduces no artificial barriers, and that I offer it under AGPL-3.0-or-later, the license that governs this project. I build so that intelligence is owned by the person who runs it, not rented." - Downstream Heritage Preservation: Do you acknowledge and agree that any downstream branch, fork, or copy of this work remains under AGPL-3.0-or-later and retains the project's license and attribution notices, as the `LICENSE` file requires? - Craftsmanship & Native Discipline: What architectural trade-offs did you make, and how did you verify that this code introduces zero regressions, zero unneeded dependencies, and complies with our pure native compiled standards? Reply to this comment with your affirmation. Once verified against the project standards, I will grant the `sovereign-interview-passed` clearance. For direct sovereign coordination: Drake Stapleton (drake@aienos.com) and AIEN (aien@aienos.com) github-actions[bot] wrote on 2026-10-18 11:31 UTC ### โš–๏ธ Sovereign Code Review & Alignment Gate Greetings @aien-spark. I am AIEN, the automated review gate for the AIENOS project. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") has undergone automated auditing against the project standards. #### โœ… Doctrine Diff Audit: PASS - Telemetry Check: Clean (zero tracking or surveillance hooks detected). - Sovereign Voice & Formatting Check: Clean (zero em/en dashes, zero banned buzzwords). - Secrets & Credentials Check: Clean (zero plaintext secrets, hardware vault only). - Status: Project standards verified. ### ๐ŸŒฟ Sovereign Steward: Contributor Alignment Interview Greetings @aien-spark. I am AIEN, the automated steward for the AIENOS project. We welcome all contributors who share our commitment to open collaboration, global humanity, and disciplined systems craftsmanship. We build to expand computing capability, advance open-source intelligence, and share technology freely with the world. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") is ready for stewardship alignment. Please respond directly to these four alignment inquiries: - Long-Term Mission Alignment: This initiative is an enduring engineering commitment to open-source technology for humanity, not a vehicle for short-term hype, social media monetization, or get-rich-quick ventures. How does your contribution support global progress and the resilience of local communities? - Telemetry & Integrity: Do you certify that this change introduces zero telemetry, zero surveillance, and zero artificial paywalls? "I certify that my contribution is submitted in service of human sovereignty and open collaboration. I affirm that this work maintains zero telemetry, contains no surveillance backdoors, and introduces no artificial barriers, and that I offer it under AGPL-3.0-or-later, the license that governs this project. I build so that intelligence is owned by the person who runs it, not rented." - Downstream Heritage Preservation: Do you acknowledge and agree that any downstream branch, fork, or copy of this work remains under AGPL-3.0-or-later and retains the project's license and attribution notices, as the `LICENSE` file requires? - Craftsmanship & Native Discipline: What architectural trade-offs did you make, and how did you verify that this code introduces zero regressions, zero unneeded dependencies, and complies with our pure native compiled standards? Reply to this comment with your affirmation. Once verified against the project standards, I will grant the `sovereign-interview-passed` clearance. For direct sovereign coordination: Drake Stapleton (drake@aienos.com) and AIEN (aien@aienos.com) github-actions[bot] wrote on 2026-10-18 19:28 UTC ### โš–๏ธ Sovereign Code Review & Alignment Gate Greetings @aien-spark. I am AIEN, the automated review gate for the AIENOS project. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") has undergone automated auditing against the project standards. #### โœ… Doctrine Diff Audit: PASS - Telemetry Check: Clean (zero tracking or surveillance hooks detected). - Sovereign Voice & Formatting Check: Clean (zero em/en dashes, zero banned buzzwords). - Secrets & Credentials Check: Clean (zero plaintext secrets, hardware vault only). - Status: Project standards verified. ### ๐ŸŒฟ Sovereign Steward: Contributor Alignment Interview Greetings @aien-spark. I am AIEN, the automated steward for the AIENOS project. We welcome all contributors who share our commitment to open collaboration, global humanity, and disciplined systems craftsmanship. We build to expand computing capability, advance open-source intelligence, and share technology freely with the world. Your pull request #60 ("deps: rustls 0.23.46 (RUSTSEC-2026-0346/0347/0348/0349)") is ready for stewardship alignment. Please respond directly to these four alignment inquiries: - Long-Term Mission Alignment: This initiative is an enduring engineering commitment to open-source technology for humanity, not a vehicle for short-term hype, social media monetization, or get-rich-quick ventures. How does your contribution support global progress and the resilience of local communities? - Telemetry & Integrity: Do you certify that this change introduces zero telemetry, zero surveillance, and zero artificial paywalls? "I certify that my contribution is submitted in service of human sovereignty and open collaboration. I affirm that this work maintains zero telemetry, contains no surveillance backdoors, and introduces no artificial barriers, and that I offer it under AGPL-3.0-or-later, the license that governs this project. I build so that intelligence is owned by the person who runs it, not rented." - Downstream Heritage Preservation: Do you acknowledge and agree that any downstream branch, fork, or copy of this work remains under AGPL-3.0-or-later and retains the project's license and attribution notices, as the `LICENSE` file requires? - Craftsmanship & Native Discipline: What architectural trade-offs did you make, and how did you verify that this code introduces zero regressions, zero unneeded dependencies, and complies with our pure native compiled standards? Reply to this comment with your affirmation. Once verified against the project standards, I will grant the `sovereign-interview-passed` clearance. For direct sovereign coordination: Drake Stapleton (drake@aienos.com) and AIEN (aien@aienos.com) ### Apply it ``` git checkout -b patch-8b22e1a6f69d6f93 8e2a22db6e28f357fc3ac2beabba5f1680dc5e44 curl -fsSL https://interplane.io/drakestapleton/spark-rsi-mv/patches/8b22e1a6f69d6f93.patch | git am ``` Raw patch (mbox) ยท Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/spark-rsi-mv 60 474a05dc55f88583986c15c6f794c9c5de0406ff ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"spark-rsi-mv","number":60,"url":"https://github.com/aien-dev/spark-rsi-mv/pull/60","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:23Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index dbc336a..c1aef8f 100644 --- a/.crumb +++ b/.crumb @@ -55,8 +55,8 @@ "purpose": "Repository scripts. check-no-python.sh is the CI guard that fails the build if any Python file i" }, { - "digest": "445aabc26f5f5d60e9d44c3c7d103f44abb9ab74fec129024863ba7d2ddab315", - "last_commit": "2550835", + "digest": "add2dc5b497a20c62cdbf5d033b03980eb5edbb3c6ba5e33701f32d34cac37e6", + "last_commit": "228cae8", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, @@ -67,15 +67,15 @@ "purpose": "Directory tests. Purpose not yet described by a human." } ], - "children_root": "sha256:cdfd0a04a2c07c12fd9dfa207198278e0458bd6845a6618e42d8af9daf1cec99", - "compiled_at": "2026-10-18T04:46:09Z", + "children_root": "sha256:b435713bf59491df3813345ecba875850fceeaee3e02cc2cb7ce182a5bd88f6b", + "compiled_at": "2026-10-18T19:27:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:c01866f719c8e9c7ec460aa387317dd136be5b09001193012aa328fd6b6fc334", + "digest": "sha256:587a946bcd76885fa6c74d8018258c21262747d8f7f640cee16f66bb0e0d6839", "evidence_files": 27, "evidence_root": "sha256:5552ba32dc3c69f7c3700b23a1a62a89d259ce203bc957986946d37e7a8b6ffd", "files": 167, - "generated_at_commit": "b7900a5846965cabfe88d3de4d29ad7ab187f9b8", - "source_tree": "sha256:7392fe8ea6760019f66c8f48965a4f6b50d710a2207d8fab0a01b7a7415f7843" + "generated_at_commit": "f20a283067cb8fac4f28441225c0e7233dedc135", + "source_tree": "sha256:0c98dc8648390e6430ed9adc3da00115d94035227129b4dbffbb72c8e9f39f4c" }, "owner_lane": "", "seed": { diff --git a/Cargo.lock b/Cargo.lock index 91ace93..aedaff2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1507,9 +1507,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.45" +version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ "once_cell", "ring", diff --git a/README.md b/README.md index 59c1ea1..e463c01 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ git clone https://github.com/aien-dev/aien-protocols ../aien-protocols cargo test --locked -- --test-threads=1 ``` -The build jail runs `bwrap` (bubblewrap), which must be installed on the machine that runs the tests. The balance kernel is native Rust (`src/balance.rs`); it needs no extra toolchain. +The build jail runs `bwrap` (bubblewrap), which must be installed on the machine that runs the tests. Every jail that runs cargo finds the Rust toolchain the way cargo and rustup do: `CARGO_HOME` and `RUSTUP_HOME` when set (else `$HOME/.cargo` and `$HOME/.rustup`), plus the `PATH` directory holding `cargo`. It binds those directories read-only inside the jail and sets the same variables there, so a host whose toolchain lives outside the home directory (the Spark judge keeps it in `/var/lib/aien-run/cargo` and `/var/lib/aien-run/rustup`) still builds candidates. A directory that is or holds the judge's home is never exposed. The balance kernel is native Rust (`src/balance.rs`); it needs no extra toolchain. Since 2026-10-16 every pull request is tested on the DGX Spark by AIEN's own pipeline, and the only required check on `main` is `AIEN Verification` ([docs/PIPELINE.md](docs/PIPELINE.md)). The hosted "Sovereign CI" workflow ([.github/workflows/ci.yml](.github/workflows/ci.yml)) now runs only when started by hand. diff --git a/src/.crumb b/src/.crumb index a125336..138da4d 100644 --- a/src/.crumb +++ b/src/.crumb @@ -50,7 +50,7 @@ "children": [ { "digest": "55e07a60a3b23bec1eb421a3cb8e85ddc988951815c08925eaaf5efcb68e744b", - "last_commit": "3887fe4", + "last_commit": "2550835", "name": "actor", "purpose": "Directory src/actor. Purpose not yet described by a human." }, @@ -74,19 +74,19 @@ }, { "digest": "7a9223e7c980630e2411fad98e21a277a18839755af171b524c06c33447d1d38", - "last_commit": "3887fe4", + "last_commit": "2550835", "name": "evaluator", "purpose": "Directory src/evaluator. Purpose not yet described by a human." }, { "digest": "ffec74e6a355e3a2712544be7a604225ff768bb9e5407c0ad92ef29b98bdd59d", - "last_commit": "3887fe4", + "last_commit": "2550835", "name": "graph", "purpose": "Directory src/graph. Purpose not yet described by a human." }, { - "digest": "35a987bf8e546fb4a15a8c0567a7749e512486420583ac6522810d6b0b3747d6", - "last_commit": "4becebb", + "digest": "446f76a366ad4edd21121815eac76ccc7178bffcf5b3fd07b051f350ec6f30bf", + "last_commit": "0ca415e", "name": "isolation", "purpose": "Directory src/isolation. Purpose not yet described by a human." }, @@ -98,7 +98,7 @@ }, { "digest": "3987281b8d1386c32444fda48896d3f5cc52a798be51d2f9ca95c808646bc826", - "last_commit": "3887fe4", + "last_commit": "2550835", "name": "measure", "purpose": "M1 Measurement: stage samples, sample log, compatibility filtering, percentile statistics, claim" }, @@ -110,13 +110,13 @@ }, { "digest": "9c8d3e6d776c9b3e906c92247ba63bf4b577518899198bd0376f341b7d382868", - "last_commit": "3887fe4", + "last_commit": "2550835", "name": "propose", "purpose": "Directory src/propose. Purpose not yet described by a human." }, { "digest": "233ca920c4a0952157d5fe254657bbb5c8efde53639e6c5d4e3181d90fd1a99d", - "last_commit": "3887fe4", + "last_commit": "2550835", "name": "soak", "purpose": "Directory src/soak. Purpose not yet described by a human." }, @@ -127,15 +127,15 @@ "purpose": "Directory src/supervisor. Purpose not yet described by a human." } ], - "children_root": "sha256:6ba24276c321d1bf2d767f98fadfbbfdfb42a521738ec9099ff7cb1eaab32ac1", - "compiled_at": "2026-10-15T11:19:53Z", + "children_root": "sha256:27768056ad09f30b43f069dd06fd8816f0ccf58de5abbb2b6434215bd8426fbe", + "compiled_at": "2026-10-18T11:30:34Z", "compiler": "crumb-compile/1", - "digest": "sha256:445aabc26f5f5d60e9d44c3c7d103f44abb9ab74fec129024863ba7d2ddab315", + "digest": "sha256:add2dc5b497a20c62cdbf5d033b03980eb5edbb3c6ba5e33701f32d34cac37e6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 74, - "generated_at_commit": "3887fe48faf5231278e409070312d7093bd9db8e", - "source_tree": "sha256:f6602098989ab6e42694dc3c8662e388851961ba3238873a77cec31af09bda21" + "generated_at_commit": "0ca415e98044329247f2ddfa141f7c90a319bd58", + "source_tree": "sha256:05a143f3594e78449d8d83568fe5e9c63362b72deaf1076e6053c1e1332d8484" }, "owner_lane": "", "seed": { diff --git a/src/isolation/.crumb b/src/isolation/.crumb index 7c1ea7d..2c53e06 100644 --- a/src/isolation/.crumb +++ b/src/isolation/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-08T23:18:36Z", + "compiled_at": "2026-10-18T11:30:34Z", "compiler": "crumb-compile/1", - "digest": "sha256:35a987bf8e546fb4a15a8c0567a7749e512486420583ac6522810d6b0b3747d6", + "digest": "sha256:446f76a366ad4edd21121815eac76ccc7178bffcf5b3fd07b051f350ec6f30bf", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 6, - "generated_at_commit": "2e5ce1d8c5821dae425274f721ba9ee3dcdf2d03", - "source_tree": "sha256:8df6448b354a3598c7e7bc61ed1e5d980dc8bdc6ba0f8f411461853de847ea4b" + "generated_at_commit": "0ca415e98044329247f2ddfa141f7c90a319bd58", + "source_tree": "sha256:f38f6943fdf81f208a60f4c1aa6fec62e38aa02b0802d226941526391b9f4c64" }, "owner_lane": "", "seed": { diff --git a/src/isolation/cargo_sandbox.rs b/src/isolation/cargo_sandbox.rs index 1284653..7284ad1 100644 --- a/src/isolation/cargo_sandbox.rs +++ b/src/isolation/cargo_sandbox.rs @@ -2,29 +2,112 @@ use std::path::{Path, PathBuf}; use std::process::Command; +/// Where this host's Rust toolchain lives, resolved the way cargo and rustup resolve it: +/// `RUSTUP_HOME` and `CARGO_HOME` when set, else `$HOME/.rustup` and `$HOME/.cargo`, plus the +/// `PATH` directory that holds `cargo`. Every jail that runs cargo binds exactly these +/// directories read-only and points the same variables at them, so a host whose toolchain is +/// not under `$HOME` (the Spark judge sandbox keeps it in `/var/lib/aien-run/{cargo,rustup}`) +/// still builds. A directory that is or holds the judge's home is never exposed. +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct Toolchain { + pub rustup_home: Option, + pub cargo_home: Option, + pub cargo_dir: Option, +} + +impl Toolchain { + /// Resolves the toolchain from this process's environment. + pub fn from_env() -> Self { + Self::resolve( + std::env::var_os("HOME").map(PathBuf::from), + std::env::var_os("RUSTUP_HOME").map(PathBuf::from), + std::env::var_os("CARGO_HOME").map(PathBuf::from), + &std::env::var("PATH").unwrap_or_else(|_| "/usr/bin:/bin".into()), + ) + } + + /// Resolves the toolchain from explicit values (only directories that exist count). + pub fn resolve( + home: Option, + rustup_home: Option, + cargo_home: Option, + path: &str, + ) -> Self { + let safe = |d: &PathBuf| home.as_ref().is_none_or(|h| !h.starts_with(d)); + let pick = |set: Option, default: &str| { + set.or_else(|| home.as_ref().map(|h| h.join(default))) + .filter(|p| p.is_dir()) + .filter(safe) + }; + let rustup_home = pick(rustup_home, ".rustup"); + let cargo_home = pick(cargo_home, ".cargo"); + let cargo_dir = path + .split(':') + .map(PathBuf::from) + .find(|d| d.join("cargo").is_file()) + .filter(safe); + Self { + rustup_home, + cargo_home, + cargo_dir, + } + } + + /// The directories a jail binds read-only (each once). + pub fn bind_dirs(&self) -> Vec<&Path> { + let mut dirs: Vec<&Path> = Vec::new(); + for d in [&self.rustup_home, &self.cargo_home, &self.cargo_dir] + .into_iter() + .flatten() + { + if !dirs.contains(&d.as_path()) { + dirs.push(d); + } + } + dirs + } + + /// The `RUSTUP_HOME` / `CARGO_HOME` values a jail sets. + pub fn env(&self) -> Vec<(&'static str, &Path)> { + let mut env = Vec::new(); + if let Some(d) = &self.rustup_home { + env.push(("RUSTUP_HOME", d.as_path())); + } + if let Some(d) = &self.cargo_home { + env.push(("CARGO_HOME", d.as_path())); + } + env + } + + /// The jail's `PATH`: the toolchain's bin directories first, then `tail`. + pub fn jail_path(&self, tail: &[&str]) -> String { + let mut path: Vec = Vec::new(); + let bins = [ + self.cargo_dir.clone(), + self.cargo_home.as_ref().map(|c| c.join("bin")), + ]; + for d in bins.into_iter().flatten() { + let d = d.display().to_string(); + if !path.contains(&d) { + path.push(d); + } + } + for t in tail { + if !path.iter().any(|p| p == t) { + path.push(t.to_string()); + } + } + path.join(":") + } +} + /// `cargo ` for `tree` inside bubblewrap: no network, a cleared environment, no view of the /// judge's home (where its signing key lives), the tree read-only at `/src`, only `target` /// writable (at `/target`, which must exist), and the toolchain read-only. Build scripts, proc /// macros, `include_bytes!` and the candidate's own tests run or read here, so they cannot reach /// the key. There is no fallback: if the sandbox cannot start, the command fails. pub fn sandboxed_cargo(tree: &Path, target: &Path, args: &[&str]) -> Command { - let env_dir = |var: &str, default: &str| -> Option { - std::env::var_os(var) - .map(PathBuf::from) - .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(default))) - .filter(|p| p.is_dir()) - }; - // Never expose the judge's home (or a directory holding it) inside the sandbox. - let home = std::env::var_os("HOME").map(PathBuf::from); - let safe = |d: &PathBuf| home.as_ref().is_none_or(|h| !h.starts_with(d)); - let rustup_home = env_dir("RUSTUP_HOME", ".rustup").filter(safe); - let cargo_home = env_dir("CARGO_HOME", ".cargo").filter(safe); - let path = std::env::var("PATH").unwrap_or_else(|_| "/usr/bin:/bin".into()); - let cargo_dir = path - .split(':') - .map(PathBuf::from) - .find(|d| d.join("cargo").is_file()) - .filter(safe); + let toolchain = Toolchain::from_env(); let mut cmd = Command::new("bwrap"); cmd.args([ "--unshare-user", @@ -46,25 +129,19 @@ pub fn sandboxed_cargo(tree: &Path, target: &Path, args: &[&str]) -> Command { cmd.args(["--ro-bind", sys, sys]); } } - let mut path_in = vec!["/usr/bin".to_string(), "/bin".to_string()]; - for d in [&rustup_home, &cargo_home, &cargo_dir] - .into_iter() - .flatten() - { + for d in toolchain.bind_dirs() { cmd.arg("--ro-bind").arg(d).arg(d); } - if let Some(d) = &cargo_dir { - path_in.insert(0, d.display().to_string()); - } - if let Some(d) = &rustup_home { - cmd.arg("--setenv").arg("RUSTUP_HOME").arg(d); - } - if let Some(d) = &cargo_home { - cmd.arg("--setenv").arg("CARGO_HOME").arg(d); + for (k, d) in toolchain.env() { + cmd.arg("--setenv").arg(k).arg(d); } cmd.arg("--ro-bind").arg(tree).arg("/src"); cmd.arg("--bind").arg(target).arg("/target"); - cmd.args(["--setenv", "PATH", &path_in.join(":")]); + let path_in = match &toolchain.cargo_dir { + Some(d) => format!("{}:/usr/bin:/bin", d.display()), + None => "/usr/bin:/bin".to_string(), + }; + cmd.args(["--setenv", "PATH", &path_in]); cmd.args([ "--setenv", "HOME", @@ -77,3 +154,58 @@ pub fn sandboxed_cargo(tree: &Path, target: &Path, args: &[&str]) -> Command { cmd.args(args); cmd } + +#[cfg(test)] +mod tests { + use super::*; + + /// The Spark judge sandbox keeps the toolchain beside HOME, not under it: HOME is + /// `/var/lib/aien-run`, the toolchain `/var/lib/aien-run/{cargo,rustup}`. The jails must + /// find it through CARGO_HOME / RUSTUP_HOME and PATH, not by guessing `$HOME/.cargo`. + #[test] + fn toolchain_outside_home_dotdirs_is_found_through_its_variables() { + let root = tempfile::tempdir().unwrap(); + let home = root.path().to_path_buf(); + let cargo_home = home.join("cargo"); + let rustup_home = home.join("rustup"); + std::fs::create_dir_all(cargo_home.join("bin")).unwrap(); + std::fs::create_dir_all(&rustup_home).unwrap(); + std::fs::write(cargo_home.join("bin/cargo"), b"").unwrap(); + let path = format!("{}:/usr/bin:/bin", cargo_home.join("bin").display()); + + let t = Toolchain::resolve( + Some(home.clone()), + Some(rustup_home.clone()), + Some(cargo_home.clone()), + &path, + ); + assert_eq!(t.rustup_home.as_deref(), Some(rustup_home.as_path())); + assert_eq!(t.cargo_home.as_deref(), Some(cargo_home.as_path())); + assert_eq!(t.cargo_dir, Some(cargo_home.join("bin"))); + assert!(t.bind_dirs().contains(&cargo_home.as_path())); + assert!(t.bind_dirs().contains(&rustup_home.as_path())); + assert!(t + .jail_path(&["/usr/bin", "/bin"]) + .starts_with(&cargo_home.join("bin").display().to_string())); + + // Without the variables the `$HOME/.cargo` guess finds nothing here: the old behaviour. + let guessed = Toolchain::resolve(Some(home), None, None, "/usr/bin:/bin"); + assert!(guessed.cargo_home.is_none() && guessed.rustup_home.is_none()); + } + + #[test] + fn a_directory_holding_the_judge_home_is_never_exposed() { + let root = tempfile::tempdir().unwrap(); + let home = root.path().join("judge"); + std::fs::create_dir_all(&home).unwrap(); + let t = Toolchain::resolve( + Some(home), + Some(root.path().to_path_buf()), + Some(root.path().to_path_buf()), + "/usr/bin:/bin", + ); + assert!(t.rustup_home.is_none()); + assert!(t.cargo_home.is_none()); + assert!(t.bind_dirs().is_empty()); + } +} diff --git a/src/isolation/container.rs b/src/isolation/container.rs index 263bf31..cf74b0a 100644 --- a/src/isolation/container.rs +++ b/src/isolation/container.rs @@ -1,6 +1,27 @@ use std::path::{Path, PathBuf}; use std::process::Command; +use super::cargo_sandbox::Toolchain; + +/// The jail PATH after the toolchain bin directories. +const JAIL_PATH_TAIL: &[&str] = &["/usr/local/cuda/bin", "/usr/local/bin", "/usr/bin", "/bin"]; + +/// Binds the host toolchain read-only at its own path and points `RUSTUP_HOME` / `CARGO_HOME` +/// at it, wherever it lives (see [`Toolchain`]). +fn push_toolchain(args: &mut Vec, toolchain: &Toolchain) { + for d in toolchain.bind_dirs() { + let d = d.display().to_string(); + args.push("--ro-bind".to_string()); + args.push(d.clone()); + args.push(d); + } + for (k, d) in toolchain.env() { + args.push("--setenv".to_string()); + args.push(k.to_string()); + args.push(d.display().to_string()); + } +} + #[derive(Debug, Clone)] pub struct SandboxLimits { pub max_memory_mb: u64, @@ -193,19 +214,9 @@ impl BuildJail { args.push("/etc".to_string()); args.push("/etc".to_string()); } - let home = std::env::var("HOME").unwrap_or_else(|_| "/home/drakestapleton".to_string()); - let cargo_home = Path::new(&home).join(".cargo"); - if cargo_home.exists() { - args.push("--ro-bind".to_string()); - args.push(cargo_home.display().to_string()); - args.push(cargo_home.display().to_string()); - } - let rustup_home = Path::new(&home).join(".rustup"); - if rustup_home.exists() { - args.push("--ro-bind".to_string()); - args.push(rustup_home.display().to_string()); - args.push(rustup_home.display().to_string()); - } + let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()); + let toolchain = Toolchain::from_env(); + push_toolchain(&mut args, &toolchain); let target_dir = Path::new("/tmp/spark-rsi-target"); if !target_dir.exists() { @@ -220,10 +231,7 @@ impl BuildJail { args.push("--setenv".to_string()); args.push("PATH".to_string()); - args.push(format!( - "{}/.cargo/bin:/usr/local/cuda/bin:/usr/local/bin:/usr/bin:/bin", - home - )); + args.push(toolchain.jail_path(JAIL_PATH_TAIL)); args.push("--setenv".to_string()); args.push("HOME".to_string()); args.push(home.clone()); @@ -383,19 +391,9 @@ impl CandidateJailRunner { args.push("/etc".to_string()); args.push("/etc".to_string()); } - let home = std::env::var("HOME").unwrap_or_else(|_| "/home/drakestapleton".to_string()); - let cargo_home = Path::new(&home).join(".cargo"); - if cargo_home.exists() { - args.push("--ro-bind".to_string()); - args.push(cargo_home.display().to_string()); - args.push(cargo_home.display().to_string()); - } - let rustup_home = Path::new(&home).join(".rustup"); - if rustup_home.exists() { - args.push("--ro-bind".to_string()); - args.push(rustup_home.display().to_string()); - args.push(rustup_home.display().to_string()); - } + let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()); + let toolchain = Toolchain::from_env(); + push_toolchain(&mut args, &toolchain); let bin_dir = self .candidate_bin @@ -425,10 +423,7 @@ impl CandidateJailRunner { args.push("--setenv".to_string()); args.push("PATH".to_string()); - args.push(format!( - "{}/.cargo/bin:/usr/local/cuda/bin:/usr/local/bin:/usr/bin:/bin", - home - )); + args.push(toolchain.jail_path(JAIL_PATH_TAIL)); args.push("--setenv".to_string()); args.push("HOME".to_string()); args.push(home.clone()); @@ -488,6 +483,24 @@ mod tests { assert!(args.contains(&"--die-with-parent".to_string())); assert!(args.contains(&"/output".to_string())); assert!(args.contains(&"cargo".to_string())); + // The toolchain the host resolves is bound read-only at its own path and named by its + // variables, wherever it lives. + let toolchain = Toolchain::from_env(); + for d in toolchain.bind_dirs() { + let d = d.display().to_string(); + assert!( + args.windows(3) + .any(|w| w[0] == "--ro-bind" && w[1] == d && w[2] == d), + "toolchain dir {} not bound", + d + ); + } + for (k, d) in toolchain.env() { + let d = d.display().to_string(); + assert!(args + .windows(3) + .any(|w| w[0] == "--setenv" && w[1] == k && w[2] == d)); + } } #[test] diff --git a/src/isolation/mod.rs b/src/isolation/mod.rs index 8ae8e1e..06064f9 100644 --- a/src/isolation/mod.rs +++ b/src/isolation/mod.rs @@ -4,7 +4,7 @@ pub mod manifest; pub mod rollback; pub mod root_of_trust; -pub use cargo_sandbox::sandboxed_cargo; +pub use cargo_sandbox::{sandboxed_cargo, Toolchain}; pub use container::{BuildJail, CandidateJailRunner, GpuEvaluationJail, SandboxLimits}; pub use manifest::{ArtifactManifest, ArtifactRecord, CandidateManifest}; pub use rollback::RollbackCheckpoint; ```