Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/security-base-preparation-file-modes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Base-preparation state files and directory are no longer created group-writable (0o644/0o755, matching the stage store). (#15844)
4 changes: 2 additions & 2 deletions src/pkg/github/automerge/base_preparation_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
65 changes: 65 additions & 0 deletions src/pkg/github/automerge/base_preparation_store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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) {
old := syscall.Umask(0)
t.Cleanup(func() { syscall.Umask(old) })

dir := filepath.Join(t.TempDir(), "state")
store := NewBasePreparationStore(dir)

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)
}

dirInfo, err := os.Stat(dir)
if err != nil {
t.Fatalf("stat directory failed: %v", err)
}
if got := dirInfo.Mode().Perm(); got != 0o755 {
t.Errorf("directory mode = %#o, want 0755", got)
}

entries, err := os.ReadDir(dir)
if err != nil {
t.Fatalf("readdir failed: %v", err)
}
var sawJSON, sawLock bool
for _, e := range entries {
info, err := e.Info()
if err != nil {
t.Fatalf("info %s failed: %v", e.Name(), err)
}
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)
}
}
Loading