[PR #5697] [MERGED] [client] Guard against container DNAT bypass of ACL rules in iptables #23670

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5697
Author: @lixmal
Created: 3/25/2026
Status: Merged
Merged: 4/16/2026
Merged by: @lixmal

Base: mainHead: iptables-mangle-dnat-guard


📝 Commits (2)

  • 3eac55a Add mangle FORWARD guard to prevent Docker DNAT bypass of ACL rules
  • b2d5ac9 Merge remote-tracking branch 'origin/main' into iptables-mangle-dnat-guard

📊 Changes

1 file changed (+37 additions, -0 deletions)

View changed files

📝 client/firewall/iptables/acl_linux.go (+37 -0)

📄 Description

Describe your changes

When container runtimes (Docker, Podman) publish ports, they DNAT traffic in nat PREROUTING, causing it to traverse the FORWARD chain instead of INPUT. If the container runtime starts after NetBird, its ACCEPT rules in filter FORWARD are inserted above NetBird's rules, bypassing ACL port restrictions.

  • Add two guard rules in mangle FORWARD that enforce the ACL mark check for DNAT'd traffic from the WireGuard interface
  • Mangle table runs before filter, so container runtimes cannot override the verdict regardless of rule insertion order
  • Uses --ctstate DNAT to scope the guard to only DNAT'd traffic, leaving regular route-forwarded traffic unaffected
  • Rules are persisted in shutdown state for proper cleanup

Native nftables is not affected since it uses separate tables with independent chain priorities.

Stack

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)

No user-facing behavior change. The fix is internal to the iptables firewall manager.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved firewall forwarding chain management for better connection tracking and traffic handling.
    • Enhanced security enforcement to prevent external traffic from circumventing ACL checks.

🔄 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/5697 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 3/25/2026 **Status:** ✅ Merged **Merged:** 4/16/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `iptables-mangle-dnat-guard` --- ### 📝 Commits (2) - [`3eac55a`](https://github.com/netbirdio/netbird/commit/3eac55ac0b301ebe5c5bf183bce722c8f942a7d0) Add mangle FORWARD guard to prevent Docker DNAT bypass of ACL rules - [`b2d5ac9`](https://github.com/netbirdio/netbird/commit/b2d5ac90c2a9f0316b097bb4ccea770922a332eb) Merge remote-tracking branch 'origin/main' into iptables-mangle-dnat-guard ### 📊 Changes **1 file changed** (+37 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `client/firewall/iptables/acl_linux.go` (+37 -0) </details> ### 📄 Description ## Describe your changes When container runtimes (Docker, Podman) publish ports, they DNAT traffic in nat PREROUTING, causing it to traverse the FORWARD chain instead of INPUT. If the container runtime starts after NetBird, its ACCEPT rules in filter FORWARD are inserted above NetBird's rules, bypassing ACL port restrictions. - Add two guard rules in mangle FORWARD that enforce the ACL mark check for DNAT'd traffic from the WireGuard interface - Mangle table runs before filter, so container runtimes cannot override the verdict regardless of rule insertion order - Uses `--ctstate DNAT` to scope the guard to only DNAT'd traffic, leaving regular route-forwarded traffic unaffected - Rules are persisted in shutdown state for proper cleanup Native nftables is not affected since it uses separate tables with independent chain priorities. ## Issue ticket number and link ## Stack <!-- branch-stack --> ### 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) No user-facing behavior change. The fix is internal to the iptables firewall manager. ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Improved firewall forwarding chain management for better connection tracking and traffic handling. * Enhanced security enforcement to prevent external traffic from circumventing ACL checks. <!-- 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 06:07:39 -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#23670