net/dns: add a health warning when Linux /etc/resolv.conf is overwritten

Change-Id: I925b4d904bc7ed920bc5afee11e6dcb2ffc2fbfd
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2022-11-13 07:35:02 -08:00 committed by Brad Fitzpatrick
parent 3f8e185003
commit 90bd74fc05

View File

@ -21,6 +21,7 @@
"sync" "sync"
"time" "time"
"tailscale.com/health"
"tailscale.com/net/dns/resolvconffile" "tailscale.com/net/dns/resolvconffile"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/util/dnsname" "tailscale.com/util/dnsname"
@ -293,10 +294,10 @@ func (m *directManager) setWant(want []byte) {
m.wantResolvConf = want m.wantResolvConf = want
} }
var warnTrample = health.NewWarnable()
// checkForFileTrample checks whether /etc/resolv.conf has been trampled // checkForFileTrample checks whether /etc/resolv.conf has been trampled
// by another program on the system. (e.g. a DHCP client) // by another program on the system. (e.g. a DHCP client)
//
// For now (2022-11-12) this only logs on changes in state.
func (m *directManager) checkForFileTrample() { func (m *directManager) checkForFileTrample() {
m.mu.Lock() m.mu.Lock()
want := m.wantResolvConf want := m.wantResolvConf
@ -313,13 +314,13 @@ func (m *directManager) checkForFileTrample() {
return return
} }
if bytes.Equal(cur, want) { if bytes.Equal(cur, want) {
warnTrample.Set(nil)
if lastWarn != nil { if lastWarn != nil {
m.mu.Lock() m.mu.Lock()
m.lastWarnContents = nil m.lastWarnContents = nil
m.mu.Unlock() m.mu.Unlock()
m.logf("trample: resolv.conf again matches expected content") m.logf("trample: resolv.conf again matches expected content")
} }
// TODO(bradfitz): register with health package that all is well
return return
} }
if bytes.Equal(cur, lastWarn) { if bytes.Equal(cur, lastWarn) {
@ -336,7 +337,7 @@ func (m *directManager) checkForFileTrample() {
show = show[:1024] show = show[:1024]
} }
m.logf("trample: resolv.conf changed from what we expected. did some other program interfere? current contents: %q", show) m.logf("trample: resolv.conf changed from what we expected. did some other program interfere? current contents: %q", show)
// TODO(bradfitz): register with health package that something is wrong warnTrample.Set(errors.New("Linux DNS config not ideal. /etc/resolv.conf overwritten. See https://tailscale.com/s/dns-fight"))
} }
func (m *directManager) SetDNS(config OSConfig) (err error) { func (m *directManager) SetDNS(config OSConfig) (err error) {