From d386eaf904adafd8109be067c2029fdb407644a0 Mon Sep 17 00:00:00 2001 From: linxin Date: Mon, 15 Apr 2024 11:38:42 +0800 Subject: [PATCH] Validate resolv.conf for presence of nameserver entries Co-authored-by: Brad Davidson Signed-off-by: linxin (cherry picked from commit f24ba9d3a9d7965fee4e9a9c44541356c14dc6a1) Signed-off-by: Brad Davidson --- pkg/agent/config/config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/agent/config/config.go b/pkg/agent/config/config.go index b7a03ca701..f81c36beae 100644 --- a/pkg/agent/config/config.go +++ b/pkg/agent/config/config.go @@ -316,19 +316,22 @@ func isValidResolvConf(resolvConfFile string) bool { nameserver := regexp.MustCompile(`^nameserver\s+([^\s]*)`) scanner := bufio.NewScanner(file) + foundNameserver := false for scanner.Scan() { ipMatch := nameserver.FindStringSubmatch(scanner.Text()) if len(ipMatch) == 2 { ip := net.ParseIP(ipMatch[1]) if ip == nil || !ip.IsGlobalUnicast() { return false + } else { + foundNameserver = true } } } if err := scanner.Err(); err != nil { return false } - return true + return foundNameserver } func locateOrGenerateResolvConf(envInfo *cmds.Agent) string {