#1065624 resolved not working after installation, race with dbus and user creation

Package:
systemd-resolved
Source:
systemd-resolved
Description:
systemd DNS resolver
Submitter:
Timo Weingärtner
Date:
2024-05-26 13:42:03 UTC
Severity:
normal
#1065624#5
Date:
2024-03-07 14:12:14 UTC
From:
To:
After installing systemd-resolved name resolution does not work anymore:
----8<----8<----
# apt-get --no-install-recommends install systemd-resolved
[…]
# host debian.org
Host debian.org not found: 2(SERVFAIL)
# resolvectl
Failed to get global data: Connection timed out
# systemctl restart systemd-resolved.service
# host debian.org
debian.org has address […]
[…]
----8<----8<----

The relevant error message from dbus-daemon appears before postinst creates
the user and starts the service.

Maybe creating the user in preinst already, before it is referenced in
dbus config, would be better.

This is the log, including my workaround:
----8<----8<----
Mar 07 14:10:50 HOST python3(mitogen:[…])[45763]: ansible-apt Invoked with pkg=['systemd-resolved'] install_recommends=False package=['systemd-resolved'] state=present […]
Mar 07 14:10:51 HOST dbus-daemon[15599]: [system] Reloaded configuration
Mar 07 14:10:51 HOST dbus-daemon[15599]: [system] Reloaded configuration
Mar 07 14:10:51 HOST dbus-daemon[15599]: [system] Reloaded configuration
Mar 07 14:10:51 HOST dbus-daemon[15599]: Unknown username "systemd-resolve" in message bus configuration file
Mar 07 14:10:51 HOST dbus-daemon[15599]: [system] Reloaded configuration
Mar 07 14:10:51 HOST systemd[1]: Reloading.
Mar 07 14:10:52 HOST systemd[1]: Starting systemd-resolved.service - Network Name Resolution...
Mar 07 14:10:52 HOST systemd-resolved[46459]: Positive Trust Anchors:
Mar 07 14:10:52 HOST systemd-resolved[46459]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Mar 07 14:10:52 HOST systemd-resolved[46459]: Negative trust anchors: home.arpa 10.in-addr.arpa […]
Mar 07 14:10:52 HOST systemd-resolved[46459]: Using system hostname 'HOST'.
Mar 07 14:10:52 HOST systemd[1]: Started systemd-resolved.service - Network Name Resolution.
Mar 07 14:10:52 HOST systemd[1]: Reached target nss-lookup.target - Host and Network Name Lookups.
Mar 07 14:10:52 HOST dbus-daemon[15599]: [system] Reloaded configuration
Mar 07 14:10:53 HOST python3(mitogen:[…])[45763]: ansible-systemd_service Invoked with unit=dbus.service state=reloaded name=dbus.service daemon_reload=False daemon_reexec=False scope=system no_block=False enabled=None force=None masked=None
Mar 07 14:10:53 HOST systemd[1]: Reloading dbus.service - D-Bus System Message Bus...
Mar 07 14:10:53 HOST dbus-daemon[15599]: [system] Reloaded configuration
Mar 07 14:10:53 HOST dbus-send[46517]: method return time=1709817053.651177 sender=org.freedesktop.DBus -> destination=:1.143 serial=3 reply_serial=2
Mar 07 14:10:53 HOST systemd[1]: Reloaded dbus.service - D-Bus System Message Bus.
Mar 07 14:10:53 HOST python3(mitogen:[…])[45763]: ansible-systemd_service Invoked with unit=systemd-resolved.service state=restarted name=systemd-resolved.service daemon_reload=False daemon_reexec=False scope=system no_block=False enabled=None force=None masked=None
Mar 07 14:10:53 HOST systemd[1]: Stopping systemd-resolved.service - Network Name Resolution...
Mar 07 14:10:53 HOST systemd[1]: systemd-resolved.service: Deactivated successfully.
Mar 07 14:10:53 HOST systemd[1]: Stopped systemd-resolved.service - Network Name Resolution.
Mar 07 14:10:53 HOST systemd[1]: Starting systemd-resolved.service - Network Name Resolution...
Mar 07 14:10:53 HOST systemd-resolved[46522]: Positive Trust Anchors:
Mar 07 14:10:53 HOST systemd-resolved[46522]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Mar 07 14:10:53 HOST systemd-resolved[46522]: Negative trust anchors: home.arpa 10.in-addr.arpa […]
Mar 07 14:10:53 HOST systemd-resolved[46522]: Using system hostname 'HOST'.
Mar 07 14:10:53 HOST systemd[1]: Started systemd-resolved.service - Network Name Resolution.
Mar 07 14:10:53 HOST systemd-resolved[46522]: wlp[…]: Bus client set default route setting: yes
Mar 07 14:10:53 HOST systemd-resolved[46522]: wlp[…]: Bus client set DNS server list to: […]
Mar 07 14:10:53 HOST systemd-resolved[46522]: enx[…]: Bus client set search domain list to: […]
Mar 07 14:10:53 HOST systemd-resolved[46522]: enx[…]: Bus client set default route setting: yes
Mar 07 14:10:53 HOST systemd-resolved[46522]: enx[…]: Bus client set DNS server list to: […]
----8<----8<----

#1065624#10
Date:
2024-03-07 15:22:52 UTC
From:
To:
Am 07.03.24 um 15:12 schrieb Timo Weingärtner:

The chain of events afaics is this:

1/ postinst creates systemd-resolve
2/ systemd-resolved.service is started in postinst
3/ dbus trigger is activated after postinst and the dbus config is reloaded

Because the dbus daemon reload happens after the systemd-resolved user
has been created, systemd-resolved could not successfully claim the
org.freedesktop.resolve1 D-Bus name.

What we would need to be able to do is to trigger a dbus daemon-reload
after the system user has been created and before the service is started.

Both is autogenerated code (via dh_installsysusers and
dh_installsystemd), and there is no way to inject maintscript code
manually unfortunately.

#1065624#15
Date:
2024-03-07 15:26:28 UTC
From:
To:
Am 07.03.24 um 16:22 schrieb Michael Biebl:

One way to maybe address this is to make dh_installsysusers generate
maintscript code to reload dbus.
This could either be done unconditionally, via a dh_installsysusers
option, or automatically when it finds a D-Bus config file shipped by
the package (and referencing that user).

dh_installsysusers is part of debhelper, so would need to be addressed
there.

#1065624#20
Date:
2024-05-26 13:38:59 UTC
From:
To:
reloaded
user
reload
started.
addressed

We should finally switch the dh tools to use mark-and-sweep for
starting/stopping/restarting, instead of doing it inline, so that it
can be done once at the end with a trigger. Then we can order the
trigger between reloading dbus and starting units.