aboutsummaryrefslogtreecommitdiffstats
path: root/tests/common/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 01:59:16 +0000
committertv <tv@krebsco.de>2026-12-01 01:59:16 +0000
commit2af90fd35ea8a0aafb9156653f5b28cbac4e1677 (patch)
treec2eceb7e2dae9625bb4e5a994e13151e11fd44d4 /tests/common/mod.rs
parent5804d2b952ebead3d9bc238fc8db20af6563fddc (diff)
enstate: validators and renderers in a sandboxHEADmaster
By bubblewrap: everything read-only but OUT (and IN bound again after a fresh /tmp), a new /dev and /proc, namespaces of their own (no network), no capabilities, a new session, gone with the receptor. The setting sandbox is bwrap (found in the receptor's PATH, as the programs' environment is empty), or none; the module sets its bubblewrap. The tests run their programs in it where bubblewrap can make one (not in Nix's build sandbox), and a test checks that a program can't write outside OUT, nor into IN, and has no network nor environment.
Diffstat (limited to 'tests/common/mod.rs')
-rw-r--r--tests/common/mod.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 3af1c88..6c04191 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -28,7 +28,7 @@ impl Host {
}
pub fn store(&self) -> Store {
- Store::new(&self.root.join("state"), &self.root.join("run"))
+ Store::new(&self.root.join("state"), &self.root.join("run")).with_sandbox(bwrap())
}
/// A shell script, with the tests' PATH (programs get an empty environment).
@@ -146,3 +146,26 @@ impl Host {
.map(|snapshot| snapshot.id)
}
}
+
+/// bubblewrap, if it can make a sandbox here (not in Nix's build sandbox, say): the
+/// tests' programs run in it then.
+pub fn bwrap() -> Option<PathBuf> {
+ static BWRAP: std::sync::OnceLock<Option<PathBuf>> = std::sync::OnceLock::new();
+ BWRAP
+ .get_or_init(|| {
+ let works = std::process::Command::new("bwrap")
+ .args([
+ "--ro-bind",
+ "/",
+ "/",
+ "--unshare-all",
+ "--die-with-parent",
+ "true",
+ ])
+ .stderr(std::process::Stdio::null())
+ .status()
+ .is_ok_and(|status| status.success());
+ works.then(|| PathBuf::from("bwrap"))
+ })
+ .clone()
+}