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

+29 -9
View File
@@ -19,15 +19,35 @@ pub async fn resolve_root_git_project_for_trust(
Ok(metadata) if metadata.is_directory => cwd.clone(),
_ => cwd.parent()?,
};
let repo_root = find_nearest_native_ancestor_with_markers(
fs,
&base,
vec![".git".to_string()],
FindUpErrorPolicy::Ignore,
/*sandbox*/ None,
)
.await
.ok()??;
let mut base = base;
let repo_root = loop {
let candidate = find_nearest_native_ancestor_with_markers(
fs,
&base,
vec![".git".to_string()],
FindUpErrorPolicy::Ignore,
/*sandbox*/ None,
)
.await
.ok()??;
let dot_git = candidate.join(".git");
let metadata = fs
.get_metadata(&PathUri::from_abs_path(&dot_git), /*sandbox*/ None)
.await
.ok()?;
if !metadata.is_directory
|| fs
.get_metadata(
&PathUri::from_abs_path(&dot_git.join("HEAD")),
/*sandbox*/ None,
)
.await
.is_ok()
{
break candidate;
}
base = candidate.parent()?;
};
let dot_git = repo_root.join(".git");
let dot_git_uri = PathUri::from_abs_path(&dot_git);
let dot_git_metadata = fs.get_metadata(&dot_git_uri, /*sandbox*/ None).await.ok()?;