fix(store): chmod SQLite DB files to 0600 on open
Bare-metal installs created the DB with process umask (often 022), making uptop.db, -wal, and -shm world-readable. These files contain alert credentials and config. Now chmod 0600 after open. Missing WAL/SHM siblings (not yet created) are silently skipped. Docker installs were already mitigated by the non-root UID.
This commit was merged in pull request #119.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
@@ -25,6 +26,13 @@ func NewSQLiteStore(path string) (*SQLStore, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if path != ":memory:" {
|
||||
for _, suffix := range []string{"", "-wal", "-shm"} {
|
||||
if err := os.Chmod(path+suffix, 0600); err != nil && !os.IsNotExist(err) {
|
||||
slog.Warn("failed to chmod database file", "path", path+suffix, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user