Skip to content
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

Add authoritative zone handling #117

Closed
wants to merge 1 commit into from
Closed

Conversation

karolyi
Copy link

@karolyi karolyi commented Jan 14, 2024

Hey,

so this would address #116.

I've changed using getopts to getopt that allows for long option parameters (see the commented out lines as to why). I don't use it right now but the time may come so why not put it in ahead of time. Also I fixed a startup error.

The way it works is, when you mount the /etc/dnscrypt-server/auth-zones directory, it gets picked up by the startup script and generate a different configuration in terms of what interfaces to listen on, and what queries to answer to, depending on where they arrive from.

I've tested this variant on my local VM, seems to be working.

Documentation is still missing; this is just a WIP version. Add your input if you'd like, but to my taste this is already good enough to go. If nothing else, I'll add the documentation part, and then you can merge (and hopefully release ASAP).

@karolyi karolyi force-pushed the master branch 3 times, most recently from df251b4 to 38178cc Compare January 14, 2024 18:13
Copy link
Member

@jedisct1 jedisct1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no documentation nor example, so I'm not sure if the intent is the same, but looking at the diff, it seems to address the same thing as something already documented.

The difference seems that the unbound instance can be set to listen to 0.0.0.0:553 and [::]:553.

So, maybe we should just introduce a flag that allows additional ip:port to be listened to? That can be useful if people want to expose an unencrypted DNS server on the regular port 53 as well.

Comment on lines +21 to +23
# --- FOR TESTING ---
# RUN apt-get update && apt-get install -y iproute2 less vim

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover from local testing?

Dockerfile Outdated
@@ -64,6 +67,8 @@ RUN mkdir -p \
COPY encrypted-dns.toml.in /opt/encrypted-dns/etc/
COPY undelegated.txt /opt/encrypted-dns/etc/

RUN chmod a+r /opt/encrypted-dns/etc/undelegated.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?


init() {
if [ "$(is_initialized)" = yes ]; then
start
exit $?
fi

# TEMP=$(getopt --name "${SCRIPTNAME}" --options 'h?N:E:T:AM:' --longoptions 'unbound-on-all-interfaces' -- "$@")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

anondns_enabled="false"
anondns_blacklisted_ips=""

metrics_address="127.0.0.1:9100"

while getopts "h?N:E:T:AM:" opt; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite scared by changing getopts to getopt. If the behavior is not exactly the same as before, it will break severs from everybody running watchtower to automatically keep their containers up to date.

@@ -2,6 +2,36 @@

KEYS_DIR="/opt/encrypted-dns/etc/keys"
ZONES_DIR="/opt/unbound/etc/unbound/zones"
AUTHZONES_DIR="/opt/unbound/etc/unbound/auth-zones"

OIFS="${IFS}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is IFS saved since it's not changed anywhere?

@karolyi
Copy link
Author

karolyi commented Jan 14, 2024

The documented part is for local-zones directives, that is very different from authoritative zones (auth-zone). They're not even handled on the same configuration level. I saw it from the get-go but unfortunately it's not what I need, as the server should be able to act authoritative for zones it gets IXFR/AXFR-ed.

getopt is available at every POSIX platforms, that includes linux, macos and freebsd (my choice). the parsing is basically the same thing implemented in getopt, as you can see from the diff.

The chmod was necessary because that file it chmods, wasn't readable to the user it needed for some reason. It is put with that permission into the git repo as well, so I did the change.

The leftovers are for documentation and testing purposes, just ignore them, don't be too picky about them.

IFS is changed so multi-line configuration snippets aren't parsed as arrays. As you can see, when the setup is done, IFS is changed back.

@karolyi
Copy link
Author

karolyi commented Jan 14, 2024

Interesting, I thought I defined an empty IFS which I didn't. At some point I got errors because they were parsed as arrays. I'm too tired for today (was working today the entire day on this) but I'll check tomorrow if that OIFS/IFS can be removed.

On second thought, that could've been because I was testing restarting the service from within the container, where the default IFS can be different. I'll test tomorrow.

@jedisct1
Copy link
Member

But couldn't auth-zone lines be added to files in /etc/dnscrypt-server/zones, just like local-zone?

@karolyi
Copy link
Author

karolyi commented Jan 14, 2024

But couldn't auth-zone lines be added to files in /etc/dnscrypt-server/zones, just like local-zone?

Not that I know of. local-zone belongs to under server: whereas auth-zones are their own levels. See https://unbound.docs.nlnetlabs.nl/en/latest/manpages/unbound.conf.html#authority-zone-options and https://github.com/NLnetLabs/unbound/blob/master/doc/example.conf.in

@karolyi karolyi force-pushed the master branch 2 times, most recently from 554ae6e to 3effd2d Compare January 15, 2024 17:48
@karolyi
Copy link
Author

karolyi commented Jan 15, 2024

Okay, so did a test now. I can't recall for what reason, but sometimes the IFS value was making my modification with the multi-line string behave as an array, so just to be sure, I've added setting/resetting its value before setting the proper variables.

If you agree this is acceptable, I'll make the documentation changes in hopes of a timely merge and release.

@karolyi
Copy link
Author

karolyi commented Jan 22, 2024

Hey,

I'm abandoning this PR. It turned out that unbound is unable to transfer zones with using TSIG signatures and so the only method is to restrict by IP that is insecure: IPs can be faked by a powerful enough adversary.

Feel free to integrate or close this PR.

@DNSCrypt DNSCrypt deleted a comment from Radek38 Oct 26, 2024
@jedisct1 jedisct1 closed this Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants