Skip to content

Commit 34544d7

Browse files
committed
lsm: Implement TruncFile
We need RWFile access + O_TRUNC access Signed-off-by: Morten Linderud <[email protected]>
1 parent 48a3109 commit 34544d7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

database.go

-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/foxboron/sbctl/lsm"
1111
"github.com/landlock-lsm/go-landlock/landlock"
1212

13-
ll "github.com/landlock-lsm/go-landlock/landlock/syscall"
1413
"github.com/spf13/afero"
1514
)
1615

@@ -63,11 +62,6 @@ func SigningEntryIter(state *config.State, fn func(s *SigningEntry) error) error
6362
return nil
6463
}
6564

66-
const (
67-
// We open the file with O_TRUNC
68-
accessFile landlock.AccessFSSet = ll.AccessFSExecute | ll.AccessFSWriteFile | ll.AccessFSReadFile | ll.AccessFSTruncate
69-
)
70-
7165
func LandlockFromFileDatabase(state *config.State) error {
7266
var llrules []landlock.Rule
7367
files, err := ReadFileDatabase(state.Fs, state.Config.FilesDb)

lsm/lsm.go

+9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ import (
66

77
"github.com/foxboron/sbctl/config"
88
"github.com/landlock-lsm/go-landlock/landlock"
9+
10+
ll "github.com/landlock-lsm/go-landlock/landlock/syscall"
911
)
1012

1113
var (
1214
rules []landlock.Rule
15+
16+
// Include file truncation
17+
truncFile landlock.AccessFSSet = ll.AccessFSExecute | ll.AccessFSWriteFile | ll.AccessFSReadFile | ll.AccessFSTruncate
1318
)
1419

20+
func TruncFile(p string) landlock.FSRule {
21+
return landlock.PathAccess(truncFile, p)
22+
}
23+
1524
func LandlockRulesFromConfig(conf *config.Config) {
1625
rules = append(rules,
1726
landlock.RODirs(

0 commit comments

Comments
 (0)