-
Notifications
You must be signed in to change notification settings - Fork 870
unbound: merge extended blocklists into core (https://github.com/opnsense/core/issues/9136) #9301
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: master
Are you sure you want to change the base?
Conversation
src/opnsense/mvc/app/controllers/OPNsense/Unbound/forms/dnsbl.xml
Outdated
Show resolved
Hide resolved
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.
looks good on the surface
|
One thing to note here is that with many blocklists, the matching algorithm has quite a performance penalty due to the subnet coverage calculation. This doesn't necessarily have to be a problem, as it's properly locked and is only for pre-processing, but it's slower than before. |
0e8b7b5 to
db13acb
Compare
|
Just to ease review a bit, the data path is as follows:
|
part 1: simplify blocklist handling.
Introduce blocklists_iter() in BaseBlocklistHandler class which yields domain information per policy, which can then be reordered easily using the calculated priorities using source_nets in get_policies().
To prevent people from using overlapping nets or different protocol families in the same policy, we validate the input. Overlapping nets will lead to possible race conditions while matching as we cannot assume the first match found is actually the relevant one anymore.
Our output data should match the expected format below:
```
{
"data": {
"<domain>": [
{"idx": <index into the first logical policy it should check},
{"idx": ...}
...
],
},
"config": {
"<idx>": {
"passlist": <compiled passlist>,
"source_nets": [
"192.168.1.0/24",
...
]
...
}
}
}
```
This part only concers the parser with backwards compatibility (to keep QFeeds functional during the process)
In the blocklist.conf template we changed the sequence index to use UUID's, which basically does the same thing as the index number, but is slightly better to track (used in the dnsbl.json output file as well).
part 1: simplify blocklist handling.
Introduce blocklists_iter() in BaseBlocklistHandler class which yields domain information per policy, which can then be reordered easily using the calculated priorities using source_nets in get_policies().
To prevent people from using overlapping nets or different protocol families in the same policy, we validate the input. Overlapping nets will lead to possible race conditions while matching as we cannot assume the first match found is actually the relevant one anymore.
Our output data should match the expected format below:
```
{
"data": {
"<domain>": [
{"idx": <index into the first logical policy it should check},
{"idx": ...}
...
],
},
"config": {
"<idx>": {
"passlist": <compiled passlist>,
"source_nets": [
"192.168.1.0/24",
...
]
...
}
}
}
```
This part only concers the parser with backwards compatibility (to keep QFeeds functional during the process)
In the blocklist.conf template we changed the sequence index to use UUID's, which basically does the same thing as the index number, but is slightly better to track (used in the dnsbl.json output file as well).
12582c4 to
93f754e
Compare
Reorganize some parts so we can split this up more easily into separate components and fix one minor passlist regex issue.
Setup new unbound-dnsbl module which should replace dnsbl_module.py and tester (work in progress). In its current state this should contain all relevant classes and functions currently used in dnsbl_module.py with rudimentary unit tests.
move dnsbl_module into unbound-dnsbl directory and use library functions.
move dnsbl_module into unbound-dnsbl directory and use library functions.
12665a3 to
6c2f240
Compare
As getNodeContent() returns descriptive values as well (starting with %), there is no guarantee $bl->$key exists in the migration, check before calling applyDefault()
fix some scoping issues when dnsbl_module is used from unbound.
use /usr/local/opnsense/scripts/unbound-dnsbl/dnsbl_match.py for the tester.
…bnet coverage calculation
…ks in dynamic tooltips
part 1: simplify blocklist handling.
Introduce blocklists_iter() in BaseBlocklistHandler class which yields domain information per policy, which can then be reordered easily using the calculated priorities using source_nets in get_policies().
To prevent people from using overlapping nets or different protocol families in the same policy, we validate the input. Overlapping nets will lead to possible race conditions while matching as we cannot assume the first match found is actually the relevant one anymore.
Our output data should match the expected format below:
```
{
"data": {
"<domain>": [
{"idx": <index into the first logical policy it should check},
{"idx": ...}
...
],
},
"config": {
"<idx>": {
"passlist": <compiled passlist>,
"source_nets": [
"192.168.1.0/24",
...
]
...
}
}
}
```
This part only concers the parser with backwards compatibility (to keep QFeeds functional during the process)
In the blocklist.conf template we changed the sequence index to use UUID's, which basically does the same thing as the index number, but is slightly better to track (used in the dnsbl.json output file as well).
Reorganize some parts so we can split this up more easily into separate components and fix one minor passlist regex issue.
Setup new unbound-dnsbl module which should replace dnsbl_module.py and tester (work in progress). In its current state this should contain all relevant classes and functions currently used in dnsbl_module.py with rudimentary unit tests.
move dnsbl_module into unbound-dnsbl directory and use library functions.
As getNodeContent() returns descriptive values as well (starting with %), there is no guarantee $bl->$key exists in the migration, check before calling applyDefault()
fix some scoping issues when dnsbl_module is used from unbound.
use /usr/local/opnsense/scripts/unbound-dnsbl/dnsbl_match.py for the tester.
98a6670 to
a9114f0
Compare
|
My changes are in, but can use an extra pair of eyes on the current state. |
| foreach ($dirs as $dir) { | ||
| mwexecf('/bin/mkdir -p %s', "/var/unbound{$dir}"); | ||
| } | ||
| /* deploy python module (without test suite) */ |
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.
| /* deploy python module (without test suite) */ | |
| /* deploy python module (without test suite) */ |
| ); | ||
| if (count($sizes) > 1) { | ||
| $messages->appendMessage(new Message( | ||
| gettext("All offered networks should be equally sized to avoid overlaps"), |
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.
| gettext("All offered networks should be equally sized to avoid overlaps"), | |
| gettext('All offered networks should be equally sized to avoid overlaps.'), |
Mostly about missing dot in sentence.
| } | ||
| if (count($ipproto) > 1) { | ||
| $messages->appendMessage(new Message( | ||
| gettext("All offered networks should use the same IP protocol"), |
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.
| gettext("All offered networks should use the same IP protocol"), | |
| gettext('All offered networks should use the same IP protocol.'), |
|
Apart from the extra review, points of interest here are:
|
| foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basedir)) as $filename) { | ||
| $target = "/var/unbound/unbound-dnsbl/".substr($filename, strlen($basedir)); | ||
| if (str_ends_with($filename, '.py') && is_dir(dirname($target))) { | ||
| @copy($filename, $target); |
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.
I don't think we're making sure to clean /var/unbound/unbound-dnsbl so our future selves will be happy?
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.
looks ok, leaving the python parts for the other avid readers :)
TODO:
post()usage to clean up config.