diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-04-29 15:01:56 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-04-29 15:37:14 +0200 |
commit | 01acc2565ac6bba44da270d59b90231a0bca3319 (patch) | |
tree | 2d5694f2133962eccab7832ec4ba1c20042e6f48 /libpod | |
parent | 5198209269eb8248eb001e02d39b3dd0dfce6c19 (diff) | |
download | podman-01acc2565ac6bba44da270d59b90231a0bca3319.tar.gz podman-01acc2565ac6bba44da270d59b90231a0bca3319.tar.bz2 podman-01acc2565ac6bba44da270d59b90231a0bca3319.zip |
libpod: host netns keep same /etc/resolv.conf
When a container is run in the host network namespace we have to keep
the same resolv.conf content and not use the systemd-resolve detection
logic.
But also make sure we still allow --dns options.
Fixes #14055
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal_linux.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index af6e7417b..13670bc86 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -2279,9 +2279,11 @@ func (c *Container) generateResolvConf() error { networkSearchDomains []string ) + hostns := true resolvConf := "/etc/resolv.conf" for _, namespace := range c.config.Spec.Linux.Namespaces { if namespace.Type == spec.NetworkNamespace { + hostns = false if namespace.Path != "" && !strings.HasPrefix(namespace.Path, "/proc/") { definedPath := filepath.Join("/etc/netns", filepath.Base(namespace.Path), "resolv.conf") _, err := os.Stat(definedPath) @@ -2303,7 +2305,7 @@ func (c *Container) generateResolvConf() error { ns := resolvconf.GetNameservers(contents) // check if systemd-resolved is used, assume it is used when 127.0.0.53 is the only nameserver - if len(ns) == 1 && ns[0] == "127.0.0.53" { + if !hostns && len(ns) == 1 && ns[0] == "127.0.0.53" { // read the actual resolv.conf file for systemd-resolved resolvedContents, err := ioutil.ReadFile("/run/systemd/resolve/resolv.conf") if err != nil { @@ -2336,7 +2338,7 @@ func (c *Container) generateResolvConf() error { // Ensure that the container's /etc/resolv.conf is compatible with its // network configuration. - resolv, err := resolvconf.FilterResolvDNS(contents, ipv6, c.config.CreateNetNS) + resolv, err := resolvconf.FilterResolvDNS(contents, ipv6, !hostns) if err != nil { return errors.Wrapf(err, "error parsing host resolv.conf") } |