fix(cli): normalize strict failures to one JSON document
ci/woodpecker/push/woodpecker Pipeline was successful
CI / fmt + clippy + test (Linux x86_64) (push) Canceled after 0s
CI / schema instance validation + consumers (push) Canceled after 0s
CI / runtime contract (macos-latest) (push) Canceled after 0s
CI / runtime contract (windows-latest) (push) Canceled after 0s
CI / release candidate artifact (macos-latest) (push) Canceled after 0s
CI / release candidate artifact (ubuntu-latest) (push) Canceled after 0s

Capture the strict child through launch_strict_capture and classify the
outcome before writing anything. In --json mode a control-plane failure now
emits exactly one error document with a stable code instead of forwarding
bubblewrap stderr and leaving stdout empty; a verified child's valid JSON is
forwarded unchanged with its own exit code. Empty, partial or non-JSON child
output becomes strict.child_invalid.

Route the remaining run --json error paths (mode, grants, missing entry,
trace) through the same contract, classify sandbox launch failures with
StrictFailureKind so probe/spawn/timeout/resource failures stay
distinguishable, and add deterministic routing tests plus forged-marker CLI
coverage. Document the decision in ADR-0053 and spec/security.md 1.2.

This is step 2 of the CI/security RFC (B02/B03).
This commit is contained in:
cflmy committed 2026-11-21 16:46:27 +08:00
1 parent f4a404bae9
commit f817cceb3b
9 files changed
+634 -103

No files matched your search

+26
View File
@@ -57,6 +57,32 @@ produces no IR and therefore cannot cause a host effect at all. No heading
annotation, keyword or Markdown container can grant a file/network/process
capability, and permission flags never change the AST→IR result.
### 1.2 Strict failure and `--json` contract
Strict execution is a two-phase operation: detect, then launch. Availability
observed by `inspect --platform` is a snapshot, not a permanent promise. The
runtime therefore re-probes before launching; a failure after a successful
probe is a refusal, never a fallback.
`--json` consumers must receive **exactly one** JSON document on stdout for
every outcome:
* a verified child in `--json` mode produces that document itself and its
bytes and exit code are forwarded unchanged;
* a control-plane failure (probe, supervisor spawn, namespace construction,
timeout, capture) produces one CLI error document
`{"command": ..., "success": false, "error": ..., "code": ...}`;
* output that is empty or is not exactly one JSON document is rejected as
`strict.child_invalid`; raw supervisor text is never forwarded as program
stdout.
The stable codes are `strict.probe_unavailable`, `strict.spawn_failed`,
`strict.namespace_failure`, `strict.timeout`, `strict.resource_limit`,
`strict.child_invalid`, `strict.identity_invalid` and
`strict.unsupported_grant` (ADR-0053). A marker alone never authorizes strict
execution: Linux verifies the namespace/privilege identity, and every other
platform rejects `MARQDO_STRICT_ACTIVE` outright (ADR-0053).
## 2. Capability grants
`Capabilities` (`crates/marqdo-host/src/capability.rs`) is the effective grant