From 2af90fd35ea8a0aafb9156653f5b28cbac4e1677 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 1 Dec 2026 01:59:16 +0000 Subject: enstate: validators and renderers in a sandbox 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. --- src/main.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9133cb3..2df4c78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,13 @@ const OPTIONS: &[OptionSpec] = &[ Some("/etc/enstate/schema.json"), "The schema of the running generation; for --pack, one to check the source list against", ), + option( + "sandbox", + Kind::Text, + "PATH", + Some("bwrap"), + "bubblewrap, to run validators and renderers in a sandbox; none runs them without one", + ), option( "unit", Kind::Text, @@ -76,6 +83,7 @@ struct Settings { schema: Option, systemctl: Option, unit: Option, + sandbox: Option, } const COMMANDS: &[(&str, &str)] = &[ @@ -253,7 +261,12 @@ fn run() -> Result { .run_dir .as_deref() .unwrap_or(Path::new("/run/enstate")), - ); + ) + .with_sandbox(match settings.sandbox.as_deref() { + Some("none") => None, + Some(bwrap) => Some(PathBuf::from(bwrap)), + None => Some(PathBuf::from("bwrap")), + }); let schema_path = settings .schema .unwrap_or_else(|| PathBuf::from("/etc/enstate/schema.json")); @@ -641,6 +654,11 @@ fn uses(command: &str, setting: &str) -> bool { // Reactions run. "systemctl" => matches!(command, "apply" | "migrate"), "unit" => command == "apply", + // Programs run. + "sandbox" => matches!( + command, + "plan" | "apply" | "stage" | "materialize" | "migrate" + ), _ => true, } } -- cgit v1.3.1