Skip to content

Commit 3925d67

Browse files
authored
fix: add user-configured allowRead paths to Landlock ruleset (#8)
ApplyLandlockFromConfig was not processing cfg.Filesystem.AllowRead paths, causing them to be blocked by Landlock despite bwrap mounting them correctly as read-only. This made files like ~/.gitconfig inaccessible inside the sandbox when using DefaultDenyRead mode. Closes #6
1 parent a953aba commit 3925d67

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/sandbox/linux_landlock.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ func ApplyLandlockFromConfig(cfg *config.Config, cwd string, socketPaths []strin
152152
}
153153
}
154154

155+
// User-configured allowRead paths
156+
if cfg != nil && cfg.Filesystem.AllowRead != nil {
157+
expandedPaths := ExpandGlobPatterns(cfg.Filesystem.AllowRead)
158+
for _, p := range expandedPaths {
159+
if err := ruleset.AllowRead(p); err != nil && debug {
160+
fmt.Fprintf(os.Stderr, "[greywall:landlock] Warning: failed to add read path %s: %v\n", p, err)
161+
}
162+
}
163+
// Also add non-glob paths directly
164+
for _, p := range cfg.Filesystem.AllowRead {
165+
if !ContainsGlobChars(p) {
166+
normalized := NormalizePath(p)
167+
if err := ruleset.AllowRead(normalized); err != nil && debug {
168+
fmt.Fprintf(os.Stderr, "[greywall:landlock] Warning: failed to add read path %s: %v\n", normalized, err)
169+
}
170+
}
171+
}
172+
}
173+
155174
// User-configured allowWrite paths
156175
if cfg != nil && cfg.Filesystem.AllowWrite != nil {
157176
expandedPaths := ExpandGlobPatterns(cfg.Filesystem.AllowWrite)

0 commit comments

Comments
 (0)