[client] Use native firewall for peer ACLs in userspace WireGuard mode#5668
[client] Use native firewall for peer ACLs in userspace WireGuard mode#5668
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Changes
Sequence DiagramsequenceDiagram
participant Caller
participant Env as Environment (NB_FORCE_USERSPACE_FIREWALL)
participant Iface as iface (bind mode)
participant Native as NativeFirewall
participant Userspace as UserspaceFirewall
Caller->>Iface: request firewall creation
Iface-->>Caller: reports bind mode (userspace or kernel)
alt Interface userspace
Caller->>Env: read NB_FORCE_USERSPACE_FIREWALL
Env-->>Caller: flag value
alt Flag true
Caller->>Userspace: create userspace (native = nil)
Userspace-->>Caller: return userspace instance
else Flag false
Caller->>Native: attempt create native
alt Native creation fails
Native-->>Caller: error
Caller->>Userspace: create userspace (fallback)
Userspace-->>Caller: return userspace instance
else Native creation succeeds
Native-->>Caller: return native instance
end
end
else Interface kernel
Caller->>Native: create native (no fallback)
Native-->>Caller: return result/error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@client/firewall/create_linux.go`:
- Around line 45-59: When createNativeFirewall(iface, ...) succeeds in userspace
bind mode (iface.IsUserspaceBind() true and err == nil) you must call the
firewall's AllowNetbird() initialization before returning; update the successful
native path (the fm returned from createNativeFirewall) to call
fm.AllowNetbird(), handle and return any error from that call (or log and
propagate) just like the userspace path does, so iptables/nftables
implementations are initialized consistently; keep the existing fallback
behavior for err != nil unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 32fe975d-d2d8-4481-8dd3-9c5c9cd3822a
📒 Files selected for processing (2)
client/firewall/create_linux.goclient/firewall/iface.go
✅ Files skipped from review due to trivial changes (1)
- client/firewall/iface.go
|



Describe your changes
When WireGuard runs in userspace mode, peer ACLs were handled by USPFilter while route ACLs used nftables/iptables. This desync meant Docker containers with published ports (bridge mode, DNAT) could not be reached even when allowed by policy, because the nftables mangle prerouting marks were never set for peer ACL rules.
NB_FORCE_USERSPACE_FIREWALLenv var to force USPFilter for peer ACLs (skips native firewall entirely)To run with no kernel netfilter rules at all, all three env vars are needed:
Issue ticket number and link
Checklist
Documentation
Select exactly one:
New env var is for internal testing/debugging only.
Summary by CodeRabbit
New Features
Improvements
Tests
Breaking Changes