[PR #6802] [client] Preserve firewall authorization in connection marks #27125

Open
opened 2026-08-05 07:08:14 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6802
Author: @CoderSufiyan
Created: 7/16/2026
Status: 🔄 Open

Base: mainHead: fix/issue-6022-forward-mark


📝 Commits (2)

  • 30dfab4 [client] Preserve firewall authorization in connection marks
  • 1cccd29 [client] Match route NAT on connection marks

📊 Changes

9 files changed (+135 additions, -28 deletions)

View changed files

📝 client/firewall/iptables/acl_linux.go (+4 -3)
client/firewall/iptables/acl_linux_test.go (+35 -0)
📝 client/firewall/iptables/router_linux.go (+6 -7)
📝 client/firewall/iptables/router_linux_test.go (+14 -4)
📝 client/firewall/nftables/acl_linux.go (+4 -6)
📝 client/firewall/nftables/router_linux.go (+6 -6)
📝 client/firewall/nftables/router_linux_test.go (+52 -0)
📝 client/internal/netflow/conntrack/conntrack.go (+2 -2)
📝 client/internal/netflow/conntrack/conntrack_test.go (+12 -0)

📄 Description

Describe your changes

Persist NetBird firewall authorization and routed-network marks in conntrack instead of relying on mutable per-packet marks. The DNAT guard now checks connection marks, so kube-router, kube-proxy, and other netfilter consumers can modify packet marks without causing authorized traffic to be dropped.

Both iptables and nftables backends are updated. Routed marks remain classified correctly by netflow.

Fixes #6022

Stack

  • This PR is independent

Checklist

  • I have performed a self-review of my own code
  • I have tested the changes locally
  • I have added or updated tests where applicable
  • I have checked for breaking changes

Documentation

  • Documentation is not needed

Validation

  • Cross-compiled Linux test binaries for ./client/firewall/iptables
  • Cross-compiled Linux test binaries for ./client/firewall/nftables
  • Cross-compiled Linux test binaries for ./client/internal/netflow/conntrack
  • git diff --check

Runtime netfilter tests require a Linux environment.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Improved firewall rule behavior for redirected, masqueraded, and return traffic by switching NAT/ACL handling to use connection (conntrack) marks consistently.
    • Strengthened DNAT guard logic to drop incorrectly marked redirected traffic.
    • Improved NetFlow direction detection for firewall-managed connections based on these connection marks.
  • Tests
    • Added/updated Linux-focused tests to verify connection-mark-based rule generation and NAT matching/cleanup behavior.

🔄 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/6802 **Author:** [@CoderSufiyan](https://github.com/CoderSufiyan) **Created:** 7/16/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/issue-6022-forward-mark` --- ### 📝 Commits (2) - [`30dfab4`](https://github.com/netbirdio/netbird/commit/30dfab4a1307aef424ea6afa0b50e27bd6d3f4a2) [client] Preserve firewall authorization in connection marks - [`1cccd29`](https://github.com/netbirdio/netbird/commit/1cccd298035ef6b5149a6072f474eb1fe1288089) [client] Match route NAT on connection marks ### 📊 Changes **9 files changed** (+135 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `client/firewall/iptables/acl_linux.go` (+4 -3) ➕ `client/firewall/iptables/acl_linux_test.go` (+35 -0) 📝 `client/firewall/iptables/router_linux.go` (+6 -7) 📝 `client/firewall/iptables/router_linux_test.go` (+14 -4) 📝 `client/firewall/nftables/acl_linux.go` (+4 -6) 📝 `client/firewall/nftables/router_linux.go` (+6 -6) 📝 `client/firewall/nftables/router_linux_test.go` (+52 -0) 📝 `client/internal/netflow/conntrack/conntrack.go` (+2 -2) 📝 `client/internal/netflow/conntrack/conntrack_test.go` (+12 -0) </details> ### 📄 Description ## Describe your changes Persist NetBird firewall authorization and routed-network marks in conntrack instead of relying on mutable per-packet marks. The DNAT guard now checks connection marks, so kube-router, kube-proxy, and other netfilter consumers can modify packet marks without causing authorized traffic to be dropped. Both iptables and nftables backends are updated. Routed marks remain classified correctly by netflow. ## Issue ticket number and link Fixes #6022 ## Stack - [x] This PR is independent ## Checklist - [x] I have performed a self-review of my own code - [x] I have tested the changes locally - [x] I have added or updated tests where applicable - [x] I have checked for breaking changes ## Documentation - [x] Documentation is **not needed** ## Validation - Cross-compiled Linux test binaries for `./client/firewall/iptables` - Cross-compiled Linux test binaries for `./client/firewall/nftables` - Cross-compiled Linux test binaries for `./client/internal/netflow/conntrack` - `git diff --check` Runtime netfilter tests require a Linux environment. <!-- codesmith:footer --> --- <a href="https://app.blacksmith.sh/netbirdio/codesmith/netbird/pr/6802"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-light-v2.svg"><img alt="View with Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"></picture></a> <a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1786808434&installation_id=146802194&pr_number=6802&repository=netbirdio%2Fnetbird&return_to=https%3A%2F%2Fgithub.com%2Fnetbirdio%2Fnetbird%2Fpull%2F6802&signature=9712e419e1e17cb5d6a34ad77c961ff3629293f35137fc42a143fa54931b1fa6"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img alt="Autofix with Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"></picture></a> <sup>Need help on this PR? Tag <code>/codesmith</code> with what you need. Autofix is disabled.</sup> <!-- codesmith:autofix:disabled --> <!-- /codesmith:footer --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved firewall rule behavior for redirected, masqueraded, and return traffic by switching NAT/ACL handling to use connection (conntrack) marks consistently. * Strengthened DNAT guard logic to drop incorrectly marked redirected traffic. * Improved NetFlow direction detection for firewall-managed connections based on these connection marks. * **Tests** * Added/updated Linux-focused tests to verify connection-mark-based rule generation and NAT matching/cleanup behavior. <!-- 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 07:08:14 -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#27125