ci: pin workspace root in apply_patch move-traversal test for Bazel hermetic sandbox#282
Merged
Merged
Conversation
Contributor
Author
|
E2B verification (E2B is a different, non-hermetic sandbox than Bazel's bwrap-hermetic sandbox, so it does not reproduce the original
Net: the change compiles. Final green can only be confirmed by the real Bazel CI. |
andrei-hasna
force-pushed
the
ci/fix-apply-patch-bwrap
branch
from
July 20, 2026 13:46
ffcee40 to
35d1889
Compare
…andbox
The apply_patch move-traversal test reads an in-workspace file through the
Linux fs sandbox (bubblewrap) before the traversal guard rejects the outside
move. Before reading, the sandbox masks the workspace `.git` metadata dir
read-only. The shared test harness (`prepare_config`) overrides `config.cwd`
to a temp dir but leaves `config.workspace_roots` pointing at the process's
build-time working directory. On a dev machine that is the repo checkout with
a real `.git`, so the mask binds an existing path; under the Bazel hermetic
CI sandbox that directory has no `.git`, so bwrap fails to set up the `.git`
tmpfs mask ("Can't mount tmpfs on .../.git: No such file or directory") and
the read aborts before the guard runs.
Pin the test's workspace root to the harness cwd (a writable temp dir) so the
`.git` mask always targets an existing, writable location regardless of the
process working directory. This keeps the real path-traversal protection
intact and only fixes the environment-specific test setup.
andrei-hasna
force-pushed
the
ci/fix-apply-patch-bwrap
branch
from
July 20, 2026 14:10
35d1889 to
633d484
Compare
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Root cause
suite::apply_patch_cli::apply_patch_cli_rejects_move_path_traversal_outside_workspacefails under the Bazel hermetic CI sandbox with:
This is an environment-specific test-setup bug, not a defect in the
path-traversal guard:
Add Filetraversal test (which the guard rejects beforetouching the filesystem), this case does an
Update Fileon a file that livesinside the workspace, so the Linux fs sandbox reads it through bubblewrap
before the traversal guard rejects the outside
Move to..gitmetadata directoryread-only (an empty read-only tmpfs when
.gitis missing).prepare_configoverridesconfig.cwdto a fresh temp dirbut leaves
config.workspace_rootspointing at the process's build-timeworking directory (
resolved_cwd = std::env::current_dir()at config build).So the permission profile materializes
:workspace_rootsagainst thatdirectory, and the
.gitmask is applied to<process-cwd>/.git.<process-cwd>is the repo checkout with a real.git,so the mask binds an existing path and the bug is hidden. Under the Bazel
hermetic sandbox,
<process-cwd>=/home/runner/work/codewith/codewith/codex-rshas no
.git(VCS metadata is stripped) and no ancestor with git metadata,so
should_leave_missing_git_for_parent_repo_discoverydoes not skip it andbwrap is told to
--tmpfs <cwd>/.git, which it cannot set up in the hermeticnew-root → the in-workspace read aborts before the guard runs.
Fix
Pin the test's workspace root to the harness cwd (a writable temp dir) so the
.gitmask always targets an existing, writable location regardless of theprocess working directory:
This mirrors the established harness pattern (see
core/tests/suite/permissions_messages.rs) and is scoped to the test only. Thereal path-traversal protection is unchanged: the test still reads
stay.txt,still attempts the
Move to: ../escape-move.txt, and still asserts the"writing outside of the project; rejected by user approval settings" rejection
plus that the escape file is never created.
Scope / coordination
codex-rs/core/tests/suite/apply_patch_cli.rs); noproduction apply_patch / worktree-guard / bwrap logic touched, to avoid
conflicts with the in-flight OCW worktree-guard fixes (OPE80-00009/10/11) on
fix/ocw-worktree-guard.prepare_configleaks the build-time process CWDinto
config.workspace_roots; a follow-up could sync it centrally so futuresandboxed read tests do not need the per-test workaround.
Verification
E2B is a different (non-hermetic) sandbox than Bazel's bwrap-hermetic sandbox,
so it does not reproduce the original failure; the remote build confirms
codex-core(incl. this test) compiles and the crate's tests build/run. Finalgreen can only be confirmed by the real Bazel CI.