[client] Drop traffic a peer ACL drop denies in prerouting, before DNAT diverts it to the forward path

Merged
LI
16d ago
+270-20

Describe your changes

Each peer ACL rule gets a paired prerouting mangle rule that marks traffic the forward chain should treat as accepted by the input ACL, so published container ports (Docker, Podman) still go through peer ACL enforcement after DNAT moves them from the input path to the forward path. That pairing was built from the rule's match only, not its action, so a drop rule's counterpart set the same accept mark as an overlapping accept rule's counterpart, and a drop-only policy opened the port the default deny would otherwise close.

  • In both the nftables and iptables backends, a drop rule's counterpart now drops new traffic in prerouting, before DNAT, instead of setting the mark. Leaving it unmarked is not enough: on the forward path an overlapping route ACL could still accept it. Established and related packets are exempt, as the input chain accepts them ahead of its drops
  • Drop counterparts are inserted ahead of accept counterparts, mirroring the drop-before-accept order of the input chain
  • On iptables, a failed drop counterpart now fails the whole rule instead of being best-effort, since the deny does not hold on the forward path without it
  • Add regression coverage for both backends

Issue ticket number and link

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)
  • I ran and tested this change locally — I did not rely on CI to find out whether it works
  • This PR has a single purpose (not a fix + refactor + feature in one)
  • This change is a trivial fix, OR it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. See CONTRIBUTING.md.

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)

Internal change with no user-facing flag or documented behavior change.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected Linux firewall handling of deny rules: matching new traffic is dropped before it can be redirected, while related and established connections remain exempt.
    • Deny rules now take precedence over corresponding allow rules, preventing denied traffic from receiving the allow rule’s redirection behavior.