Skip to content

resolved: add ability for external programs to hook into name resolution (for machined+networkd to synthesize records) - #39293

Merged
poettering merged 11 commits into
systemd:mainfrom
poettering:resolved-hook
Nov 15, 2025
Merged

poettering merged 11 commits into
systemd:mainfrom
poettering:resolved-hook

Conversation

@poettering

@poettering poettering commented Oct 13, 2025 •

Copy link
Copy Markdown
Member

Fixes: #8518

@bluca

bluca commented Oct 13, 2025

Copy link
Copy Markdown
Member

Could you please add an integration test for this at TEST-75-RESOLVED? Thanks

@bluca bluca added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels Oct 13, 2025
@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Oct 14, 2025
@poettering poettering added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed please-review PR is ready for (re-)review by a maintainer labels Oct 15, 2025
poettering added a commit that referenced this pull request Oct 16, 2025
Split out of #39293, but make a ton of sense on their own.

@daandemeyer daandemeyer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As @bluca said, this really needs an integration test

Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
Comment thread src/resolve/resolved-hook.c Resolved
@daandemeyer daandemeyer added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks needs-rebase labels Oct 20, 2025
@poettering

Copy link
Copy Markdown
Member Author

As @bluca said, this really needs an integration test

it has already, both for the networkd and for the machined case!

@poettering

Copy link
Copy Markdown
Member Author

it's almost certainly going to be the new one, i.e. "/run/systemd/resolve.hook/io.systemd.Network"

@bluca

bluca commented Nov 14, 2025

Copy link
Copy Markdown
Member

Yeah so if the socket unit is started it fails with: Failed to bind to varlink socket: Address already in use
if the socket unit is stopped it fails with: Failed to bind to varlink socket: Permission denied

Wild, guess it has to do with the sd-run sandbox

@poettering

Copy link
Copy Markdown
Member Author

hmm, so i guess this is because of the fake networkd service run via systemd-run in NetworkdClientTest, it doesn't get a socket passed in, and it cannot create it itself because networkd is run unpriv

@bluca

bluca commented Nov 14, 2025

Copy link
Copy Markdown
Member

Got the fix - ok if I push directly?

@poettering

Copy link
Copy Markdown
Member Author

sure

@github-actions github-actions Bot added please-review PR is ready for (re-)review by a maintainer and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Nov 14, 2025
@bluca

bluca commented Nov 14, 2025

Copy link
Copy Markdown
Member

Wild, guess it has to do with the sd-run sandbox

It was this ^^ the test runs in a sd-run sandbox, and sets up some shimmed directory where the sockets are set up, but the new one is in a new dir that wasn't covered, so the directory from the host was passed through (hence why "already in use" if socket was running and "permission denied" if it was not, as it could not write to it)

@bluca

bluca commented Nov 15, 2025

Copy link
Copy Markdown
Member

Other tests that use a different class (and run on networkd on the guest) also fail similarly:

test_coldplug_dhcp_ip4_only_no_ra (__main__.DnsmasqClientTest.test_coldplug_dhcp_ip4_only_no_ra) ...
---- systemd-networkd ----
Nov 14 23:05:37 autopkgtest-lxc-ccjkhw systemd-networkd[1939]: Failed to bind to systemd-resolved hook Varlink socket: Permission denied
Nov 14 23:05:37 autopkgtest-lxc-ccjkhw systemd-networkd[1939]: Could not set up manager: Permission denied

@bluca

bluca commented Nov 15, 2025

Copy link
Copy Markdown
Member

Pushed another test fix, should be ok now hopefully

poettering and others added 11 commits November 15, 2025 07:44
This introduces /run/systemd/resolve.hook/ as a new directory that local
(privileged) programs can bind a Varlink socket into. If they do they'll
get a method call for each attempted resolved lookup, which they can
then either process themselves (and generate new records for, or return
errors to block stuff) or let pass so that the regular resolution is
done.

Usecase for this is primarily two things:

1. in machined we can add local resolution of machine names to their IP
   addresses, similar in fashion to nss-mymachines, but working also if
   the non-NSS interfaces to name resolution are used, i.e. the local
   DNS responder. In fact, I think we should eventually remove
   nss-mymachines from our tree, as soon as this code in resolved is
   setlled.

2. in networkd we can add local resolution of names specified in DHCP
   leases we hand out.

But beyond that there should be many other uses, for example people
could write "dns firewalls" with this if they like where they
dynamically block certain names from resolution.

Fixes: systemd#8518
This basically implements nss-myhostname, but natively in
systemd-resolved, so that the logic becomes available also for clients
using the local DNS stub for resolution or the D-Bus or Varlink APIs.
Match the behaviour of the other test classes that use sd-run and
always create the mock tmpfs runtime dirs.
This will be needed as the new resolve.hook directory won't exist
on boot but will be needed by the test case.
Let's synthesize DNS RRs for leases handed out by our DHCP server. This
way local VMs can have resolvable hostnames locally.

This does not implement reverse look ups for now. We can add this
later in similar fashion.
This function doesn't "connect" to Varlink (i.e. it isn't a client) but
it binds a Varlink socket (i.e. it is server), hence let's remove the
verb "connect" from its name. let's copy how machined/resolved name the
counterpart for this function: manager_varlink_init()
Let's expose local VMs/containers under ._dhcp by default. Let's also
expose WIFI AP clients under .home.arpa (i.e. the RFC8375 domain for
home networks).
Let's make our networkd sockets recognizable purely by name. It hink
already for debugging it's a good idea to always set socket names, in
particular for services that have multiple sockets they listen on.

This adds a name to the rtnl socket, which so far missed one. Note that
the C code won't look for it, for compat with older versions, but at
least things are a bit more debuggable.
@poettering
poettering merged commit c15bd80 into systemd:main Nov 15, 2025
@github-actions github-actions Bot removed the please-review PR is ready for (re-)review by a maintainer label Nov 15, 2025
bluca pushed a commit to bluca/systemd-fedora that referenced this pull request Dec 19, 2025
systemd-networkd-resolve-hook.socket will be introduced by
systemd/systemd#39293 but we need the spec
to handle the socket for the upgrade/downgrade test to pass so adding
it early behind the upstream bcond.
slrz pushed a commit to hdacloud/systemd that referenced this pull request Feb 13, 2026
systemd-networkd-resolve-hook.socket will be introduced by
systemd/systemd#39293 but we need the spec
to handle the socket for the upgrade/downgrade test to pass so adding
it early behind the upstream bcond.

(cherry picked from commit ea1d871)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Interface for plugging custom name resolution services into resolved

5 participants