1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #41335 from thaJeztah/remove_unneeded_eval_symlinks

daemon.setupPathsAndSandboxOptions() skip resolving symlinks
This commit is contained in:
Akihiro Suda 2020-08-18 19:55:51 +09:00 committed by GitHub
commit 111f9c3fdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -399,21 +399,11 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
case container.HostConfig.NetworkMode.IsHost():
// In host-mode networking, the container does not have its own networking
// namespace, so both `/etc/hosts` and `/etc/resolv.conf` should be the same
// as on the host itself. The container gets a copy of these files, but they
// may be symlinked, so resolve the original path first.
etcHosts, err := filepath.EvalSymlinks("/etc/hosts")
if err != nil {
return err
}
resolvConf, err := filepath.EvalSymlinks("/etc/resolv.conf")
if err != nil {
return err
}
// as on the host itself. The container gets a copy of these files.
*sboxOptions = append(
*sboxOptions,
libnetwork.OptionOriginHostsPath(etcHosts),
libnetwork.OptionOriginResolvConfPath(resolvConf),
libnetwork.OptionOriginHostsPath("/etc/hosts"),
libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf"),
)
case container.HostConfig.NetworkMode.IsUserDefined():
// The container uses a user-defined network. We use the embedded DNS
@ -427,11 +417,10 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
// If systemd-resolvd is used, the "upstream" DNS servers can be found in
// /run/systemd/resolve/resolv.conf. We do not query those DNS servers
// directly, as they can be dynamically reconfigured.
resolvConf, err := filepath.EvalSymlinks("/etc/resolv.conf")
if err != nil {
return err
}
*sboxOptions = append(*sboxOptions, libnetwork.OptionOriginResolvConfPath(resolvConf))
*sboxOptions = append(
*sboxOptions,
libnetwork.OptionOriginResolvConfPath("/etc/resolv.conf"),
)
default:
// For other situations, such as the default bridge network, container
// discovery / name resolution is handled through /etc/hosts, and no
@ -444,11 +433,10 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
// DNS servers on the host can be dynamically updated.
//
// Copy the host's resolv.conf for the container (/run/systemd/resolve/resolv.conf or /etc/resolv.conf)
resolvConf, err := filepath.EvalSymlinks(daemon.configStore.GetResolvConf())
if err != nil {
return err
}
*sboxOptions = append(*sboxOptions, libnetwork.OptionOriginResolvConfPath(resolvConf))
*sboxOptions = append(
*sboxOptions,
libnetwork.OptionOriginResolvConfPath(daemon.configStore.GetResolvConf()),
)
}
container.HostsPath, err = container.GetRootResourcePath("hosts")