mirror of
https://github.com/containers/podman.git
synced 2025-12-11 01:11:30 +08:00
Fix up handling of user defined network namespaces
If user specifies network namespace and the /etc/netns/XXX/resolv.conf exists, we should use this rather then /etc/resolv.conf Also fail cleaner if the user specifies an invalid Network Namespace. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@@ -758,8 +758,24 @@ func (c *Container) makeBindMounts() error {
|
||||
|
||||
// generateResolvConf generates a containers resolv.conf
|
||||
func (c *Container) generateResolvConf() (string, error) {
|
||||
resolvConf := "/etc/resolv.conf"
|
||||
for _, ns := range c.config.Spec.Linux.Namespaces {
|
||||
if ns.Type == spec.NetworkNamespace {
|
||||
if ns.Path != "" && !strings.HasPrefix(ns.Path, "/proc/") {
|
||||
definedPath := filepath.Join("/etc/netns", filepath.Base(ns.Path), "resolv.conf")
|
||||
_, err := os.Stat(definedPath)
|
||||
if err == nil {
|
||||
resolvConf = definedPath
|
||||
} else if !os.IsNotExist(err) {
|
||||
return "", errors.Wrapf(err, "failed to stat %s", definedPath)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the endpoint for resolv.conf in case it is a symlink
|
||||
resolvPath, err := filepath.EvalSymlinks("/etc/resolv.conf")
|
||||
resolvPath, err := filepath.EvalSymlinks(resolvConf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -904,10 +904,10 @@ func WithNetNS(portMappings []ocicni.PortMapping, postConfigureNetNS bool, netmo
|
||||
}
|
||||
|
||||
ctr.config.PostConfigureNetNS = postConfigureNetNS
|
||||
ctr.config.CreateNetNS = true
|
||||
ctr.config.NetMode = namespaces.NetworkMode(netmode)
|
||||
ctr.config.CreateNetNS = !ctr.config.NetMode.IsUserDefined()
|
||||
ctr.config.PortMappings = portMappings
|
||||
ctr.config.Networks = networks
|
||||
ctr.config.NetMode = namespaces.NetworkMode(netmode)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user