diff options
| author | tv <tv@krebsco.de> | 2026-12-01 01:59:16 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 01:59:16 +0000 |
| commit | 2af90fd35ea8a0aafb9156653f5b28cbac4e1677 (patch) | |
| tree | c2eceb7e2dae9625bb4e5a994e13151e11fd44d4 /tests/receptor.rs | |
| parent | 5804d2b952ebead3d9bc238fc8db20af6563fddc (diff) | |
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/receptor.rs')
| -rw-r--r-- | tests/receptor.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/receptor.rs b/tests/receptor.rs index f8417a3..fb99497 100644 --- a/tests/receptor.rs +++ b/tests/receptor.rs @@ -499,6 +499,10 @@ remove = true fn command_line() { let host = Host::new("cli"); let _ = host.schema(secrets_schema(&host)); + let sandbox = match common::bwrap() { + Some(bwrap) => format!("--sandbox={}", bwrap.display()), + None => "--sandbox=none".to_owned(), + }; let enstate = |arguments: &[&str]| { let output = Command::new(env!("CARGO_BIN_EXE_enstate")) .args(arguments) @@ -513,6 +517,12 @@ fn command_line() { .contains(&"--apply") .then(|| format!("--systemctl={}", host.systemctl().display())), ) + .args( + ["--plan", "--apply", "--stage", "--materialize", "--migrate"] + .iter() + .any(|command| arguments.contains(command)) + .then(|| sandbox.clone()), + ) .output() .unwrap(); ( @@ -588,6 +598,7 @@ fn command_line() { "--state-dir=state", "--run-dir=run", "--schema=schema.json", + &sandbox, ]) .output() .unwrap(); @@ -595,3 +606,41 @@ fn command_line() { assert_eq!(output.status.code(), Some(0), "{stdout}"); assert!(stdout.contains("nothing changes"), "{stdout}"); } + +/// In the sandbox, a program can write only to OUT, has no network but loopback, and +/// an empty environment. +#[test] +fn programs_in_a_sandbox() { + if common::bwrap().is_none() { + eprintln!("bubblewrap can't make a sandbox here: skipped"); + return; + } + let host = Host::new("sandbox"); + let escaped = host.root.join("escaped"); + // An objection for each thing it could do that it shouldn't. + let nosy = host.program( + "nosy", + &format!( + r#"object() {{ printf '{{"address": "secrets/a", "message": "%s"}}\n' "$1"; }} +if touch {escaped} 2>/dev/null; then object "wrote outside OUT"; fi +if touch "$1/x" 2>/dev/null; then object "wrote into IN"; fi +touch "$2/x" || object "couldn't write into OUT" +if [ "$(awk 'NR > 2 {{ print $1 }}' /proc/net/dev)" != "lo:" ]; then object "has a network"; fi +if env | grep -v '^PWD=\|^SHLVL=\|^_=\|^OLDPWD=' | grep -q .; then object "has an environment"; fi"#, + escaped = escaped.display() + ), + ); + let schema = host.schema(json!({ + "schema": 1, + "channels": { "secrets": { "slots": { "a": { "type": "application/octet-stream" } } } }, + "validators": { "nosy": { "slots": ["secrets/a"], "program": nosy } } + })); + let submission = host.submission( + "a", + json!({ "channel": "secrets", "items": [{ "address": "secrets/a", "op": "set" }] }), + &[("secrets/a", b"A")], + ); + let plan = host.plan(&schema.0, &submission); + assert!(plan.accepted, "{plan:?}"); + assert!(!escaped.exists()); +} |
