Repository navigation
🐛 fix: create base-preparation state files without group write - #15879
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
The production change is right; the new test does not compile, so the automerge test package is red.
1. Compile error — jsonPath declared and never used (high)
src/pkg/github/automerge/base_preparation_store_test.go:32 — jsonPath := dir + "/sha256hex.json" is never read. Go treats an unused local as a compile error, so every test in src/pkg/github/automerge fails to build, not just this one. CI confirms it: golangci-lint job 124283816449 and build-and-test job 124283910446 both stop at declared and not used: jsonPath. Delete the line (the loop below it already finds the real file).
2. The assertions cannot fail without the fix under a normal umask (medium)
- File mode:
os.OpenFile(..., fileMode)is masked by the process umask (base_preparation_store.go:88,:116). GitHub runners and most dev shells run with umask022, so the old0o664already landed on disk as0o644— the& 0o020check passes onv5too. The repo already has the pattern for this:src/pkg/beads/beads_perms_test.go:152wraps the write inold := syscall.Umask(0); defer syscall.Umask(old). Do the same here. - Directory mode:
dirist.TempDir(), whichos.MkdirTempcreates at0o700.os.MkdirAllon an existing directory is a no-op, sobase_preparation_store_test.go:22-29asserts on TempDir's mode, not ondirectoryMode. Point the store atfilepath.Join(t.TempDir(), "sub")so the code under test actually creates it.
Minor: e.Name() != ".lock" at :40 never excludes anything — the lock file is <sha256hex>.lock, not .lock. Harmless since both files should be 0o644, but checking every entry (including the lock) is simpler and stronger.
Context I checked: 0o775/0o664 arrived in be04a9cb4 (#15836) with no stated need for group write; the sibling durable store at src/pkg/stagelabels/store.go:613,617 already uses 0o755/0o644, and the only production caller is automerge_base_preparation.go:25 under stagelabels.DefaultStateDir. So tightening to match is consistent and I see no consumer that depends on group write.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Reviewed (security) — no in-scope findings. Mode constants at src/pkg/github/automerge/base_preparation_store.go:80-81 are consumed by all three creation sites (MkdirAll :82, .lock :87, .next :112), and the new test clears umask so the modes are asserted unmasked.
Advisory (not blocking): os.MkdirAll (:82) never chmods a directory that already exists, so any deployment where /data/base-preparation was already created at 0o775 keeps a group-writable directory — same-group processes could still rename/replace the .json snapshot there regardless of the new 0o644 file mode. If #15836 is already running on a shared volume, a one-time chmod 755 on the existing directory is needed for this fix to take effect.
— hive: agent=adjudicator-3 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. |
Match the stagelabels/store.go modes (0o755 directory, 0o644 files) to prevent group-writable state files on the shared /data volume. Group write on the shared volume allows any same-group process to alter ownership state, which represents a security vulnerability. Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
…ise modes Drop the unused jsonPath local that broke compilation of the automerge test package. Clear the umask for the test's duration (restored via t.Cleanup) so the requested modes land unmasked, root the store in a subdirectory of t.TempDir() so MkdirAll creates it, and assert the exact 0755/0644 modes on the directory, the .json snapshot and the .lock file instead of a filter that never matched the hex-prefixed lock name. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
629a0b3 to
649303b
Compare
There was a problem hiding this comment.
Looks correct to me.
Read src/pkg/github/automerge/base_preparation_store.go at 649303b and the sibling store it claims to match: src/pkg/stagelabels/store.go:619 (MkdirAll … 0o755) and :623 (WriteFile … 0o644). The new constants at base_preparation_store.go:141-142 now agree with it, and all three creation sites (.lock at :147, .next at :166, MkdirAll at :143) take their mode from those constants, so nothing is left at 0o664.
The test is sound: it does not call t.Parallel, so the process-wide Umask(0) is restored by t.Cleanup before any parallel tests resume; the store root is a child of t.TempDir() so MkdirAll really creates it; and because .next is renamed to .json at :178 the "only .json and .lock" assertion holds.
One info-level note, not a defect in this diff: os.OpenFile(path+".lock", O_CREATE|O_RDWR, …) at :147 does not change the mode of a .lock that already exists, so lock files created at 0o664 by the current release stay 0o664 until removed. The .json snapshot self-heals on the next write via the rename. The lock file's content is never read, so this is cosmetic.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Base-preparation state files (.lock and .next files) were created with 0o664 mode in a 0o775 directory. On the shared /data volume, group-writable permissions allow any process in the same group to tamper with ownership state.
This fix matches the sibling durable stage store (stagelabels/store.go), which uses 0o755 for directories and 0o644 for files. While corrupt JSON fails closed, well-formed tampering would not be detected.
Added a test to verify file modes are not group-writable.
Closes #15844
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88