Skip to content

Commit 0fa48f5

Browse files
blink-so[bot]f0ssel
andcommitted
Add detailed PF rules error debugging
- Capture and log pfctl command output on failure - Log the actual PF rules content for debugging - Helps diagnose PF rules syntax or permission issues - Should reveal why PF rules are failing to load Co-authored-by: f0ssel <[email protected]>
1 parent 1e335cc commit 0fa48f5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

namespace/macos.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,15 @@ func (m *MacOSNetJail) setupPFRules() error {
263263

264264
// Load rules into anchor
265265
cmd := exec.Command("pfctl", "-a", pfAnchorName, "-f", m.pfRulesPath)
266-
err = cmd.Run()
266+
output, err := cmd.CombinedOutput()
267267
if err != nil {
268-
return fmt.Errorf("failed to load PF rules: %v", err)
268+
m.logger.Error("Failed to load PF rules", "error", err, "output", string(output), "rules_file", m.pfRulesPath)
269+
// Also log the actual rules content for debugging
270+
rulesContent, readErr := os.ReadFile(m.pfRulesPath)
271+
if readErr == nil {
272+
m.logger.Debug("PF rules content", "rules", string(rulesContent))
273+
}
274+
return fmt.Errorf("failed to load PF rules: %v, output: %s", err, string(output))
269275
}
270276

271277
// Enable PF if not already enabled
@@ -303,7 +309,7 @@ anchor "%s"
303309

304310
// Verify that rules were loaded correctly
305311
cmd = exec.Command("pfctl", "-a", pfAnchorName, "-s", "rules")
306-
output, err := cmd.Output()
312+
output, err = cmd.Output()
307313
if err == nil && len(output) > 0 {
308314
// Rules loaded successfully
309315
return nil

0 commit comments

Comments
 (0)