fix: preserve systemd-resolved stub in DNS auto-detection#50
Merged
Conversation
0.4.1 introduced auto-detection of the host's DNS servers in linuxMacDNSServers(). When /etc/resolv.conf contained only the systemd-resolved stub (127.0.0.53), the code fell back to /run/systemd/resolve/resolv.conf to grab the raw upstream nameservers. That bypasses systemd-resolved entirely: queries go straight to the upstream over plain UDP/53, dropping DoT, DNSSEC, and split-DNS. On hosts where resolved is configured with DoT-only upstreams (Mullvad with DNSOverTLS=opportunistic is the reported case), the raw UDP path is unreachable and every lookup times out. Read /etc/resolv.conf verbatim instead. On the typical systemd-resolved host that returns 127.0.0.53, and queries flow through resolved as the user configured. As a safety net for minimal images that ship without /etc/resolv.conf, fall back to /run/systemd/resolve/stub-resolv.conf, which also points at the stub. The raw upstream file is never read. Fixes #47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
linuxMacDNSServers(): read/etc/resolv.confverbatim instead of swapping the stub out for the raw upstreams in/run/systemd/resolve/resolv.conf./run/systemd/resolve/stub-resolv.confonly when/etc/resolv.confis absent (minimal images). The raw upstream file is never read.sysdns_test.gocovering the 127.0.0.53 regression, multi-nameserver order, IPv6 bracketing, malformed lines, and missing files.Why
0.4.1 (#43) replaced 127.0.0.53 with the raw Mullvad upstream from
/run/systemd/resolve/resolv.conf, so greyproxy tried plain UDP/53 to an upstream that systemd-resolved had been reaching over DoT. On hosts configured withDNSOverTLS=opportunistic(matclab's setup in #47) the direct UDP path is unreachable and every lookup times out. Letting queries flow through 127.0.0.53 keeps DoT, DNSSEC, and split-DNS intact.The container concern the original code cited (127.x.x.x being container-local) doesn't apply: greyproxy runs on the host, and the sandboxed client connects to it via the host's loopback, so 127.0.0.53 is reachable.
Fixes #47
Test plan
go test ./cmd/greyproxy/ -run TestResolvConf -vgo build ./...go vet ./cmd/greyproxy/