Repository navigation
🐛 fix(sink/git): fall back to writable temp dir when cache root is read-only (DR-FIND-06) - #163
Merged
Merged
Conversation
…ad-only (DR-FIND-06)
There was a problem hiding this comment.
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 attemptensureSecureMirrorRoot()on the cache candidate and fall back to a separately validated temp candidate on any failure, while still honoringKOLLECT_GIT_MIRROR_DIRexactly (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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



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, soos.UserCacheDir()succeeds and returns/home/nonroot/.cache/...on the read-only rootfs; the olddefaultMirrorRoot()only fell back toos.TempDir()whenUserCacheDir()errored, so every git export failed withmkdir /home/nonroot: read-only file system. The chart already mounts a writable/tmpemptyDir (deployment.yaml:126-136) andos.TempDir()resolves there — the code just never reached it.Fix
mirrorRootDir()now tries the cache candidate viaensureSecureMirrorRoot, and on any error (read-only rootfs / unwritable parent / ENOTDIR / permission / insecure-reuse) falls back to the temp path (independently re-validated). An explicitKOLLECT_GIT_MIRROR_DIRis still honored exactly — no fallback. Usesos.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).