test(cli): prove check never spawns a Foreign kernel
A document with an executable foreign.call is statically checked without a marker side effect, then run to show the same provider does execute. This guards the 'check/inspect cannot execute untrusted code' contract.
This commit is contained in:
1 parent
18d9f39562
commit
2cf9ecedd5
4 files changed
+72
-2
No files matched your search
@@ -21,6 +21,8 @@ currently `0.1.0`; no release tag has been cut. Dates use ISO 8601.
|
||||
`PATH`, and `interpreter_version` is verified before execution.
|
||||
- Release documentation (`COMPATIBILITY.md`, `docs/releasing.md`) and the
|
||||
Linux security-gate evidence report (`docs/security-gate.md`).
|
||||
- `check_never_spawns_a_foreign_kernel`: proves static `check` does not spawn a
|
||||
declared Foreign provider, while `run` on the same document does.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -885,3 +885,66 @@ fn plugin_abi_major_mismatch_is_rejected_before_execution() {
|
||||
"plugin export must not run after an ABI mismatch"
|
||||
);
|
||||
}
|
||||
|
||||
/// `check` is static: a document that would run a Foreign kernel must not spawn
|
||||
/// it or perform its side effect. The same document is then executed to prove
|
||||
/// the marker would appear if check were executing code.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn check_never_spawns_a_foreign_kernel() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let dir = TempDir::new("check-no-exec");
|
||||
let marker = dir.path().join("spawned.marker");
|
||||
let provider = dir.path().join("mocklang");
|
||||
fs::write(
|
||||
&provider,
|
||||
format!(
|
||||
"#!/bin/sh\n: > '{}'\ncat >/dev/null\nprintf '%s' '{{\"type\":\"int\",\"decimal\":\"1\"}}'\n",
|
||||
marker.display()
|
||||
),
|
||||
)
|
||||
.expect("write mock provider");
|
||||
let mut permissions = fs::metadata(&provider)
|
||||
.expect("provider metadata")
|
||||
.permissions();
|
||||
permissions.set_mode(0o700);
|
||||
fs::set_permissions(&provider, permissions).expect("chmod provider");
|
||||
let digest = hex::encode(sha2::Sha256::digest(
|
||||
fs::read(&provider).expect("read provider"),
|
||||
));
|
||||
dir.write(
|
||||
"kernel.json",
|
||||
&format!(
|
||||
"{{\"provider_id\":\"mocklang\",\"languages\":[\"mocklang\"],\"wire_version\":1,\"entrypoint\":\"{}\",\"digest\":\"{digest}\"}}",
|
||||
provider.display()
|
||||
),
|
||||
);
|
||||
dir.write(
|
||||
"doc.mq.md",
|
||||
"## 代码\n\n```mocklang\nignored\n```\n\n## main\n\n**值 = foreign.call(ref(\"#代码\"), {})**\n\n> 打印(值)\n",
|
||||
);
|
||||
|
||||
let checked = cli(dir.path(), &["check", "doc.mq.md"]);
|
||||
assert_exit(&checked, 0, "check must accept the static document");
|
||||
assert!(
|
||||
!marker.exists(),
|
||||
"check spawned the Foreign kernel and produced a side effect"
|
||||
);
|
||||
|
||||
let ran = cli(
|
||||
dir.path(),
|
||||
&[
|
||||
"run",
|
||||
"doc.mq.md",
|
||||
"--kernel",
|
||||
"kernel.json",
|
||||
"--allow-foreign",
|
||||
],
|
||||
);
|
||||
assert_exit(&ran, 0, "run must execute the Foreign kernel");
|
||||
assert!(
|
||||
marker.exists(),
|
||||
"run did not execute the provider; the no-execution assertion is vacuous"
|
||||
);
|
||||
}
|
||||
+2
-2
@@ -38,7 +38,7 @@ cargo fmt --all -- --check PASS
|
||||
cargo clippy --workspace --all-targets -- -D warnings PASS
|
||||
cargo test --workspace PASS
|
||||
cargo test -p marqdo-cli --test conformance_ast PASS (4 tests)
|
||||
cargo test -p marqdo-cli --test integration_cli PASS (22 tests)
|
||||
cargo test -p marqdo-cli --test integration_cli PASS (23 tests)
|
||||
cargo test -p marqdo-cli --test plugin_worker PASS (4 tests)
|
||||
cargo test -p marqdo-foreign --test provider PASS (8 tests)
|
||||
```
|
||||
@@ -62,7 +62,7 @@ runs.
|
||||
| 1 | macOS native plugin fixtures | **Fixed locally, macOS CI UNVERIFIED** | host-target manifest + dylib flags, foreign-target/tamper/ABI tests PASS |
|
||||
| 2 | Status/docs reconcile | **Done** | this file, `COMPATIBILITY.md`, `CHANGELOG.md`, `docs/releasing.md`, `docs/security-gate.md` |
|
||||
| 3 | Package lock v3 reproducibility | **Implemented; targeted audit pending** | ADR-0016, `cargo test -p marqdo-cli --test package_env` PASS |
|
||||
| 4 | Analysis/Trace/Tool protocol | **Implemented; consumers PASS locally** | schemas + `tests/consumers/*.py`, `analysis_trace`/`tool_protocol` PASS |
|
||||
| 4 | Analysis/Trace/Tool protocol | **Implemented; consumers PASS locally** | schemas + `tests/consumers/*.py`, `analysis_trace`/`tool_protocol` PASS; `check_never_spawns_a_foreign_kernel` PASS |
|
||||
| 5 | Foreign pinned environment | **Done (ADR-0020)** | provider tests PASS; env binds interpreter; version drift rejected |
|
||||
| 6 | ABI session/broker hardening | **Partial** | `fs.read` bridge + budgets + handle tests PASS; Windows ABI unsupported; broader services still `capability.unavailable` |
|
||||
| 7 | Linux strict probe | **Done as fail-closed evidence** | `docs/security-gate.md`; userns/bwrap EPERM, cgroup ro, sudo blocked |
|
||||
|
||||
@@ -28,6 +28,11 @@ bwrap --unshare-user --unshare-net --ro-bind / / true
|
||||
sudo -n true
|
||||
-> sudo: The "no new privileges" flag is set, which prevents sudo from
|
||||
running as root (exit 1)
|
||||
capsh --print
|
||||
-> Current: = (no effective capabilities)
|
||||
-> Bounding set = cap_sys_admin, ... (not effective; no-new-privs=1)
|
||||
unshare --mount true / --pid --fork true / --net true
|
||||
-> Operation not permitted (exit 1 each)
|
||||
```
|
||||
|
||||
The workspace root is writable, but the host root filesystem and cgroup2 mount
|
||||
|
||||
Reference in new issue
Block a user