feat(sandbox): implement probe-gated Linux strict isolation (ADR-0021)
Strict mode now re-executes the CLI inside a Bubblewrap supervisor with user/mount/PID/net/UTS/IPC namespaces, no-new-privs, all capabilities dropped, a read-only /project, private /proc and /dev, rlimits, output capture and wall-clock process-group cleanup. The child verifies PID 1, NoNewPrivs, empty CapEff, an unshared uid map and loopback-only networking before project code. - PlatformCapabilities::detect runs a real bwrap probe; no probe, no strict - strict L1 supports pure Marqdo + Math; Foreign/ABI/worker/kernel/grants/trace are rejected with exit 2 before sandboxing - forged MARQDO_STRICT_ACTIVE is rejected; missing bwrap fails closed - add adversarial helper, 7-test escape/resource matrix, seeded security lane script and self-hosted security workflow - executed G-C lane as uid 1000 in a disposable Ubuntu 26.04 VM: 7/7 PASS plus positive CLI and refusal matrix; evidence in docs/evidence - ADR-0021, spec/security.md, STATUS/COMPATIBILITY/README/CHANGELOG updated; ADR-0019 remains for non-Linux/fail-closed rules
This commit is contained in:
1 parent
9b001a33a5
commit
b6fc18233d
22 files changed
+1886
-132
No files matched your search
+102
-1
@@ -59,6 +59,31 @@ impl SandboxSettings {
|
||||
})
|
||||
}
|
||||
|
||||
/// Reject strict-mode requests that this L1 isolation level does not
|
||||
/// support. Strict currently covers pure Marqdo and native Math only;
|
||||
/// granting Foreign, ABI plugins, tools or trace files would require
|
||||
/// extending the supervisor contract first.
|
||||
pub fn strict_preflight(&self) -> Result<(), String> {
|
||||
let requested = self.allow_foreign
|
||||
|| !self.allow_read.is_empty()
|
||||
|| !self.allow_write.is_empty()
|
||||
|| !self.allow_plugin.is_empty()
|
||||
|| !self.plugins.is_empty()
|
||||
|| self.trust_native_plugin
|
||||
|| !self.kernels.is_empty()
|
||||
|| self.trace_file.is_some();
|
||||
if requested {
|
||||
return Err(
|
||||
"strict mode currently supports pure Marqdo and native Math only; \
|
||||
--allow-read/--allow-write/--allow-foreign/--allow-plugin/--plugin/\
|
||||
--trust-native-plugin/--kernel/--trace-file are rejected. Use \
|
||||
--mode project for those capabilities."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Build the effective capability set.
|
||||
pub fn capabilities(&self) -> Result<Capabilities, String> {
|
||||
let mode = self.sandbox_mode()?;
|
||||
@@ -91,7 +116,10 @@ impl SandboxSettings {
|
||||
}
|
||||
Ok(capabilities)
|
||||
}
|
||||
SandboxMode::Strict => Ok(Capabilities::project()),
|
||||
SandboxMode::Strict => {
|
||||
self.strict_preflight()?;
|
||||
Ok(Capabilities::project())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -625,6 +653,43 @@ fn resolve_link(
|
||||
}
|
||||
}
|
||||
|
||||
/// Re-execute this CLI inside the strict Linux supervisor.
|
||||
fn launch_strict_process(
|
||||
project_root: &Path,
|
||||
document: Option<&Path>,
|
||||
settings: &SandboxSettings,
|
||||
) -> i32 {
|
||||
let program = match std::env::current_exe() {
|
||||
Ok(path) => path,
|
||||
Err(error) => {
|
||||
eprintln!("error: cannot locate the marqdo executable: {error}");
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
let args: Vec<std::ffi::OsString> = std::env::args_os().skip(1).collect();
|
||||
let output_limit = settings
|
||||
.max_output
|
||||
.unwrap_or(1024 * 1024)
|
||||
.min(64 * 1024 * 1024);
|
||||
let timeout = Duration::from_secs(settings.timeout.unwrap_or(30));
|
||||
let command = marqdo_sandbox::StrictHostCommand {
|
||||
program: &program,
|
||||
args: &args,
|
||||
project_root,
|
||||
document,
|
||||
original_document: document,
|
||||
output_limit,
|
||||
timeout,
|
||||
};
|
||||
match marqdo_sandbox::launch_strict(&command) {
|
||||
Ok(code) => code,
|
||||
Err(error) => {
|
||||
eprintln!("error: {error}");
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `marqdo run` / `marqdo call`.
|
||||
pub fn execute(
|
||||
file: Option<&Path>,
|
||||
@@ -676,6 +741,42 @@ pub fn execute(
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
if mode == SandboxMode::Strict {
|
||||
if let Err(error) = settings.strict_preflight() {
|
||||
if json {
|
||||
output::print_json(&json!({"success": false, "error": error}));
|
||||
} else {
|
||||
eprintln!("error: {error}");
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
if marqdo_sandbox::marker_present() {
|
||||
// We were re-executed by the supervisor: validate the marker set
|
||||
// before running any project code.
|
||||
if let Err(reason) = marqdo_sandbox::verify_active() {
|
||||
if json {
|
||||
output::print_json(&json!({
|
||||
"success": false,
|
||||
"error": format!("strict isolation verification failed: {reason}"),
|
||||
}));
|
||||
} else {
|
||||
eprintln!("error: strict isolation verification failed: {reason}");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
let platform = PlatformCapabilities::detect();
|
||||
if let Err(error) = marqdo_sandbox::enforce(mode, &platform) {
|
||||
if json {
|
||||
output::print_json(&json!({"success": false, "error": error.to_string()}));
|
||||
} else {
|
||||
eprintln!("error: {error}");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return launch_strict_process(&project.root, file, settings);
|
||||
}
|
||||
}
|
||||
let platform = PlatformCapabilities::detect();
|
||||
if let Err(error) = marqdo_sandbox::enforce(mode, &platform) {
|
||||
if json {
|
||||
|
||||
Reference in new issue
Block a user