fix(strict): bind the bundled stdlib and verify strict resources
- Strict child now gets the verified stdlib tree read-only at /run/marqdo-stdlib with MARQDO_STDLIB_DIR set, so Compat-C 打印 works under strict without exposing a host path (ADR-0021 update). - Add a strict-lane negative: resource.open(file) is refused with permission.denied; hello/factorial/multi-module and --json still pass. - StrictHostCommand gains stdlib_dir; CLI discovers the bundle and sandbox binds it; sandbox tests constructors updated. Evidence: G-C lane PASS on the disposable Ubuntu 26.04 VM (7/7 adversarial matrix, positive CLI, strict language-resource refusal, forged marker), plus fmt/clippy/423 local tests.
This commit is contained in:
1 parent
1be4662049
commit
1d87f98539
9 files changed
+65
-4
No files matched your search
@@ -682,6 +682,10 @@ fn launch_strict_process(
|
||||
.unwrap_or(1024 * 1024)
|
||||
.min(64 * 1024 * 1024);
|
||||
let timeout = Duration::from_secs(settings.timeout.unwrap_or(30));
|
||||
let stdlib_dir = crate::stdlib::StdlibBundle::discover()
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|bundle| bundle.root().to_path_buf());
|
||||
let command = marqdo_sandbox::StrictHostCommand {
|
||||
program: &program,
|
||||
args: &args,
|
||||
@@ -690,6 +694,7 @@ fn launch_strict_process(
|
||||
original_document: document,
|
||||
output_limit,
|
||||
timeout,
|
||||
stdlib_dir: stdlib_dir.as_deref(),
|
||||
};
|
||||
match marqdo_sandbox::launch_strict(&command) {
|
||||
Ok(code) => code,
|
||||
|
||||
@@ -89,6 +89,11 @@ impl StdlibBundle {
|
||||
})
|
||||
}
|
||||
|
||||
/// Bundle root.
|
||||
pub fn root(&self) -> &Path {
|
||||
&self.root
|
||||
}
|
||||
|
||||
/// Declared stdlib version.
|
||||
pub fn version(&self) -> &str {
|
||||
&self.version
|
||||
|
||||
@@ -232,6 +232,8 @@ pub struct StrictHostCommand<'a> {
|
||||
pub output_limit: usize,
|
||||
/// Wall-clock budget for the supervised process tree.
|
||||
pub timeout: Duration,
|
||||
/// Verified bundled stdlib directory to bind read-only when present.
|
||||
pub stdlib_dir: Option<&'a Path>,
|
||||
}
|
||||
|
||||
/// Launch a command inside the strict sandbox (Linux only).
|
||||
|
||||
@@ -317,6 +317,16 @@ fn run_with(
|
||||
})?;
|
||||
|
||||
let mut args = common_args();
|
||||
if let Some(stdlib) = command.stdlib_dir {
|
||||
args.extend([
|
||||
OsString::from("--ro-bind"),
|
||||
stdlib.as_os_str().to_os_string(),
|
||||
OsString::from("/run/marqdo-stdlib"),
|
||||
OsString::from("--setenv"),
|
||||
OsString::from("MARQDO_STDLIB_DIR"),
|
||||
OsString::from("/run/marqdo-stdlib"),
|
||||
]);
|
||||
}
|
||||
args.extend([
|
||||
OsString::from("--ro-bind"),
|
||||
project_root.as_os_str().to_os_string(),
|
||||
@@ -548,6 +558,7 @@ mod tests {
|
||||
original_document: None,
|
||||
output_limit: 4096,
|
||||
timeout: Duration::from_secs(1),
|
||||
stdlib_dir: None,
|
||||
};
|
||||
let error = run_with(
|
||||
&command,
|
||||
@@ -585,6 +596,7 @@ mod tests {
|
||||
original_document: None,
|
||||
output_limit: 4096,
|
||||
timeout: Duration::from_secs(1),
|
||||
stdlib_dir: None,
|
||||
};
|
||||
let error = run_with(
|
||||
&command,
|
||||
|
||||
@@ -111,6 +111,7 @@ fn run(helper: &Path, project: &Path, outside: &Path, mode: &str) -> StrictOutco
|
||||
original_document: None,
|
||||
output_limit: 64 * 1024,
|
||||
timeout: Duration::from_secs(3),
|
||||
stdlib_dir: None,
|
||||
};
|
||||
launch_strict_capture(&command).unwrap_or_else(|error| panic!("{mode}: {error}"))
|
||||
}
|
||||
@@ -267,6 +268,7 @@ fn strict_supervisor_enforces_memory_cpu_and_output_limits() {
|
||||
original_document: None,
|
||||
output_limit: 64 * 1024,
|
||||
timeout: Duration::from_secs(2),
|
||||
stdlib_dir: None,
|
||||
};
|
||||
let cpu = launch_strict_capture(&command).expect_err("CPU loop must be stopped");
|
||||
let message = cpu.to_string();
|
||||
@@ -283,6 +285,7 @@ fn strict_supervisor_enforces_memory_cpu_and_output_limits() {
|
||||
original_document: None,
|
||||
output_limit: 64 * 1024,
|
||||
timeout: Duration::from_secs(3),
|
||||
stdlib_dir: None,
|
||||
})
|
||||
.expect("output helper should be captured, not spawn-failed");
|
||||
assert!(
|
||||
|
||||
@@ -54,14 +54,23 @@ The trusted supervisor is this process; the restricted child is the same
|
||||
The document argument is rewritten to `/project/...`; only the document token
|
||||
changes, all other arguments are preserved.
|
||||
|
||||
### 4. Child self-verification
|
||||
### 4. Bundled stdlib mount
|
||||
|
||||
After CM-A07 Compat-C, `打印` is implemented by the bundled `.mq.md` stdlib.
|
||||
Strict therefore bind-mounts the verified `stdlib/` tree read-only at
|
||||
`/run/marqdo-stdlib` and sets `MARQDO_STDLIB_DIR` for the child, just like the
|
||||
program itself. The tree contains only Markdown/read-only data; it grants no
|
||||
new OS capability, and the loader still verifies its digest in the child. File,
|
||||
network, process and provider resources remain refused.
|
||||
|
||||
### 5. Child self-verification
|
||||
|
||||
The child accepts `MARQDO_STRICT_ACTIVE=1` only if it can verify all of:
|
||||
`getpid() == 1`, `NoNewPrivs: 1`, empty `CapEff`, a non-initial uid map, and no
|
||||
non-loopback network interface. A forged marker outside the sandbox fails
|
||||
before project code runs.
|
||||
|
||||
### 5. Threat model and non-goals
|
||||
### 6. Threat model and non-goals
|
||||
|
||||
This protects against untrusted Marqdo documents that use the language,
|
||||
interpreter, Math, console, or attempt direct syscalls. It does not sandbox
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ export PATH="$HOME/.cargo/bin:$PATH"
|
||||
./tests/security/run-lane.sh
|
||||
```
|
||||
|
||||
Expected final line: `G-C security lane: PASS`. The script exports
|
||||
Expected final line: `G-C security lane: PASS`. The lane also checks that the read-only bundled stdlib works for `打印` and that a project-file `resource.open` is refused in strict mode. The script exports
|
||||
`MARQDO_REQUIRE_STRICT_SECURITY=1`; a missing bubblewrap, compiler or helper is
|
||||
a failure, never a skip.
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ Normative implementation:
|
||||
|---|---|---|
|
||||
| `pure` | No external I/O; memory computation and budgets only. | **Enforced.** `Capabilities::pure()` = `console`, `math` only; every FS/foreign/plugin grant flag makes the CLI exit 2 with "pure mode prohibits external I/O grants". |
|
||||
| `project` | Operator-approved project resources under `CapabilityHost` + bounded resources. | **Enforced for the implemented operations.** Defaults equal `pure`; `--allow-read`, `--allow-write`, `--allow-foreign`, `--allow-plugin` add grants. `resource.open` supports stdout write, granted project-file read/write (ADR-0025/0026) and granted in-process provider kinds (ADR-0033); network/process remain unsupported. Sandboxing is cooperative (in-process checks), not OS isolation; in-process providers are trusted, not sandboxed. |
|
||||
| `strict` | Untrusted documents under real OS isolation. | **Linux: enforced when the runtime probe passes (ADR-0021).** `resource.open` is **refused** in strict except for the existing `stdio/stdout` console channel (console grant); file/network/process resources remain refused until a provider passes the isolation lane (CM-A11, ADR-0030). `PlatformCapabilities::detect()` runs a real Bubblewrap smoke test; success reports `Available { mechanism }`, failure reports `Unavailable { reason }`. Strict L1 supports the interpreter, console and native Math only; `--allow-read/--allow-write/--allow-foreign/--allow-plugin/--plugin/--trust-native-plugin/--kernel/--trace-file` are rejected with exit 2. macOS/Windows and Linux hosts without the mechanisms remain `Unavailable`; there is **no fallback** to an unrestricted process. |
|
||||
| `strict` | Untrusted documents under real OS isolation. | **Linux: enforced when the runtime probe passes (ADR-0021).** `resource.open` is **refused** in strict except for the existing `stdio/stdout` console channel (console grant); file/network/process resources remain refused until a provider passes the isolation lane (CM-A11, ADR-0030). `PlatformCapabilities::detect()` runs a real Bubblewrap smoke test; success reports `Available { mechanism }`, failure reports `Unavailable { reason }`. Strict L1 supports the interpreter, console, native Math and the read-only bundled stdlib (published at `/run/marqdo-stdlib` for the Compat-C print chain); `--allow-read/--allow-write/--allow-foreign/--allow-plugin/--plugin/--trust-native-plugin/--kernel/--trace-file` are rejected with exit 2. macOS/Windows and Linux hosts without the mechanisms remain `Unavailable`; there is **no fallback** to an unrestricted process. |
|
||||
|
||||
`marqdo inspect <file> --platform` prints the detection report, for example:
|
||||
|
||||
|
||||
@@ -53,6 +53,31 @@ echo "== positive CLI contract =="
|
||||
"$bin" run examples/hello.mq.md --mode strict --json | python3 -c \
|
||||
'import json,sys; d=json.load(sys.stdin); assert d["success"] is True'
|
||||
|
||||
echo "== strict language resources are console-only =="
|
||||
mkdir -p .cache/security
|
||||
cat > .cache/security/file-resource.mq.md <<'MQ'
|
||||
## main
|
||||
|
||||
**内存 = memory.new(1, 1)**
|
||||
|
||||
> resource.open("file", "README.md", ["read"])
|
||||
|
||||
*None*
|
||||
MQ
|
||||
set +e
|
||||
"$bin" run .cache/security/file-resource.mq.md --mode strict >/dev/null 2>.cache/security/file-resource.err
|
||||
code=$?
|
||||
set -e
|
||||
if [ "$code" -eq 0 ]; then
|
||||
echo "error: strict accepted a project file resource" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q "permission.denied" .cache/security/file-resource.err || {
|
||||
echo "error: strict file-resource refusal had no permission.denied diagnostic" >&2
|
||||
cat .cache/security/file-resource.err >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "== external-execution surfaces are refused =="
|
||||
reject() {
|
||||
set +e
|
||||
|
||||
Reference in new issue
Block a user