VAULT-2809: Tweak creation of vault.db file (#12034)

This commit is contained in:
Nick Cabatoff
2021-07-09 20:45:50 +02:00
committed by GitHub
parent 91c323df46
commit 43af97e650
3 changed files with 19 additions and 2 deletions

3
changelog/12034.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
storage/raft: Tweak creation of vault.db file
```

View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"strings"
@@ -154,9 +155,22 @@ func (f *FSM) openDBFile(dbPath string) error {
return errors.New("can not open empty filename")
}
st, err := os.Stat(dbPath)
switch {
case err != nil && os.IsNotExist(err):
case err != nil:
return fmt.Errorf("error checking raft FSM db file %q: %v", dbPath, err)
default:
perms := st.Mode() & os.ModePerm
if perms&0o077 != 0 {
f.logger.Warn("raft FSM db file has wider permissions than needed",
"needed", os.FileMode(0o600), "existing", perms)
}
}
freelistType, noFreelistSync := freelistOptions()
start := time.Now()
boltDB, err := bolt.Open(dbPath, 0o666, &bolt.Options{
boltDB, err := bolt.Open(dbPath, 0o600, &bolt.Options{
Timeout: 1 * time.Second,
FreelistType: freelistType,
NoFreelistSync: noFreelistSync,

View File

@@ -330,7 +330,7 @@ func (s *BoltSnapshotSink) writeBoltDBFile() error {
// Create the BoltDB file
dbPath := filepath.Join(path, databaseFilename)
boltDB, err := bolt.Open(dbPath, 0o666, &bolt.Options{Timeout: 1 * time.Second})
boltDB, err := bolt.Open(dbPath, 0o600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
return err
}