Block list fetching does not respect to per-client upstreams and bootstrap upstreams
Prerequisites
-
[x] I have checked the Wiki and Discussions and found no answer
-
[x] I have searched other issues and found no duplicates
-
[x] I want to report a bug and not ask a question or ask for help
-
[x] I have set up AdGuard Home correctly and configured clients to use it. (Use the Discussions for help with installing and configuring clients.)
Platform (OS and CPU architecture)
Linux, AMD64 (aka x86_64)
Installation
GitHub releases or script from README
Setup
On one machine
AdGuard Home version
AdGuard Home, version v0.107.77
Action
Added a client upstream [/example.com/]127.0.0.11(the docker dns) for 127.0.0.1, ::1, 172.10.0/16(the docker network).
Added boostrap upstream 127.0.0.11(the docker dns).
Adding a custom blocklist serving from a local server with custom domain in the same docker network as AdGuardHome. It used the global upstream and failed to resolve the domain.
Expected result
Queries from AdGuardHome itself, unless upstream server domain, should respect to per-client settings, where there's a rule for querying the custom domain of block list url in this case.
Some preliminary thoughts:
- Respect per-client settings for queries from AdGuardHome itself, with ip
127.0.0.1 - Fallback to global bootstrap upstream to resolve blocklist fetching.
- Provide a builtin ClientID that identifies queries from AdGuardHome itself.
Actual result
AdGuardHome ignores per-client settings, instead it uses global upstream settings and fails.
Additional information and/or screenshots
nslookup queries from inside AdGuardHome container correctly goes into expected per-client upstream.
I can reproduce this. I’ll forward it to the dev team.
I can also reproduce this issue on AdGuard Home v0.107.78.
In my setup, split DNS routing is configured through upstream_dns_file. The rule [/example.local/]127.0.0.2 is not honored for the resolution performed by AdGuard Home itself; instead of querying the DNS server at 127.0.0.2, it uses the global upstream https://dns.google/dns-query.
I reproduced the per-client part of this report against current master at
5f6cb57df9d54d8a89afc9200d813411f9ce4f7a, but there is an API-policy
decision to make before a safe patch.
The internal HTTP client resolves download hostnames through
Server.Resolve, which calls internalProxy.LookupNetIP directly:
Normal client requests select per-client upstreams later in the request processing path, so this internal lookup has no client identity and never reaches that selection logic:
In an isolated race-enabled diagnostic test, a configured client-specific upstream was completely bypassed (zero client lookup and custom-upstream calls), while the global domain-routed upstream handled both A and AAAA lookups:
go test -race -count=1 -run '^TestIssue8420Diagnostic$' ./internal/dnsforward
ok github.com/AdguardTeam/AdGuardHome/internal/dnsforward 1.229s
I do not think silently falling back to bootstrap DNS is safe: an empty
bootstrap configuration receives public defaults, so that could leak private
filter-list hostnames and override an intentional negative answer. Treating
all internal requests as 127.0.0.1 is also ambiguous and could select an
unrelated loopback policy or recurse back into AdGuard Home.
Before preparing a PR, could maintainers choose the intended contract?
- A dedicated internal/self client identity whose custom upstream is used for AdGuard Home's own HTTP requests; or
- A separately configurable resolver for internal/filter-download hostnames.
I can implement either direction with focused coverage for A/AAAA, no-config fallback, global domain routing, configuration replacement/removal, recursion protection, and the hosts-first behavior being added in #8510. I would keep DNS filtering/query logging out of this change because that is the separate scope of #6388.