Repository navigation
fix(mfile,mctx,minimald): keep a box's minimal.toml edits inside its workspace (0.7 backport) - #3596
Merged
Conversation
…workspace Backport of #3404 to release/0.7.x. When a box runs `min add`, the daemon edits the box's minimal.toml on its behalf. On this line that edit read the file and wrote it back with std::fs::write, so a link under the workspace carried the read and the write to a file outside it, and a dangling link had its target created there. Kept from the source: the confined editor with openat2(2) and RESOLVE_BENEATH on Linux, the descriptor-relative read and replace, the no-links check where openat2 is missing, the `beneath` module, every refusal with main's wording, `Context::confine_mfile_edits_to` carried through `cloned_reinit`, and the daemon's per-box context setting it to the box's workspace. Host CLI edits keep following links as before. Adapted for this line: - This line has no `File::edit_exclusively` and no minimal.toml lock (both came with #2302), so the editor is `File::edit_within`, main's `edit_exclusively_within` without the lock. - `add_deps` keeps this line's body; only its read and write go through the confined editor when the context has a workspace root. - The daemon change is in `Session::build_context` (box_actor/setup.rs on main). - The temp file and rename are made through the directory's descriptor (openat with O_EXCL, renameat, unlinkat on failure) rather than through tempfile and /proc, so the Linux path and the fallback share one write. mfile now depends on libc. Needed on this line beyond main's change: - The scaffold of a default minimal.toml (`scaffold_mfile_if_missing`, run by configure_loadout and by build_context on an attach or relaunch) wrote by path with std::fs::write. A dangling link at minimal.toml reads as missing, so the write followed it out of the workspace. It now goes through `File::edit_within` and writes only if the name is still empty. On main the scaffold uses the #2302 editor, which refuses a dangling link. - Main's fallback for a system without openat2 replaces the file by temp file and rename in the canonical parent. Here the fallback, after the no-links check, opens the parent directory once (its last name with O_NOFOLLOW) and does the same descriptor-relative read (O_NOFOLLOW), temp file and rename as the openat2 path, so a link put at the name after the check is refused or replaced, never followed. Tests: the mfile edit_within tests, the mctx add_deps refusal and the session test are ported, each refusal with a control in which the same edit of a regular file succeeds; the session test's control writes a package. New: fallback tests that call the fallback directly (a link at the name, a dangling link, a `.minimal` link, a link swapped in during the edit, and a regular file as control) and a scaffold test (a dangling link refused, nothing created at its target; an empty workspace scaffolded as control). (cherry picked from commit 287e4f4) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
norrietaylor
approved these changes
Nov 18, 2026
Contributor
|
Approved: no findings at Nothing to do. Clobber: none seen. |
bryan-minimal
enabled auto-merge (squash)
November 18, 2026 22:42
bryan-minimal
disabled auto-merge
November 18, 2026 22:42
bryan-minimal
enabled auto-merge (squash)
November 18, 2026 22:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #3404 to
release/0.7.x, ported by hand. It replaces #3519, the automatic backport: the cherry-pick conflicted in four files, and this line needed two changes that main's commit does not contain.Squash-merge this PR and keep the PR title as the subject.
What
When a command run inside a box asks the daemon to edit the box's
minimal.toml, the daemon now resolves that file beneath the box's workspace. A link that leads out of the workspace is refused, with the same messages as on main.Kept from #3404
openat2withRESOLVE_BENEATHon Linux, and a no-links check whereopenat2is missing.Adapted for this line
minimal.tomllock (both came with fix(mfile): lock minimal.toml edits and name missing link fields #2302). The editor here is main's without the lock.add_depskeeps this line's body. Only its read and write go through the confined editor.Session::build_context; on main it is inbox_actor/setup.rs.mfilenow depends onlibc.Needed here beyond main's change
minimal.tomlinto a box's workspace when it builds the box's context and finds none. On this line that write went by path. On main it goes through the fix(mfile): lock minimal.toml edits and name missing link fields #2302 editor. Here it now goes through the confined editor and writes only when the name is still empty.openat2. After the no-links check it opens the parent directory once, reads without following a link, and replaces the file by a temporary file and a rename, as theopenat2path does. A link put at the name while an edit runs is refused with "it was replaced by a link during the edit".Both came from an independent review of the first version of this port.
Testing
edit_withintests, theadd_depsrefusal and the session test. Each refusal has a control in which the same edit of a regular file succeeds..minimallink, a link put there during the edit, and a regular file as the control), and a scaffold test with an empty workspace as its control.Workspace lint, tests, the new tests repeated 15 times, and the native end-to-end script pass on this commit.
🤖 Generated with Claude Code