diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-08-19 14:01:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-19 14:01:48 -0400 |
commit | 651fbacc35b8fcd2b170357548c1f6272ae2c48b (patch) | |
tree | 167124e3eee310636bc04027d42bfb6db5d4f2b7 /libpod | |
parent | 55553bccdc7471b37ea8fc0398f637278695a896 (diff) | |
parent | 15fff7d918a782875ab130a6d96665aedc0ba967 (diff) | |
download | podman-651fbacc35b8fcd2b170357548c1f6272ae2c48b.tar.gz podman-651fbacc35b8fcd2b170357548c1f6272ae2c48b.tar.bz2 podman-651fbacc35b8fcd2b170357548c1f6272ae2c48b.zip |
Merge pull request #11281 from Luap99/3.3-back
[v3.3] backport rootless networking fixes
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/networking_linux.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 8e9b5997c..7eef04ddf 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -173,11 +173,27 @@ func (r *RootlessCNI) Do(toRun func() error) error { // the link target will be available in the mount ns. // see: https://github.com/containers/podman/issues/10855 resolvePath := "/etc/resolv.conf" - resolvePath, err = filepath.EvalSymlinks(resolvePath) - if err != nil { - return err + for i := 0; i < 255; i++ { + // Do not use filepath.EvalSymlinks, we only want the first symlink under /run. + // If /etc/resolv.conf has more than one symlink under /run, e.g. + // -> /run/systemd/resolve/stub-resolv.conf -> /run/systemd/resolve/resolv.conf + // we would put the netns resolv.conf file to the last path. However this will + // break dns because the second link does not exists in the mount ns. + // see https://github.com/containers/podman/issues/11222 + link, err := os.Readlink(resolvePath) + if err != nil { + // if there is no symlink exit + break + } + resolvePath = filepath.Join(filepath.Dir(resolvePath), link) + if strings.HasPrefix(resolvePath, "/run/") { + break + } + if i == 254 { + return errors.New("too many symlinks while resolving /etc/resolv.conf") + } } - logrus.Debugf("The actual path of /etc/resolv.conf on the host is %q", resolvePath) + logrus.Debugf("The path of /etc/resolv.conf in the mount ns is %q", resolvePath) // When /etc/resolv.conf on the host is a symlink to /run/systemd/resolve/stub-resolv.conf, // we have to mount an empty filesystem on /run/systemd/resolve in the child namespace, // so as to isolate the directory from the host mount namespace. |