names: Use systemd-resolved for DNS resolution

- Disable mDNS resolution. While we can migrate our DNS-SD service definition
files to systemd-resolved and switch from using avahi to systemd-resolved, many
programs still solely depend on avahi-daemon. Examples include cups and GNOME.
It is not clear if they will work any mDNS daemon or if they interact with
avahi-daemon in other ways that the mDNS protocol. So, for now, disable mDNS in
systemd-resolved and continue to use avahi-daemon for it. This is also Fedora's
default.

- Re-introduce Fallback DNS servers with the value same as the upstream systemd
project. Debian removes the default fallback DNS servers likely because they
could be considered a privacy violation. However, when systemd-resolved package
is first installed, the post install script recommends a reboot instead of
feeding the currently configured nameservers from /etc/resolve.conf into
systemd-resolved. Immediately, this causes the system not be able to connect to
any external servers. While this may be acceptable solution for interactive
systems and pre-built images, FreedomBox has to a) be available for remote
access b) perform upgrades without user intervention (and without reboot until a
day). To mitigate privacy concerns, an option to disable these fallback servers
will be provided in the UI.

- systemd-resolved's stub resolver runs on 127.0.0.53%lo:53 and 127.0.0.54. This
does not conflict either with shared connections which listen on 10.42.x.1 or
with bind which listens on 127.0.0.1 (and other IP addresses). This MR does not
address the existing conflict between bind and shared network connections.
However, it does not cause any further conflicts.

Tests:

* mDNS

- Avahi diagnostics works. daemon is running. mdns port is exposed in the
firewall.

- systemd-resolved does not listen on mDNS ports.

- Running avahi-browse shows freedombox on local network.

- Running avahi-browse shows the services ssh, sftp-ssh, http and ejabberd.

- Machine can be discovered in Gnome Files.

* NetworkManager shared connections

- After install/upgrade to systemd-resolved, 'shared' connections can be
created.

- With a 'shared' connection configured and active, it is possible to upgrade to
using systemd-resolved.

- Resolving domains from a machine on shared network goes via systemd-resolved
on FreedomBox.

* Bind

- Installing, running tests on bind works.

- Programs connecting from outside network can connect to bind as expected.

- Programs connecting from local machine can connect to bind as expected.

* Upgrading works

- Upgrading to new FreedomBox package works

- systemd-resolved is installed and running. 'resolvectl' shows a proper name
server (or fallback nameserver like 1.1.1.1).

- libnss-resolve is installed and configured in /etc/nsswitch.conf

- /etc/resolv.conf has proper link to /run/systemd/resolve/stub-resolv.conf.

- Programs using /etc/resolv.conf directly work. Install python3-pycares.
python3 -m pycares freedombox.org.

- NetworkManager has passed on proper DNS entries. In logs dns=systemd-resolved,
rc-manager=unmanaged, plugin=systemd-resolved

- DNS resolution works after first setup. Installing packages works.

- 'resolvectl query' resolution works.

- Programs using glibc API resolution such as 'ping' work.

* Fresh image

- Building an image with new freedombox package works without error.

- Booting from fresh images works.

- systemd-resolved is installed and running. 'resolvectl' show proper name
server.

- libnss-resolve is installed and configured in /etc/nsswitch.conf

- /etc/resolv.conf has proper link to /run/systemd/resolve/stub-resolv.conf

- Programs using /etc/resolv.conf directly work. Install python3-pycares.
python3 -m pycares wikipedia.org

- NetworkManager has passed on proper DNS entries. In logs dns=systemd-resolved,
rc-manager=unmanaged, plugin=systemd-resolved

- DNS resolution works after first setup. Installing packages works.

* Installing package on Debian

- Installing new freedombox package in Debian machine works.

- systemd-resolved is installed and running.

- libnss-resolve is installed and configured.

- /etc/resolv.conf has proper link to /run

- NetworkManager has passed on proper DNS entries to systemd-resolved using
'nmcli reload dns-rc'.

- Resolution works with fallback DNS servers when network interfaces are
configured with /etc/network/interfaces

* OpenVPNs works

- As a server, we don't push DNS servers to the client. So, a client continues
to use its old DNS servers. With systemd-resolved running on server, the client
is able to connect to OpenVPN server, route traffic to the internet, and resolve
DNS queries.

* WireGuard works

- As a server, we can't push DNS servers to the client. So, a client continues
to use its old DNS servers. With systemd-resolved running on server, the client
is able to connect to WireGuard server, route traffic to the internet, and
resolve DNS queries.

- As a client, server does not push DNS servers to the client. So, a client
continues to use its old DNS servers. With systemd-resolved running on the
client, the client is able to connect to WireGuard server, route traffic to the
internet, and resolve DNS queries.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-08-21 18:59:09 -07:00 committed by Veiko Aasa
parent 51b919cc11
commit 0817e7af45
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
5 changed files with 74 additions and 4 deletions

2
debian/control vendored
View File

@ -178,8 +178,6 @@ Recommends:
powermgmt-base,
# fuser, pstree and other utilities
psmisc,
# Manage /etc/resolv.conf
resolvconf,
# Tool to kill WLAN, Bluetooth and moble broadband
rfkill,
# Monitor network traffic

View File

@ -9,11 +9,14 @@ from django.utils.translation import gettext_lazy as _
from plinth import app as app_module
from plinth import cfg, menu
from plinth.daemon import Daemon
from plinth.modules.backups.components import BackupRestore
from plinth.package import Packages
from plinth.privileged import service as service_privileged
from plinth.signals import domain_added, domain_removed
from plinth.utils import format_lazy
from . import components, manifest
from . import components, manifest, privileged
logger = logging.getLogger(__name__)
@ -32,7 +35,7 @@ class NamesApp(app_module.App):
app_id = 'names'
_version = 1
_version = 2
can_be_disabled = False
@ -50,6 +53,13 @@ class NamesApp(app_module.App):
parent_url_name='system:visibility', order=10)
self.add(menu_item)
packages = Packages('packages-names',
['systemd-resolved', 'libnss-resolve'])
self.add(packages)
daemon = Daemon('daemon-names', 'systemd-resolved')
self.add(daemon)
backup_restore = BackupRestore('backup-restore-names',
**manifest.backup)
self.add(backup_restore)
@ -63,6 +73,15 @@ class NamesApp(app_module.App):
def setup(self, old_version):
"""Install and configure the app."""
super().setup(old_version)
# Fresh install or upgrading to version 2
if old_version < 2:
privileged.set_resolved_configuration(dns_fallback=True)
# Load the configuration files for systemd-resolved provided by
# FreedomBox.
service_privileged.restart('systemd-resolved')
self.enable()

View File

@ -0,0 +1,4 @@
[Resolve]
# Use Avahi daemon instead of systemd-resolved for mDNS. Many programs such as
# GNOME and cups still depend on avahi-daemon.
MulticastDNS=no

View File

@ -0,0 +1,12 @@
[Resolve]
# Debian removes the default fallback DNS servers likely because they could be
# considered a privacy violation. However, when systemd-resolved package is
# first installed, the post install script recommends a reboot instead of
# feeding the currently configured nameservers from /etc/resolve.conf into
# systemd-resolved. Immediately, this causes the system not be able to connect
# to any external servers. While this may be acceptable solution for interactive
# systems and pre-built images, FreedomBox has to a) be available for remote
# access b) perform upgrades without user intervention (and without reboot until
# a day). To mitigate privacy concerns, an option to disable these fallback
# servers will be provided in the UI.
FallbackDNS=1.1.1.1#cloudflare-dns.com 8.8.8.8#dns.google 1.0.0.1#cloudflare-dns.com 8.8.4.4#dns.google 2606:4700:4700::1111#cloudflare-dns.com 2001:4860:4860::8888#dns.google 2606:4700:4700::1001#cloudflare-dns.com 2001:4860:4860::8844#dns.google

View File

@ -0,0 +1,37 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Configure Names App."""
import pathlib
from plinth import action_utils
from plinth.actions import privileged
fallback_conf = pathlib.Path(
'/etc/systemd/resolved.conf.d/freedombox-fallback.conf')
source_fallback_conf = pathlib.Path(
'/usr/share/freedombox'
'/etc/systemd/resolved.conf.d/freedombox-fallback.conf')
@privileged
def set_resolved_configuration(dns_fallback: bool | None = None):
"""Set systemd-resolved configuration options."""
if dns_fallback is not None:
_set_enable_dns_fallback(dns_fallback)
def get_resolved_configuration() -> dict[str, bool]:
"""Return systemd-resolved configuration."""
return {'dns_fallback': fallback_conf.exists()}
def _set_enable_dns_fallback(dns_fallback: bool):
"""Update whether to use DNS fallback servers."""
if dns_fallback:
if not fallback_conf.exists():
fallback_conf.parent.mkdir(parents=True, exist_ok=True)
fallback_conf.symlink_to(source_fallback_conf)
else:
fallback_conf.unlink(missing_ok=True)
action_utils.service_reload('systemd-resolved')