-
-
Notifications
You must be signed in to change notification settings - Fork 812
[client] Fix rule order for deny rules in peer ACLs #4147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that deny (drop) rules in peer ACLs are evaluated before allow rules by introducing a separate deny rules map and adjusting insertion order across components.
- Added
incomingDenyRules
alongsideincomingRules
and updated all filtering, add/delete, and hook logic to use the correct map based on rule action. - Changed
peerACLsBlock
signature and call sites to swap the decoder and packet parameters. - Updated tests and native firewall (nftables/iptables) managers to insert drop rules at the beginning and added new tests for deny-rule precedence.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
client/firewall/uspfilter/filter.go | Introduced incomingDenyRules , split add/delete logic by action |
client/firewall/uspfilter/tracer.go | Updated peerACLsBlock calls to match new signature |
client/firewall/uspfilter/filter_test.go | Extended tests to verify rules in deny vs allow maps |
client/firewall/uspfilter/filter_filter_test.go | Added test cases for drop-over-accept precedence and updated general accept rule setup |
client/firewall/uspfilter/allow_netbird*.go | Reset incomingDenyRules on Close |
client/firewall/nftables/manager_linux_test.go | Insert DROP rules first in tests; added rule-order test |
client/firewall/iptables/manager_linux_test.go | Added deny-rule precedence tests in iptables manager |
client/firewall/iptables/acl_linux.go | Insert DROP rules at position 1; updated ipset naming to include action |
Comments suppressed due to low confidence (4)
client/firewall/iptables/acl_linux.go:85
- [nitpick] The
transformIPsetName
signature now includes theaction
parameter but the function lacks an updated doc comment. Adding a comment explaining the new parameter and its effect on the resulting ipset name will aid future maintainers.
) ([]firewall.Rule, error) {
client/firewall/uspfilter/filter.go:1017
- [nitpick] This
return nil, true
represents the default "drop all" policy inpeerACLsBlock
but no comment explains why. Restoring or adding a clarifying comment will make the intended default behavior explicit.
return nil, true
client/firewall/nftables/manager_linux_test.go:5
- [nitpick] The import of
encoding/binary
is interleaved with other standard libraries, which breaks the project's import grouping. Move it into the main standard-library block to match the established style.
"encoding/binary"
client/firewall/uspfilter/filter_filter_test.go:498
- [nitpick] Tests use
net.ParseIP
for rule IPs while production code usesnetip.Addr
. Consider switching tonetip.ParseAddr
in tests for consistency and to reflect the actual API surface.
rules, err := manager.AddPeerFiltering(
var targetMap map[netip.Addr]RuleSet | ||
if r.drop { | ||
targetMap = m.incomingDenyRules | ||
} else { | ||
targetMap = m.incomingRules | ||
} | ||
|
||
if _, ok := targetMap[r.ip]; !ok { | ||
targetMap[r.ip] = make(RuleSet) | ||
} | ||
m.incomingRules[r.ip][r.id] = r | ||
targetMap[r.ip][r.id] = r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using a local targetMap
to select between incomingRules
and incomingDenyRules
can obscure which global map is being mutated. Consider directly manipulating m.incomingRules
or m.incomingDenyRules
in their respective branches for clearer intent.
Copilot uses AI. Check for mistakes.
|
Describe your changes
Rule order in peer ACLs was random, this PR makes deny rules always come first, just like with route ACLs
Issue ticket number and link
Stack
Checklist