Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions internal/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,24 @@ func Apply(cfg Config) error {
return nil
}

// Apply all rules at once
// Apply all rules in a single Restrict() call.
// Using separate RestrictPaths() and RestrictNet() calls creates two
// Landlock rulesets. RestrictNet() clears handledAccessFS, and since
// REFER is "always denied by default when not in handled_access_fs"
// (per kernel docs), the second ruleset would implicitly deny REFER.
// Using Restrict() with combined rules avoids this issue.
log.Debug("Applying Landlock restrictions")
var allRules []landlock.Rule
if !cfg.UnrestrictedFilesystem {
err := llCfg.RestrictPaths(file_rules...)
if err != nil {
return fmt.Errorf("failed to apply Landlock filesystem restrictions: %w", err)
}
allRules = append(allRules, file_rules...)
}
if !cfg.UnrestrictedNetwork {
err := llCfg.RestrictNet(net_rules...)
allRules = append(allRules, net_rules...)
}
if len(allRules) > 0 {
err := llCfg.Restrict(allRules...)
if err != nil {
return fmt.Errorf("failed to apply Landlock network restrictions: %w", err)
return fmt.Errorf("failed to apply Landlock restrictions: %w", err)
}
}

Expand Down