<feed xmlns='http://www.w3.org/2005/Atom'>
<title>passt/test/pasta_options/dns_host_follow, branch master</title>
<subtitle>Plug A Simple Socket Transport</subtitle>
<link rel='alternate' type='text/html' href='https://passt.top/passt/'/>
<entry>
<title>conf: Follow changes to the host nameserver used for DNS forwarding</title>
<updated>2026-11-29T23:37:09+00:00</updated>
<author>
<name>Aditya Merchant</name>
<email>adityamerchant08@gmail.com</email>
</author>
<published>2026-11-13T11:21:13+00:00</published>
<link rel='alternate' type='text/html' href='https://passt.top/passt/commit/?id=f6d66985479641283059841b71966f84b5188890'/>
<id>f6d66985479641283059841b71966f84b5188890</id>
<content type='text'>
We read the host's /etc/resolv.conf once, at start, and forward queries
sent to the --dns-forward address to the first nameserver listed there.
If the host then joins another network, connects to a VPN, or pasta
starts before the network is configured, that nameserver goes stale and
name resolution in the namespace stops working until pasta restarts.
With rootless Podman, that means stopping every container using the
rootless network namespace.

In pasta mode, if we forward DNS queries for an IP version, and the host
nameserver for it comes from resolv.conf (no --dns-host or --dns), watch
resolv.conf with inotify and read it again as it changes, so that new
DNS flows go to its current first nameserver. Watch the directory, not
the file, as NetworkManager and others replace resolv.conf by renaming
a new file over it. If resolv.conf is a symbolic link, watch the
directory of its target, as long as that's also called resolv.conf:
the other usual target, systemd-resolved's stub-resolv.conf, always
points to its local stub resolver anyway.

Once sandboxed, we can't open files by path, and keeping a descriptor
for the directory would undo the filesystem isolation: lookups of ".."
from it reach the rest of the host filesystem. Instead, right after
isolate_prefork() unshares our mount namespace, and before mounts become
unbindable, take a detached copy of the directory with open_tree() and
OPEN_TREE_CLONE: lookups from its root can't go above it, so the
directory holding resolv.conf is all we can still see. Make that copy
read-only, and only ever open resolv.conf from it. This needs Linux 5.12
or later: if any step fails, or if we can't read resolv.conf through the
copy, we don't follow changes.

AppArmor resolves paths of files on a detached mount relative to their
filesystem, so allow the usual locations of resolv.conf under /run with
paths relative to /run, too. For SELinux, allow watching /etc, and the
directories under /run used by NetworkManager and systemd-resolved.

Flows that already exist keep their target, so a client reusing the
same source port keeps reaching the old nameserver until its flow
expires.

The new test replaces resolv.conf on an overlay mounted on /etc, in a
separate mount namespace, and checks that we pick up the new nameserver.

Link: https://github.com/podman-container-tools/podman/issues/29130
Link: https://archives.passt.top/passt-dev/20230121104703.3ebcc753@elisabeth/
Signed-off-by: Aditya Merchant &lt;adityamerchant08@gmail.com&gt;
Reviewed-by: Laurent Vivier &lt;lvivier@redhat.com&gt;
Signed-off-by: Stefano Brivio &lt;sbrivio@redhat.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We read the host's /etc/resolv.conf once, at start, and forward queries
sent to the --dns-forward address to the first nameserver listed there.
If the host then joins another network, connects to a VPN, or pasta
starts before the network is configured, that nameserver goes stale and
name resolution in the namespace stops working until pasta restarts.
With rootless Podman, that means stopping every container using the
rootless network namespace.

In pasta mode, if we forward DNS queries for an IP version, and the host
nameserver for it comes from resolv.conf (no --dns-host or --dns), watch
resolv.conf with inotify and read it again as it changes, so that new
DNS flows go to its current first nameserver. Watch the directory, not
the file, as NetworkManager and others replace resolv.conf by renaming
a new file over it. If resolv.conf is a symbolic link, watch the
directory of its target, as long as that's also called resolv.conf:
the other usual target, systemd-resolved's stub-resolv.conf, always
points to its local stub resolver anyway.

Once sandboxed, we can't open files by path, and keeping a descriptor
for the directory would undo the filesystem isolation: lookups of ".."
from it reach the rest of the host filesystem. Instead, right after
isolate_prefork() unshares our mount namespace, and before mounts become
unbindable, take a detached copy of the directory with open_tree() and
OPEN_TREE_CLONE: lookups from its root can't go above it, so the
directory holding resolv.conf is all we can still see. Make that copy
read-only, and only ever open resolv.conf from it. This needs Linux 5.12
or later: if any step fails, or if we can't read resolv.conf through the
copy, we don't follow changes.

AppArmor resolves paths of files on a detached mount relative to their
filesystem, so allow the usual locations of resolv.conf under /run with
paths relative to /run, too. For SELinux, allow watching /etc, and the
directories under /run used by NetworkManager and systemd-resolved.

Flows that already exist keep their target, so a client reusing the
same source port keeps reaching the old nameserver until its flow
expires.

The new test replaces resolv.conf on an overlay mounted on /etc, in a
separate mount namespace, and checks that we pick up the new nameserver.

Link: https://github.com/podman-container-tools/podman/issues/29130
Link: https://archives.passt.top/passt-dev/20230121104703.3ebcc753@elisabeth/
Signed-off-by: Aditya Merchant &lt;adityamerchant08@gmail.com&gt;
Reviewed-by: Laurent Vivier &lt;lvivier@redhat.com&gt;
Signed-off-by: Stefano Brivio &lt;sbrivio@redhat.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
