-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
[Feat] Unbound: Support per-rule (local-zone) ipset targets #1162
Open
EngineersBox
wants to merge
24
commits into
NLnetLabs:master
Choose a base branch
from
EngineersBox:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EngineersBox
changed the title
Support per-rule (local-zone) ipset targets
[Feat] Unbound: Support per-rule (local-zone) ipset targets
Nov 1, 2024
EngineersBox
commented
Nov 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In the existing workflow and configuration, Unbound requires an ipset to be specified globally and referenced where necessary in each
local-zone
declaration.This is very limiting as it does not allow delineation of domains operating in different contexts, i.e. utilising ipsets for each port or protocol.
Having all rules bundled into a single ipset implies uniformity in access (egress/ingress) when bound to an ipset, potentially causing unwanted firewall access for domains over ports/interfaces/etc that are not desired.
For example, using the follwing config to populate an ipset for two domains where
https_example.com
operates over https port 443 andamqp_domain.net
operates over 5431:Causes issues when trying to create matching iptables rules to allow to distinct ports on each domain:
As both
https_example.com
andamqp_domain.amqp
will be allowed on port 443 and 5431.Changes
This PR does the following:
The new
local-zone
declaration format is:lcoal-zone: <domain> ipset [<protocol> <set name> <ttl | no-ttl>]
.The last parameters are still optional, should the user still be using the global ipset declaration.
Global declarations will be translated into per-rule definitions internally for simplicity, but have no difference in their behaviour.
The
protocol
field is designed for network layer protocols (i.e. ipv4/ipv6/arpa/etc), it only supportsipv4
andipv6
values currently inline with the existing supported protocols, appropriately logging an error when encountering an invalid value.Example Configuration
An example config in this new setup is:
Would allow for an iptables setup as follows, ensuring no overlap between the rules.
Notes
There are a few things to note, obviously this needs to have Unbound build with ipset support via
--enable-ipset
and the apparmor profile modified to include theCAP_NET_ADMIN
permission as well (necessitated by netlink framework).These changes would need to be included in the Debian package distribution and also potentially some refactor to allow the apparmor profile to be conditionally modified to include the capability when the USE_IPSET env var is detected from the
configure
script (I will raise a separate issue to deal with this as it is a more general problem to be solved with the Debian package).In a BSD distribution, compiled with the packet filter framework, there is no support for TTLs to be set on individual table entries. The only support that pf provides is invoking manual expiry of table entries past a delta of
n
seconds via thepfctl -t <table> -T expire <seconds>
flag (https://man.openbsd.org/pfctl#T~3).Thus no support is added there for TTLs and a suitable warning is raised from the parser when the config is checked.
TODO [Done]
There are a few things I'd like to do before this is moved out of draft and into a fully reviewable state: