[PR #5668] [MERGED] [client] Use native firewall for peer ACLs in userspace WireGuard mode #28321

Closed
opened 2026-08-05 08:06:10 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5668
Author: @lixmal
Created: 3/23/2026
Status: Merged
Merged: 4/9/2026
Merged by: @lixmal

Base: mainHead: fix/userspace-native-firewall


📝 Commits (4)

  • 25a5b3e Use native firewall for peer ACLs in userspace WireGuard mode
  • 9f41367 Set NB_FORCE_USERSPACE_FIREWALL in ACL manager tests
  • 0adec63 Move EnvForceUserspaceFirewall to platform-independent file
  • 4d75797 Merge remote-tracking branch 'origin/main' into fix/userspace-native-firewall

📊 Changes

9 files changed (+58 additions, -45 deletions)

View changed files

📝 client/firewall/create_linux.go (+27 -5)
📝 client/firewall/iface.go (+6 -0)
📝 client/firewall/iptables/manager_linux.go (+6 -10)
📝 client/firewall/iptables/manager_linux_test.go (+0 -2)
📝 client/firewall/iptables/state_linux.go (+3 -8)
📝 client/firewall/nftables/manager_linux.go (+6 -10)
📝 client/firewall/nftables/manager_linux_test.go (+0 -2)
📝 client/firewall/nftables/state_linux.go (+3 -8)
📝 client/internal/acl/manager_test.go (+7 -0)

📄 Description

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.

  • Use native nftables/iptables for peer ACLs in userspace mode when available (the TUN interface is identical from netfilter's perspective)
  • Fall back to USPFilter when native firewall is unavailable
  • Add NB_FORCE_USERSPACE_FIREWALL env 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:

NB_WG_KERNEL_DISABLED=true
NB_FORCE_USERSPACE_FIREWALL=true
NB_FORCE_USERSPACE_ROUTER=true

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

New env var is for internal testing/debugging only.

Summary by CodeRabbit

  • New Features

    • Added NB_FORCE_USERSPACE_FIREWALL environment variable to force userspace firewall mode.
  • Improvements

    • Initialization prefers userspace when forced and falls back to userspace if native setup fails.
    • Peer-filtering/allow rules are applied consistently across firewall backends.
  • Tests

    • Tests updated to exercise forced userspace firewall behavior.
  • Breaking Changes

    • Userspace-bind state is no longer persisted or exposed in shutdown state.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5668 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 3/23/2026 **Status:** ✅ Merged **Merged:** 4/9/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `fix/userspace-native-firewall` --- ### 📝 Commits (4) - [`25a5b3e`](https://github.com/netbirdio/netbird/commit/25a5b3ea1a9eedea54de462e211079461ef38143) Use native firewall for peer ACLs in userspace WireGuard mode - [`9f41367`](https://github.com/netbirdio/netbird/commit/9f41367f5d5680bcb1b282f5bb6141f04480d9d1) Set NB_FORCE_USERSPACE_FIREWALL in ACL manager tests - [`0adec63`](https://github.com/netbirdio/netbird/commit/0adec637fcdf1d4e8b44d0e70b38e9333e1fd1d2) Move EnvForceUserspaceFirewall to platform-independent file - [`4d75797`](https://github.com/netbirdio/netbird/commit/4d75797f39402f6853838ba1baadb60e629181ea) Merge remote-tracking branch 'origin/main' into fix/userspace-native-firewall ### 📊 Changes **9 files changed** (+58 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `client/firewall/create_linux.go` (+27 -5) 📝 `client/firewall/iface.go` (+6 -0) 📝 `client/firewall/iptables/manager_linux.go` (+6 -10) 📝 `client/firewall/iptables/manager_linux_test.go` (+0 -2) 📝 `client/firewall/iptables/state_linux.go` (+3 -8) 📝 `client/firewall/nftables/manager_linux.go` (+6 -10) 📝 `client/firewall/nftables/manager_linux_test.go` (+0 -2) 📝 `client/firewall/nftables/state_linux.go` (+3 -8) 📝 `client/internal/acl/manager_test.go` (+7 -0) </details> ### 📄 Description ## 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. - Use native nftables/iptables for peer ACLs in userspace mode when available (the TUN interface is identical from netfilter's perspective) - Fall back to USPFilter when native firewall is unavailable - Add `NB_FORCE_USERSPACE_FIREWALL` env 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: ``` NB_WG_KERNEL_DISABLED=true NB_FORCE_USERSPACE_FIREWALL=true NB_FORCE_USERSPACE_ROUTER=true ``` ## Issue ticket number and link ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) New env var is for internal testing/debugging only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added NB_FORCE_USERSPACE_FIREWALL environment variable to force userspace firewall mode. * **Improvements** * Initialization prefers userspace when forced and falls back to userspace if native setup fails. * Peer-filtering/allow rules are applied consistently across firewall backends. * **Tests** * Tests updated to exercise forced userspace firewall behavior. * **Breaking Changes** * Userspace-bind state is no longer persisted or exposed in shutdown state. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 08:06:10 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#28321