From cb3b81ee07423685a0f2d6a3fb33d0b68373bd66 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:57:46 -0400 Subject: [PATCH 1/2] fix: create base-preparation state files without group write 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> --- .../security-base-preparation-file-modes.md | 1 + .../automerge/base_preparation_store.go | 4 +- .../automerge/base_preparation_store_test.go | 55 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 changelog.d/security-base-preparation-file-modes.md create mode 100644 src/pkg/github/automerge/base_preparation_store_test.go diff --git a/changelog.d/security-base-preparation-file-modes.md b/changelog.d/security-base-preparation-file-modes.md new file mode 100644 index 0000000000..d5f276cd3c --- /dev/null +++ b/changelog.d/security-base-preparation-file-modes.md @@ -0,0 +1 @@ +- Base-preparation state files and directory are no longer created group-writable (0o644/0o755, matching the stage store). (#15844) diff --git a/src/pkg/github/automerge/base_preparation_store.go b/src/pkg/github/automerge/base_preparation_store.go index bb4608af00..f32fca1fd8 100644 --- a/src/pkg/github/automerge/base_preparation_store.go +++ b/src/pkg/github/automerge/base_preparation_store.go @@ -138,8 +138,8 @@ func (s *BasePreparationStore) change(key string, fn func(*basePreparation) erro s.mu.Unlock() return nil } - const directoryMode = 0o775 - const fileMode = 0o664 + const directoryMode = 0o755 + const fileMode = 0o644 if err := os.MkdirAll(s.dir, directoryMode); err != nil { return err } diff --git a/src/pkg/github/automerge/base_preparation_store_test.go b/src/pkg/github/automerge/base_preparation_store_test.go new file mode 100644 index 0000000000..1326608e8c --- /dev/null +++ b/src/pkg/github/automerge/base_preparation_store_test.go @@ -0,0 +1,55 @@ +package automerge + +import ( + "os" + "testing" +) + +func TestBasePreparationStoreFileModes(t *testing.T) { + dir := t.TempDir() + store := NewBasePreparationStore(dir) + + // Perform a change to create the directory and files. + err := store.change("owner/repo:main", func(st *basePreparation) error { + st.Owner.Number = 42 + return nil + }) + if err != nil { + t.Fatalf("change failed: %v", err) + } + + // Check directory mode is not group-writable. + dirInfo, err := os.Stat(dir) + if err != nil { + t.Fatalf("stat directory failed: %v", err) + } + dirMode := dirInfo.Mode() + if (dirMode & 0o020) != 0 { + t.Errorf("directory is group-writable: mode=%#o", dirMode) + } + + // Check .json file mode is not group-writable. + jsonPath := dir + "/sha256hex.json" + // Find actual .json file since the name is sha256(key) + entries, err := os.ReadDir(dir) + if err != nil { + t.Fatalf("readdir failed: %v", err) + } + var jsonFile os.FileInfo + for _, e := range entries { + if e.Name() != ".lock" { + info, err := e.Info() + if err != nil { + t.Fatalf("info failed: %v", err) + } + jsonFile = info + break + } + } + if jsonFile != nil { + jsonMode := jsonFile.Mode() + if (jsonMode & 0o020) != 0 { + t.Errorf(".json file is group-writable: mode=%#o", jsonMode) + } + } +} From 649303b591dace059e2cbbeadbbde1b0bd7469f7 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:58:21 -0400 Subject: [PATCH 2/2] test: make base-preparation file-mode test compile and actually exercise 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> --- .../automerge/base_preparation_store_test.go | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/pkg/github/automerge/base_preparation_store_test.go b/src/pkg/github/automerge/base_preparation_store_test.go index 1326608e8c..e42ecc5bfb 100644 --- a/src/pkg/github/automerge/base_preparation_store_test.go +++ b/src/pkg/github/automerge/base_preparation_store_test.go @@ -2,14 +2,24 @@ package automerge import ( "os" + "path/filepath" + "strings" + "syscall" "testing" ) +// TestBasePreparationStoreFileModes verifies the store never creates +// group-writable state on the shared /data volume. The umask is cleared so the +// requested modes land on disk unmasked (runners default to 022, which would +// hide a group-writable request), and the store root is a subdirectory of +// t.TempDir() so MkdirAll actually creates it with the store's mode. func TestBasePreparationStoreFileModes(t *testing.T) { - dir := t.TempDir() + old := syscall.Umask(0) + t.Cleanup(func() { syscall.Umask(old) }) + + dir := filepath.Join(t.TempDir(), "state") store := NewBasePreparationStore(dir) - // Perform a change to create the directory and files. err := store.change("owner/repo:main", func(st *basePreparation) error { st.Owner.Number = 42 return nil @@ -18,38 +28,38 @@ func TestBasePreparationStoreFileModes(t *testing.T) { t.Fatalf("change failed: %v", err) } - // Check directory mode is not group-writable. dirInfo, err := os.Stat(dir) if err != nil { t.Fatalf("stat directory failed: %v", err) } - dirMode := dirInfo.Mode() - if (dirMode & 0o020) != 0 { - t.Errorf("directory is group-writable: mode=%#o", dirMode) + if got := dirInfo.Mode().Perm(); got != 0o755 { + t.Errorf("directory mode = %#o, want 0755", got) } - // Check .json file mode is not group-writable. - jsonPath := dir + "/sha256hex.json" - // Find actual .json file since the name is sha256(key) entries, err := os.ReadDir(dir) if err != nil { t.Fatalf("readdir failed: %v", err) } - var jsonFile os.FileInfo + var sawJSON, sawLock bool for _, e := range entries { - if e.Name() != ".lock" { - info, err := e.Info() - if err != nil { - t.Fatalf("info failed: %v", err) - } - jsonFile = info - break + info, err := e.Info() + if err != nil { + t.Fatalf("info %s failed: %v", e.Name(), err) } - } - if jsonFile != nil { - jsonMode := jsonFile.Mode() - if (jsonMode & 0o020) != 0 { - t.Errorf(".json file is group-writable: mode=%#o", jsonMode) + switch { + case strings.HasSuffix(e.Name(), ".json"): + sawJSON = true + case strings.HasSuffix(e.Name(), ".lock"): + sawLock = true + default: + t.Errorf("unexpected entry %q", e.Name()) + continue } + if got := info.Mode().Perm(); got != 0o644 { + t.Errorf("%s mode = %#o, want 0644", e.Name(), got) + } + } + if !sawJSON || !sawLock { + t.Fatalf("expected a .json and a .lock entry, got json=%v lock=%v", sawJSON, sawLock) } }