Skip to content

Commit 67d17f0

Browse files
committed
fix(knowledge): tighten sentinel perms to 0600 and silence fd gosec warnings
1 parent 84ea19d commit 67d17f0

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

workspace/knowledge.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,20 @@ func withSentinelLock(sentinelPath string, fn func() error) error {
9696
// Open or create the sentinel file just to acquire the lock fd.
9797
// We do NOT read/write through this fd to keep flock + atomic-write
9898
// concerns separate.
99-
lockFile, err := os.OpenFile(sentinelPath, os.O_RDWR|os.O_CREATE, 0o644)
99+
lockFile, err := os.OpenFile(sentinelPath, os.O_RDWR|os.O_CREATE, 0o600)
100100
if err != nil {
101101
return fmt.Errorf("failed to open sentinel for locking: %w", err)
102102
}
103103
defer func() {
104104
_ = lockFile.Close()
105105
}()
106106

107-
if err := syscall.Flock(int(lockFile.Fd()), syscall.LOCK_EX); err != nil {
107+
fd := int(lockFile.Fd()) //nolint:gosec // os.File.Fd returns uintptr but the underlying OS fd is always a valid int on unix
108+
if err := syscall.Flock(fd, syscall.LOCK_EX); err != nil {
108109
return fmt.Errorf("failed to acquire sentinel lock: %w", err)
109110
}
110111
defer func() {
111-
_ = syscall.Flock(int(lockFile.Fd()), syscall.LOCK_UN)
112+
_ = syscall.Flock(fd, syscall.LOCK_UN)
112113
}()
113114

114115
return fn()

0 commit comments

Comments
 (0)