Preserve parent repository discovery through sandbox metadata mounts (#39629)

## Why

The Linux sandbox represents missing protected metadata paths such as `.git`
with empty read-only directories. Repository and project discovery treated any
`.git` directory as a checkout root, so this synthetic directory could hide a
real parent repository and its trust configuration.

## What changed

- Treat a `.git` directory as repository metadata only when it contains
  `HEAD`, while continuing to recognize file-based `.git` entries.
- Protect missing `.git` paths with the same read-only synthetic mounts as
  other workspace metadata without disrupting parent-repository discovery.
- Canonicalize and read-only bind the synthetic-mount registry into the
  sandbox, and make protected-path cleanup handle read-only directory trees.

## Testing

Added coverage for repository, project-root, trust, synthetic-mount, and
Landlock behavior, including nested incomplete `.git` directories and a
redirected `TMPDIR`.

GitOrigin-RevId: 0724c54d56531143bb28011e4ca414cd3b0212be
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-20 06:57:00 +00:00
1 parent e396ef3fc1
commit 9ca99b5171
15 files changed
+305 -116

No files matched your search

+1
View File
@@ -41,6 +41,7 @@ async fn remote_project_trust_guards_thread_start_and_preserves_repository_decis
std::fs::create_dir_all(&codex_home)?;
std::fs::create_dir_all(&project_cwd)?;
std::fs::create_dir(project_root.join(".git"))?;
std::fs::write(project_root.join(".git/HEAD"), "ref: refs/heads/main\n")?;
std::fs::create_dir(project_cwd.join(".codex"))?;
let undecided_config = format!(
"[{}]\n",