From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 8671B5A026E for ; Mon, 30 Nov 2026 01:34:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795998886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BZfYfSMblogM+fZZiT8DKrUiZr0as4Dl6SXCHPs1Gok=; b=dsyAUX9PaqTc9TBm3HFSc/3ri6a0PsXOMkkptmeo/J1HacDQ1b+VZKtwhaIwPGCAI1KBMO TRi3DKo2i8eP31C2ayXMuWXXhj1utmbGlyZNMIMwhfFoIqfH40SwYAFq66CuA0eHSYf8og oRG53QftQhNknWGL7WEuKBVYeVt+sbA= X-MC-Rep: binary re single Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-267-z98mSu8PNTu3I_OIuE1EfA-1; Mon, 30 Nov 2026 00:34:44 +0000 X-MC-Unique: z98mSu8PNTu3I_OIuE1EfA-1 X-Mimecast-MFC-AGG-ID: z98mSu8PNTu3I_OIuE1EfA_1795998883 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4b9fde3044dso71172685e9.0 for ; Sun, 29 Nov 2026 16:34:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795998883; x=1796603683; h=date:content-transfer-encoding:content-type:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to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b0:4a2:a9:ed5a with SMTP id 5b1f17b1804b1-4bb88826835mr634484995e9.8.1795998882838; Sun, 29 Nov 2026 16:34:42 -0800 (PST) X-Received: by 2002:a05:600c:8b11:b0:4a2:a9:ed5a with SMTP id 5b1f17b1804b1-4bb88826835mr634484825e9.8.1795998882273; Sun, 29 Nov 2026 16:34:42 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb9065744esm501639795e9.1.2026.11.29.16.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 16:34:41 -0800 (PST) From: Stefano Brivio To: Aditya Merchant Subject: Re: [PATCH v2 1/2] conf: Follow changes to the host nameserver used for DNS forwarding Message-ID: <20261130013439.0a40738a@elisabeth> In-Reply-To: <20261113112114.38764-2-adityamerchant08@gmail.com> References: <20261113112114.38764-1-adityamerchant08@gmail.com> <20261113112114.38764-2-adityamerchant08@gmail.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Mon, 30 Nov 2026 01:34:40 +0100 (CET) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RIFep7xCPA1JPASuY7FnehCPauZRTZVHPl80ojb6W2E_1795998883 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: K75LFF7LJ4PTJUEI6FH5P4T3HWZGSFL3 X-Message-ID-Hash: K75LFF7LJ4PTJUEI6FH5P4T3HWZGSFL3 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, David Gibson , Paul Holzinger X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi Aditya, On Fri, 13 Nov 2026 16:51:13 +0530 Aditya Merchant wrote: > 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. >=20 > 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. >=20 > 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. >=20 > 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. >=20 > Flows that already exist keep their target, so a client reusing the > same source port keeps reaching the old nameserver until its flow > expires. >=20 > 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. >=20 > Link: https://github.com/podman-container-tools/podman/issues/29130 > Link: https://archives.passt.top/passt-dev/20230121104703.3ebcc753@elisab= eth/ > Signed-off-by: Aditya Merchant Applied, thanks for your patience and for the significant feature, and welcome to the git log! I finally had the chance to test this with a few different configurations, with SELinux and AppArmor, it all works. I still have a few comments, below, that might be relevant for follow-ups. > [...] > > @@ -281,6 +310,216 @@ out: > =09} > } > =20 > +/* Name of host's resolv.conf, or of the target of a symbolic link to it= , that > + * we follow changes to: see conf_resolv_watch() > + */ > +#define RESOLV_NAME=09"resolv.conf" > + > +/** > + * conf_resolv_update() - Update host nameservers from host's resolv.con= f > + * @c:=09=09Execution context > + * > + * Return: 0 on success, negative error code if the file can't be opened > + * > + * #syscalls:pasta openat In case you extend this to passt as well, don't forget to update the count of allowed system calls for x86_64 in README.md, that is: -* =E2=9C=85 restrictive seccomp profiles (34 syscalls allowed for _passt_,= 43 for +* =E2=9C=85 restrictive seccomp profiles (35 syscalls allowed for _passt_,= 43 for _pasta_ on x86_64) > + */ > +static int conf_resolv_update(struct ctx *c) > +{ > +=09bool found4 =3D false, found6 =3D false; > +=09char addr[INET6_ADDRSTRLEN]; > +=09struct lineread resolvconf; > +=09struct in6_addr ns6; > +=09struct in_addr ns4; > +=09char *line; > +=09int fd; > + > +=09fd =3D openat(c->resolv_dir_fd, RESOLV_NAME, O_RDONLY | O_CLOEXEC); > +=09if (fd < 0) > +=09=09return -errno; > + > +=09lineread_init(&resolvconf, fd); > +=09while (lineread_get(&resolvconf, &line) > 0) { > +=09=09const char *p =3D resolv_nameserver(line); > + > +=09=09if (!p) > +=09=09=09continue; > + > +=09=09if (!found4) > +=09=09=09found4 =3D inet_pton(AF_INET, p, &ns4) =3D=3D 1; > +=09=09if (!found6) > +=09=09=09found6 =3D inet_pton(AF_INET6, p, &ns6) =3D=3D 1; > +=09} > +=09close(fd); > + > +=09if (c->ip4.dns_host_resolv && found4 && > +=09 !IN4_ARE_ADDR_EQUAL(&ns4, &c->ip4.dns_host)) { > +=09=09c->ip4.dns_host =3D ns4; > +=09=09info("Forwarding DNS queries to new host nameserver %s", > +=09=09 inet_ntop(AF_INET, &ns4, addr, sizeof(addr))); > +=09} > + > +=09if (c->ip6.dns_host_resolv && found6 && > +=09 !IN6_ARE_ADDR_EQUAL(&ns6, &c->ip6.dns_host)) { > +=09=09c->ip6.dns_host =3D ns6; > +=09=09info("Forwarding DNS queries to new host nameserver %s", > +=09=09 inet_ntop(AF_INET6, &ns6, addr, sizeof(addr))); > +=09} If we didn't find any nameserver for a given IP version, but we had one in .dns_host, we'll keep that one instead of removing it. It should be harmless, I think, because in the worst case we'll just try to attempt reaching a stale and possibly unreachable DNS server, but it might be unexpected (the user might have removed the server for a specific reason, and expects us now to remove it as well) and also inconsistent with what we do at start-up time. So, I guess, we could / should clear .dns_host on !found4 or !found6. > [...] > > +++ b/passt.1 > @@ -287,7 +287,10 @@ Configure the host nameserver which guest or namespa= ce queries to the > \fB\-\-dns-forward\fR address will be redirected to. This option can > be specified zero to two times (once for IPv4, once for IPv6). > By default, the first nameserver from the host's > -\fI/etc/resolv.conf\fR. > +\fI/etc/resolv.conf\fR. In pasta mode, on Linux 5.12 or later, this In case you extend this to passt, don't forget to drop "In pasta mode...". > +default follows changes to that file: new DNS flows go to its current > +first nameserver of the same IP version, while existing flows keep their > +target until they expire. The "its" makes it a bit hard to read, I think: it's not obvious that it refers to "that file", but, if it refers to it, then it doesn't really add much. That is, I think something like: "[...] new DNS flows go to the first nameserver listed for each IP version" would probably be clearer and include all the relevant information. --=20 Stefano