Skip to content

🐛 fix(sink/git): fall back to writable temp dir when cache root is read-only (DR-FIND-06) - #163

Merged
konih merged 1 commit into
mainfrom
fix/dr-find-06-git-mirror-rootfs
Aug 2, 2026
Merged

konih merged 1 commit into
mainfrom
fix/dr-find-06-git-mirror-rootfs

Conversation

@konih

@konih konih commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

DR-FIND-06 (P1) — git export fails on read-only rootfs

Found in the driving-range lab. In the shipped container the base image sets HOME=/home/nonroot, so os.UserCacheDir() succeeds and returns /home/nonroot/.cache/... on the read-only rootfs; the old defaultMirrorRoot() only fell back to os.TempDir() when UserCacheDir() errored, so every git export failed with mkdir /home/nonroot: read-only file system. The chart already mounts a writable /tmp emptyDir (deployment.yaml:126-136) and os.TempDir() resolves there — the code just never reached it.

Fix

mirrorRootDir() now tries the cache candidate via ensureSecureMirrorRoot, and on any error (read-only rootfs / unwritable parent / ENOTDIR / permission / insecure-reuse) falls back to the temp path (independently re-validated). An explicit KOLLECT_GIT_MIRROR_DIR is still honored exactly — no fallback. Uses os.TempDir(), not a hardcoded /tmp. The empirically-false "container has neither HOME nor XDG_CACHE_HOME set" comment is corrected.

Tests (TDD)

  • TestMirrorRootDir_readOnlyCacheFallsBackToTempDir — driver, fails before / passes after (root-safe ENOTDIR technique).
  • TestMirrorRootDir_writableCacheIsPreferred, TestMirrorRootDir_explicitOverrideIsNotRedirected — behavior guards.

Review

Independent reviewer: APPROVE, no P0/P1/P2 (3 P3 nits). Confirmed the end-to-end linchpin (RO rootfs + writable /tmp emptyDir), genuine TDD driver, no security weakening, and that pre-existing git-export test failures are env-only (CI Preflight green on main).

Closes the CODE half only — the finding closes on a live driving-range re-verify (deploy + kollect-pipeline collect to a git sink), not on merge.

Copilot AI review requested due to automatic review settings August 2, 2026 10:17
@konih
konih merged commit 9d0bd61 into main Aug 2, 2026
22 checks passed
@konih
konih deleted the fix/dr-find-06-git-mirror-rootfs branch August 2, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes git sink exports failing in containers where the per-user cache directory resolves onto a read-only root filesystem by adding a secure runtime fallback from the cache candidate to a temp-dir-backed mirror root.

Changes:

  • Split default mirror root computation into cache and temp candidates, keeping defaultMirrorRoot() as the deterministic “candidate chooser” used by existing tests.
  • Update mirrorRootDir() to attempt ensureSecureMirrorRoot() on the cache candidate and fall back to a separately validated temp candidate on any failure, while still honoring KOLLECT_GIT_MIRROR_DIR exactly (no fallback).
  • Add regression tests covering read-only/unusable cache fallback behavior, cache preference when writable, and non-redirection of explicit operator override.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/sink/git/mirror.go Adds cache-vs-temp candidate helpers and runtime fallback logic in mirrorRootDir() while preserving secure validation.
internal/sink/git/mirror_root_test.go Updates the default-path test commentary to reflect the new behavior and where fallback lives.
internal/sink/git/mirror_root_fallback_test.go Adds new unit tests to lock in fallback, preference, and explicit override behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +85
custom := filepath.Join(t.TempDir(), "operator-mirrors")
t.Setenv(envMirrorDir, custom)
// Even with an unusable cache candidate, the explicit path wins.
setUnusableCacheHome(t)
t.Setenv(envMirrorDir, custom)
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants