Skip to content

Commit

Permalink
VAULT-2809: Tweak creation of vault.db file (hashicorp#12034)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff authored and jartek committed Sep 11, 2021
1 parent 307d2f9 commit 6c89955
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/12034.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
storage/raft: Tweak creation of vault.db file
```
16 changes: 15 additions & 1 deletion physical/raft/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion physical/raft/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6c89955

Please sign in to comment.