Repository navigation
fix(minimald): resume and restart re-run the root-constraint admission check - #3511
Conversation
…n check A start from a box's stored spec (BOX-025, BOX-176) checked the spec's version, its network policy and its egress rules, but not the BOX-160 check a create of the same spec meets: the constraints of its type's built-in root and of the type the record is filed under. A stored spec that create refuses, such as a `task` spec with a terminal or a type with no built-in root, resumed and left the box running. checked_stored_spec now passes the stored bytes through root_constraint_refusal, the function the create path uses, with the record's type in place of the creating verb's. The refusal keeps the create's exit status 3, is worded for a start rather than a create, and comes before the record is written, so the record stays as it was. The test drives the refusals through an attach, checks the record bytes are unchanged, and resumes the box once the spec the create accepted is stored again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 3 billable files and costs up to $0.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 57 minutes for your next included review. View limit details
|
|
Approved: no findings at Nothing to do. Clobber: none seen. |
norrietaylor
left a comment
There was a problem hiding this comment.
Approving. The stored bytes go through the same root_constraint_refusal a create runs, with the record's type in the verb's place, and the check runs before held_spec or the record is touched, so a refusal leaves no state behind on either resume or restart. The kind() extraction keeps the create message byte-identical. Three low/nit notes inline.
| /// terminal check passes it on. The control: the spec the create accepted | ||
| /// resumes once it is stored again. | ||
| #[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
| async fn resume_refuses_stored_spec_its_root_excludes_keeps_state() { |
There was a problem hiding this comment.
[low] The title and body say restart re-runs the check too, but only the resume path is tested. Restart goes through the same checked_stored_spec, so it works today, but nothing pins it: a later change that moves the root check out of checked_stored_spec into the resume branch would pass CI. One refused restart of an until_stopped box whose stored spec its root excludes (exit 3, RestartRefusalKind::Spec, record bytes unchanged) next to restart_refuses_box_not_until_stopped_keeps_state would cover it.
There was a problem hiding this comment.
Agreed, nothing pins restart. A follow-up PR adds the refused restart of an until_stopped box whose stored spec its root excludes (exit 3, RestartRefusalKind::Spec, record bytes unchanged), next to restart_refuses_box_not_until_stopped_keeps_state.
| ), | ||
| Err(AdmissionRootRefusal::UnknownRoot(UnknownRootRefusal { key, value, .. })) => { | ||
| format!( | ||
| "The settings it was created with set `{key}` to `{value}`, which names no \ |
There was a problem hiding this comment.
[low] When key is box.type, this arm also covers a project type that omits type.root, e.g. box.type = "ci". The text "set box.type to ci, which names no built-in type" suggests the type should have been a built-in one, when the actual problem is that the spec does not name the root ci extends. The create message makes that distinction ("does not name the built-in type that ci extends"). Branch on key here the way UnknownRootRefusal's Display does.
There was a problem hiding this comment.
You are right, for a project type the text points at the wrong thing. The follow-up branches on the key the way UnknownRootRefusal does, so a type that omits its root says it does not name the built-in type it extends.
| let spec = | ||
| serde_json_lenient::from_slice::<serde_json_lenient::Value>(stored).map_err(|e| { | ||
| refused(format!( | ||
| "The settings it was created with cannot be read: {e}." |
There was a problem hiding this comment.
[nit] This parse error can't happen on the only caller: checked_stored_spec has already parsed the same bytes as a BoxSpec through box_runtime::stored_spec, which returns this exact sentence on failure. The duplicated string will drift if either one changes. Pass the parsed Value in, or .expect with the reason, and keep one copy of the text.
There was a problem hiding this comment.
Agreed. The follow-up passes the parsed value in, so the sentence has one copy.
What
Creating a box checks that the box's type permits what its spec asks for (BOX-160). Resuming or restarting a box from its stored spec did not run that check. BOX-025a says a resume re-checks the stored spec and refuses "with the exit code creation would give", and the code's own comment says a stored spec is "refused as a create of that spec would be refused".
Resume and restart now call the same check creation uses, through one function, before anything is written. A refusal exits 3 with wording for a resume, and the box's record is left unchanged. Creation's own message does not change.
Is this safe for existing boxes
Yes, by reading every writer of a stored spec. Since specs were first stored, the client builds them in two shapes only, a session with a terminal or a task without, and each stored record is filed under the matching type. Task boxes and lifetimes no shipped client writes are already refused earlier, at other checks. So no box the product can create and stop is refused on resume.
That also bounds how reachable this was: it takes a stored spec that creation would refuse, which means a record edited on disk or written by another client. It is defence in depth that the spec asks for.
What was not missing
The other checks creation runs either already ran on resume (version, policy, unenforceable egress), cannot be reached there (a stored spec with secrets is already refused as unreadable), or do not apply (the projection digest compares with what a client sends at creation).
Testing
resume_refuses_stored_spec_its_root_excludes_keeps_state, driven through attach: three refusals (a task spec with a terminal, an unknown type, a session spec on a record filed as a task), each asserting exit 3, the message, unchanged record bytes and noresumedevent; and a control, where the spec creation accepted is stored again and the box resumes to running.Workspace lint, tests and the native end-to-end script pass on this commit.
🤖 Generated with Claude Code