Skip to content

The netbird role ranks the overlay's resolver first where resolvconf writes resolv.conf - #97

Merged
davidjalbers merged 5 commits into
mainfrom
davidjalbers/plx-262-a-host-with-three-or-more-nameservers
Dec 3, 2026
Merged

davidjalbers merged 5 commits into
mainfrom
davidjalbers/plx-262-a-host-with-three-or-more-nameservers

Conversation

@davidjalbers

@davidjalbers davidjalbers commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What changes

The role netbird of plexus.host ranks NetBird's interface first in /etc/resolvconf/interface-order where Debian's resolvconf writes /etc/resolv.conf, and has resolvconf -u write the file again at once.

  • tasks/resolvconf.yml, imported by tasks/main.yml after the install and before the daemon starts: a managed block (blockinfile, marker # BEGIN/END plexus.host.netbird: the overlay's resolver first) holding one pattern, the interface's name, above the package's lines.
  • It acts only where /etc/resolv.conf resolves to /run/resolvconf/resolv.conf (the test resolvconf's own postinst makes) and interface-order exists.
  • Right after the block, a task runs resolvconf -u where the block task reported a change, so that a record NetBird registered before the run moves within the run, before the play's next task.
    It is a task, not a handler: a flush this early in the play would run every other role's pending handler with it.
    ansible-lint's no-handler is set aside at that one line.
  • defaults/main.yml: netbird_interface: wt0, the name of the record the block ranks.
  • newborns/netbird-resolvconf.test.ts: a Debian trixie container with the real resolvconf package (1.94), four nameservers under eth0.inet6 and eth0.dhcp, and a stand-in record wt0 with the overlay's resolver and search domain.
    The container takes SYS_ADMIN alone, to unmount the resolv.conf Docker mounts.

The runner host's user-data is unchanged.

What a consumer sees when it takes the version

On a host with netbird_enabled whose /etc/resolv.conf is resolvconf's, the next playbook run reports two changed tasks: Rank the overlay's resolver first adds three lines at the head of interface-order, and Have resolvconf write resolv.conf in the new order rewrites /etc/resolv.conf.
NetBird's resolver is then the first nameserver and the overlay's domain leads the search list.
That holds on every such host, not only on one with three or more provider nameservers: on a host whose overlay resolver was third, it is now first, so every public name goes through NetBird's forwarder first (question 1).
Such a host with two provider nameservers may also have failed to resolve overlay names before: glibc ends a lookup at the first NXDOMAIN, so a provider resolver that answers NXDOMAIN for the overlay's domain never lets the third nameserver be asked (the reviewer ran this with stand-in servers; what a real provider answers is unknown, and the issue's statement that a Proxmox guest does not show the fault is itself unverified). The change may therefore repair such hosts as well as reroute their public lookups.
A delivery slot's container that already runs keeps its copy of the old file until it restarts; a new runner host runs netbird before actions_runners, so its slots start with the new file.
A second run changes nothing.
On a host where systemd-resolved, NetworkManager or a plain file owns /etc/resolv.conf, the three new tasks report ok or skipped and nothing changes.

The four questions

1. Does NetBird's resolver, ranked first, answer names outside the overlay, and how fast does glibc move on?
It forwards them.
With the resolvconf manager NetBird writes only its own address as nameserver (applyDNSConfig, client/internal/dns/resolvconf_unix.go), and registers the nameservers it read from /etc/resolv.conf at start as a handler for the root zone at PriorityFallback, skipping its own address (registerFallback, server.go).
A primary nameserver group of the account, where there is one, takes all names at a higher priority.
When every upstream fails it answers SERVFAIL (upstream.go); when no handler matches, REFUSED (handler_chain.go).
glibc goes to the next nameserver at once on SERVFAIL, NOTIMP or REFUSED (resolv/res_send.c, glibc 2.41, thisansp_error) and on an ICMP port unreachable (ECONNREFUSED, same file); only a resolver that does not answer at all costs the timeout, 5 s by default (resolv.conf(5), timeout:n).
A daemon that stops cleanly removes its record (resolvconf -d), so the provider's nameservers lead again.
After an unclean exit that leaves a stale record, NetBird at its next start reads a file with its own address first, skips that address (by equality, in registerFallback), and so forwards to the two provider nameservers that survive resolvconf's limit of three, not three (the reviewer's reading of the source; not run).
Public resolution therefore keeps working; it gains one hop through the forwarder, and a hung daemon whose record stays would cost 5 s per query before the next nameserver.
I did not stop on this.

2. Is the interface always wt0?
No: wt0 is NetBird's default (client/iface/configurer/name.go), netbird up --interface-name changes it (client/cmd/up.go), and so can an MDM policy; the profile keeps it as WgIface.
The record NetBird registers is named exactly after the interface (resolvconf -a <interface>, resolvconf_unix.go).
The role never passes --interface-name and netbird status does not report the name, so the role does not know it; it gets a default, netbird_interface: wt0, which a host that changed the name sets alike.

3. Does an upgrade of resolvconf overwrite interface-order?
It is a conffile: DEBIAN/conffiles of resolvconf_1.94_all.deb (trixie) lists /etc/resolvconf/interface-order.
dpkg keeps a locally changed conffile when the package's version of it did not change, and asks when it did, unless --force-confold or --force-confnew decides (dpkg(1), --force-things); the collection sets neither.
unattended-upgrades holds such a package back with "Package resolvconf has conffile prompt and needs to be upgraded manually" (conffile_prompt in /usr/bin/unattended-upgrade of the trixie package).
resolvconf reads no other file for the order: list-records reads interface-order, and its own built-in list only where the file is unreadable.
So the role edits the conffile, but as little as it can: one block above the package's lines, the rest left as shipped, so that a prompt shows a one-hunk difference.
A person who takes the package's new file drops the block until the next playbook run writes it again; a test holds that.
Where interface-order is missing, the role does nothing rather than create a file of one line, which would leave every other record unlisted.

4. Is the task a no-op where systemd-resolved or NetworkManager manages DNS?
Yes.
The condition is the one resolvconf's own postinst uses: /etc/resolv.conf resolves to /run/resolvconf/resolv.conf (resolvconf(8): the link "is normally created on installation of the resolvconf package").
With systemd-resolved the file links to /run/systemd/resolve/stub-resolv.conf; NetworkManager writes a file of its own; either way the block is skipped and resolvconf -u never runs.
The condition reads no command, so the resolvconf that Debian's systemd-resolved package provides as a compatibility command does not count.
On such hosts NetBird uses those managers itself (getOSDNSManagerType, host_unix.go).
A test holds it for a link to the stub and for a file headed # Generated by NetworkManager, by the link and the file alone, not with the daemons running.

Choices the issue did not make

  • The fix sits in the role netbird of plexus.host, not in the runner host's user-data, since any host on an image where resolvconf writes the file is affected (the coordinator's reading, for the maintainer to confirm or correct).
  • The block goes at the very head, above the package's lo* lines, as the fix by hand did: a local caching resolver registered under lo would otherwise come first, and resolvconf's TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS (default yes) would cut the overlay's resolver off behind it.
  • The pattern is the exact interface name, wt0, not wt0*: NetBird's record has exactly that name.
  • The ranking runs on every host the role runs on where resolvconf writes the file, whatever the number of nameservers.
  • netbird_interface is a new default instead of a name read from NetBird's profile file, whose format is NetBird's own.
  • The test runs the task file through include_role with tasks_from, and checks with --list-tasks that the role's main file lists the ranking's own task before Enable and start the NetBird daemon; the import has a name of its own, apart from that task's.
    The real NetBird daemon is not installed in the test.

Not tried

  • A real machine: no runner host or app host was created or touched; the provider's image and the four nameservers are a stand-in in a container.
  • A real NetBird daemon registering its record, joining an overlay, or forwarding a public name; answers 1 and 2 rest on NetBird's source at d8a304a, not on a run.
  • A deploy through a delivery slot, or a slot's copy of the file.
  • A package upgrade of resolvconf with a changed conffile; the test copies the package's file back by hand.
  • Real systemd-resolved or NetworkManager.
  • Whether a Proxmox guest uses resolvconf at all.
  • Test first for every behaviour: the two guard tests of the third commit (the package's file coming back, and the hosts where nothing runs) came after the code they hold.
    Each was checked by breaking that code once.

Owed to the compendium

  • approaches/platform.md, the paragraph on the netbird role, says nothing of DNS.
    This pull request does not change the compendium.

🤖 Generated with Claude Code

davidjalbers and others added 3 commits December 3, 2026 13:17
…esolvconf writes resolv.conf (PLX-262)

Red: on a Debian host whose /etc/resolv.conf is resolvconf's, with four
nameservers from eth0 and NetBird's record wt0, resolvconf writes the
provider's three and cuts the overlay's resolver off. The role has no task
file resolvconf.yml, its main file names none, and nothing ranks wt0 or
the interface it is told. The first test, the host as found, passes: it
shows the cut-off in the container with the real package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…writes resolv.conf (PLX-262)

resolvconf writes at most three nameservers, in the order of
/etc/resolvconf/interface-order, which ranks eth* and the other named
interfaces ahead of NetBird's, matched only by the last line. A host whose
provider brings three or more nameservers cut the overlay's resolver off,
and no overlay name resolved.

Where /etc/resolv.conf links to resolvconf's own, as its package links it,
the role adds a block that names NetBird's interface above the package's
lines and has resolvconf write the file again at once. Ranked first, the
resolver answers the overlay's zones and forwards every other name to the
nameservers the host had when the daemon started. The interface is
netbird_interface, NetBird's default wt0, which the role does not change.
Elsewhere, and where interface-order is missing, nothing runs.

The task file runs before the daemon starts, so that a host joining in the
same run registers into the order already.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… nothing where resolvconf does not write resolv.conf (PLX-262)

Guards, green at once: a run after the package's interface-order came back
ranks the overlay's resolver first again; a run on a host whose
resolv.conf links to systemd-resolved's stub, is a file of its own as
NetworkManager writes one, or is resolvconf's with no interface-order
passes and changes neither file. Without the task's two conditions the
second test fails at its first host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidjalbers davidjalbers self-assigned this Dec 3, 2026
davidjalbers and others added 2 commits December 3, 2026 13:32
…ng other roles' handlers, and runs before the daemon starts (PLX-262)

Red: a play in which an earlier task notifies a handler, then the task file
runs, then later tasks read resolv.conf and look for the handler's mark.
The overlay's resolver leads at once, but the earlier handler has already
run: the role's flush runs every handler pending in the play.

The listing test now finds the task of the imported file by its whole
name and holds it before the daemon's start; it passes at this commit,
and no longer passes for a task that only shares the start of the name.
The container takes SYS_ADMIN alone, which unmounting Docker's
resolv.conf needs, instead of --privileged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, not by a flushed handler (PLX-262)

resolvconf -u runs right after the block, where the block task reports a
change, so the file is written again within the run and nothing waits on
the end of the play. The handler and the flush are gone: the flush ran
every handler pending in the play, and the role runs right after base, so
other roles' handlers ran earlier than before. In check mode nothing runs,
as before. ansible-lint's no-handler is set aside at that one line, with
the reason above the task.

The import takes a name of its own, apart from the task it brings, and the
header says the forwarded nameservers are those /etc/resolv.conf held when
the daemon started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidjalbers
davidjalbers merged commit ed79975 into main Dec 3, 2026
2 checks passed
@davidjalbers
davidjalbers deleted the davidjalbers/plx-262-a-host-with-three-or-more-nameservers branch December 3, 2026 13:05
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.

1 participant