Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Scrub hook Git env for registry sibling reads

rcourtman94aa399d2b84
diff --git a/scripts/release_control/registry_audit.py b/scripts/release_control/registry_audit.py
index 08b0bafba3..3781ec22f8 100644
--- a/scripts/release_control/registry_audit.py
+++ b/scripts/release_control/registry_audit.py
@@ -5,7 +5,6 @@ from __future__ import annotations
import argparse
import json
-import os
from pathlib import Path
import re
import subprocess
@@ -20,7 +19,7 @@ from canonical_completion_guard import (
subsystem_matches_path,
)
from control_plane import DEFAULT_CONTROL_PLANE
-from repo_file_io import canonical_repo_id, canonical_workspace_repos_root, load_repo_json
+from repo_file_io import canonical_repo_id, canonical_workspace_repos_root, git_env, load_repo_json
from status_audit import load_status_payload
@@ -73,16 +72,13 @@ def tracked_workspace_files(*, active_repos: list[str], local_repo: str) -> set[
repo_root = REPO_ROOT if repo_id == local_repo else repos_root / repo_id
if not repo_root.exists():
continue
- env = os.environ.copy()
- if repo_root != REPO_ROOT:
- env.pop("GIT_INDEX_FILE", None)
result = subprocess.run(
["git", "ls-files", "-z"],
cwd=repo_root,
check=True,
capture_output=True,
text=False,
- env=env,
+ env=git_env(repo_root, local_repo_root=REPO_ROOT),
)
for entry in result.stdout.split(b"\x00"):
if not entry:
diff --git a/scripts/release_control/registry_audit_test.py b/scripts/release_control/registry_audit_test.py
index a79dec84b9..2df8306dad 100644
--- a/scripts/release_control/registry_audit_test.py
+++ b/scripts/release_control/registry_audit_test.py
@@ -72,6 +72,74 @@ class RegistryAuditTest(unittest.TestCase):
self.assertIn("internal/staged.go", files)
self.assertNotIn("pulse:internal/staged.go", files)
+ def test_tracked_workspace_files_scrubs_hook_env_for_sibling_repos(self) -> None:
+ with tempfile.TemporaryDirectory() as tmpdir:
+ workspace = Path(tmpdir) / "workspace"
+ repo_root = workspace / "repos" / "pulse"
+ mobile_repo = workspace / "repos" / "pulse-mobile"
+ repo_root.mkdir(parents=True)
+ mobile_repo.mkdir(parents=True)
+
+ self.git(repo_root, "init")
+ (repo_root / "internal").mkdir()
+ (repo_root / "internal" / "local.go").write_text("package internal\n", encoding="utf-8")
+ self.git(repo_root, "add", "internal/local.go")
+ self.git(
+ repo_root,
+ "-c",
+ "user.name=Pulse Test",
+ "-c",
+ "commit",
+ "-m",
+ "initial",
+ )
+
+ self.git(mobile_repo, "init")
+ (mobile_repo / "src" / "relay" / "__tests__").mkdir(parents=True)
+ (mobile_repo / "src" / "relay" / "client.ts").write_text("export {}\n", encoding="utf-8")
+ (mobile_repo / "src" / "relay" / "__tests__" / "channel.test.ts").write_text(
+ "export {}\n",
+ encoding="utf-8",
+ )
+ self.git(mobile_repo, "add", "src/relay/client.ts", "src/relay/__tests__/channel.test.ts")
+ self.git(
+ mobile_repo,
+ "-c",
+ "user.name=Pulse Test",
+ "-c",
+ "commit",
+ "-m",
+ "initial",
+ )
+
+ hook_env = {
+ "GIT_DIR": str(repo_root / ".git"),
+ "GIT_WORK_TREE": str(repo_root),
+ "GIT_INDEX_FILE": str(repo_root / ".git" / "index"),
+ "GIT_COMMON_DIR": str(repo_root / ".git"),
+ }
+ contracts_dir = repo_root / "docs" / "release-control" / "v6" / "internal" / "subsystems"
+ contracts_dir.mkdir(parents=True)
+
+ with patch("registry_audit.REPO_ROOT", repo_root), patch(
+ "registry_audit.DEFAULT_CONTROL_PLANE",
+ {
+ **registry_audit.DEFAULT_CONTROL_PLANE,
+ "subsystems_dir_path": str(contracts_dir),
+ },
+ ), patch.dict(os.environ, hook_env, clear=False):
+ files = tracked_workspace_files(
+ active_repos=["pulse", "pulse-mobile"],
+ local_repo="pulse",
+ )
+
+ self.assertIn("internal/local.go", files)
+ self.assertIn("pulse-mobile:src/relay/client.ts", files)
+ self.assertIn("pulse-mobile:src/relay/__tests__/channel.test.ts", files)
+ self.assertNotIn("pulse-mobile:internal/local.go", files)
+
def test_audit_registry_payload_accepts_valid_minimal_registry(self) -> None:
payload = {
"version": 13,
diff --git a/scripts/release_control/repo_file_io.py b/scripts/release_control/repo_file_io.py
index 903ca0e97f..7230bbb0ca 100644
--- a/scripts/release_control/repo_file_io.py
+++ b/scripts/release_control/repo_file_io.py
@@ -12,13 +12,37 @@ from typing import Any, Iterable
REPO_ROOT = Path(__file__).resolve().parents[2]
DEFAULT_REPO_ROOT = REPO_ROOT
+LOCAL_GIT_ENV_VARS = (
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
+ "GIT_CONFIG",
+ "GIT_CONFIG_PARAMETERS",
+ "GIT_CONFIG_COUNT",
+ "GIT_OBJECT_DIRECTORY",
+ "GIT_DIR",
+ "GIT_WORK_TREE",
+ "GIT_IMPLICIT_WORK_TREE",
+ "GIT_GRAFT_FILE",
+ "GIT_INDEX_FILE",
+ "GIT_NO_REPLACE_OBJECTS",
+ "GIT_REPLACE_REF_BASE",
+ "GIT_PREFIX",
+ "GIT_SHALLOW_FILE",
+ "GIT_COMMON_DIR",
+)
+
+
+def strip_local_git_env(env: dict[str, str]) -> dict[str, str]:
+ for name in LOCAL_GIT_ENV_VARS:
+ env.pop(name, None)
+ return env
-def git_env(repo_root: Path | None = None) -> dict[str, str]:
+def git_env(repo_root: Path | None = None, *, local_repo_root: Path | None = None) -> dict[str, str]:
env = os.environ.copy()
root = repo_root or REPO_ROOT
- if root != DEFAULT_REPO_ROOT:
- env.pop("GIT_INDEX_FILE", None)
+ local_root = local_repo_root or DEFAULT_REPO_ROOT
+ if root.resolve() != local_root.resolve():
+ strip_local_git_env(env)
return env
diff --git a/scripts/release_control/repo_file_io_test.py b/scripts/release_control/repo_file_io_test.py
index 14da8ab4e0..7296301628 100644
--- a/scripts/release_control/repo_file_io_test.py
+++ b/scripts/release_control/repo_file_io_test.py
@@ -10,6 +10,7 @@ from repo_file_io import (
canonical_repo_id,
canonical_repo_root,
canonical_workspace_repos_root,
+ git_env,
load_repo_json,
missing_staged_repo_paths,
read_repo_text,
@@ -79,6 +80,37 @@ class RepoFileIoTest(unittest.TestCase):
with patch("repo_file_io.REPO_ROOT", repo_root):
self.assertEqual(missing_staged_repo_paths([staged_rel, missing_rel]), [missing_rel])
+ def test_git_env_preserves_local_hook_env_and_scrubs_other_repos(self) -> None:
+ with tempfile.TemporaryDirectory() as tmpdir:
+ workspace = Path(tmpdir) / "workspace"
+ local_repo = workspace / "repos" / "pulse"
+ sibling_repo = workspace / "repos" / "pulse-mobile"
+ local_repo.mkdir(parents=True)
+ sibling_repo.mkdir(parents=True)
+
+ leaked_env = {
+ "PATH": os.environ.get("PATH", ""),
+ "GIT_DIR": str(local_repo / ".git"),
+ "GIT_WORK_TREE": str(local_repo),
+ "GIT_INDEX_FILE": str(local_repo / ".git" / "index"),
+ "GIT_COMMON_DIR": str(local_repo / ".git"),
+ "GIT_PREFIX": "docs/",
+ }
+
+ with patch.dict(os.environ, leaked_env, clear=True):
+ local_env = git_env(local_repo, local_repo_root=local_repo)
+ sibling_env = git_env(sibling_repo, local_repo_root=local_repo)
+
+ self.assertEqual(local_env["GIT_DIR"], leaked_env["GIT_DIR"])
+ self.assertEqual(local_env["GIT_WORK_TREE"], leaked_env["GIT_WORK_TREE"])
+ self.assertEqual(local_env["GIT_INDEX_FILE"], leaked_env["GIT_INDEX_FILE"])
+ self.assertEqual(sibling_env["PATH"], leaked_env["PATH"])
+ self.assertNotIn("GIT_DIR", sibling_env)
+ self.assertNotIn("GIT_WORK_TREE", sibling_env)
+ self.assertNotIn("GIT_INDEX_FILE", sibling_env)
+ self.assertNotIn("GIT_COMMON_DIR", sibling_env)
+ self.assertNotIn("GIT_PREFIX", sibling_env)
+
def test_canonical_repo_identity_uses_git_common_dir_for_linked_worktree(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
workspace = Path(tmpdir) / "workspace"