Repository navigation
fix(cache): confine file operations to the configured root - #5231
singh4jitendra wants to merge 2 commits into
Conversation
Confine traditional and shared-chunk cache filesystem operations to their configured root with os.Root. Protect creation, reads/stat, sparse writes, CRC validation, eviction and atomic shared-cache publication against final and intermediate symlink escapes. Preserve configured-root symlinks, in-root relative links, cache layout and permissions, with target-preservation regressions.
There was a problem hiding this comment.
Code Review
This pull request enhances the security of the file cache mechanism by preventing symlink escape vulnerabilities. It introduces a RootDir field to FileSpec to track the trusted cache root and refactors file operations—including creation, opening, stat, and removal—to use Go's os.Root (via os.OpenRoot), ensuring all filesystem operations are strictly confined within the trusted cache directory. Comprehensive unit tests have been added to verify that symlink escapes are rejected while legitimate root symlinks remain supported. As there are no review comments provided, I have no further feedback to offer.
|
Hi @charith87, could you take a look when you have a moment? The cache-root hardening is ready for review, and the local build and race tests passed. The GitHub workflows are still waiting for approval. Happy to make any changes you suggest. Thanks! |
Merge current master without rewriting PR history. Preserve the PR behavior while adopting the upstream v4 module path, Go 1.27.4 and dependency security updates. Validated with relevant race tests and make build.
|
Merged the latest master in c01ded9 and resolved the two v4 import conflicts, keeping the confined cache helpers in place. Rechecked on native Linux with Go 1.27.4:
The branch is updated without rewriting history, and the cache-root protections and compatibility behavior are unchanged. Ready for the updated CI run and review. |
|
Adding @abhishek10004 for review since seems to relate to shared chunk cache. |
|
Hi @abhishek10004, @charith87 pointed this your way for review. Could you have a look when you get a chance? Thanks! |
|
Hi @abhishek10004, could you take a final look when you get a chance and merge if all looks good? Thanks! |
|
Hi @abhishek10004, just checking in on the cache-root change. Could you review it when you have a chance and merge if everything looks good? Happy to make any adjustments. Thanks! |
|
Hi @abhishek10004, could you take a look at the cache-root fix when you have time? Happy to address any feedback before merge. Thanks! |
|
Hi @abhishek10004, could you review the cache-root fix when you have a chance? Thanks! |
|
Hi @trinadhkotturu @abhishek10004, this issue can only happen if a process or user already has write access to the |
Description
The root remains operator-trusted. Fresh private permissions already mitigate ordinary cross-user access, and bucket-object control alone is insufficient to exploit this class of issue. The change does not authenticate cache contents from untrusted writers or provide a general filesystem sandbox. It addresses a different boundary from #5225 and does not restore the reverted log-file change #4637/#4654.
The shared-reader edits overlap #5225. If that PR lands first, this branch should be rebased so rooted paths retain its full-object cache identity; the two fixes are kept as separate review units rather than duplicating the namespace fix here.
Link to the issue in case of a bug fix.
Fixes #5226
Testing details
Checks ran with Go 1.27.2 on native Linux storage in Ubuntu 24.04 under WSL. Native storage was used because drvfs does not preserve the permission semantics and raw LF checksum fixtures required by existing tests. No test expectations were weakened. Only the verified formatted changes were copied back to the contribution worktree.
make build- passed, including generation, imports/formatting, dependency hygiene, vet, golangci-lint (0 issues), and compilation.git diff --check- passed.go test -mod=readonly -count=1 -timeout=60s -run '^TestCreateFileRejectsSymlinkEscapes$' ./internal/cache/util- failed as expected for all four read/truncate escape cases, including truncation of the owned sentinel target.go test -mod=readonly -p 1 -count=1 -timeout=8m ./internal/cache/... ./internal/gcsx- passed in all seven packages.go test -mod=readonly -p 1 -count=1 -race -timeout=8m ./internal/cache/... ./internal/gcsx- passed in all seven packages, with no race reports.Any backward incompatible change? If so, please explain.
Absolute or escaping descendant symlinks inside the cache are intentionally rejected. The configured cache root itself can still point to the intended storage through a symlink, and relative descendant links confined to the root remain supported. Cache keys/layout, configured permissions, and ordinary/shared-cache modes are unchanged. Cache writers must still be trusted for data integrity.