Skip to content

net/dns/resolver: upgrade forwarded MagicDNS queries to DoH when IP known#2435

Merged
bradfitz merged 1 commit intomainfrom
bradfitz/doh
Jul 15, 2021
Merged

net/dns/resolver: upgrade forwarded MagicDNS queries to DoH when IP known#2435
bradfitz merged 1 commit intomainfrom
bradfitz/doh

Conversation

@bradfitz
Copy link
Copy Markdown
Member

@bradfitz bradfitz commented Jul 15, 2021

Recognize Cloudflare, Google, Quad9 which are by far the
majority of upstream DNS servers that people use.

RELNOTE=MagicDNS now uses DNS-over-HTTPS when querying popular upstream resolvers,
so DNS queries aren't sent in the clear over the Internet.

Updates #915 (might fix it?)
Updates #988 (gets us closer, if it fixes Android)
Updates #74 (not yet configurable, but progress)
Updates #2056 (not yet configurable, dup of #74?)

Copy link
Copy Markdown
Contributor

@crawshaw crawshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adding DoH targets via the control plane future work?

@bradfitz bradfitz force-pushed the bradfitz/doh branch 2 times, most recently from cbe8e4a to d3e62df Compare July 15, 2021 17:17
@bradfitz
Copy link
Copy Markdown
Member Author

Is adding DoH targets via the control plane future work?

Yeah. That requires more plumbing. I linked a bunch of those bugs in the commit message now.

if err != nil {
return nil, err
}
req.Header.Set("Content-Type", dohType)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setting both Accept and Content-Type would be good

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it included in examples (https://datatracker.ietf.org/doc/html/rfc8484#page-5) but looks like the Accept one is pretty optional, though:

The DoH client SHOULD include an HTTP Accept request header field to
indicate what type of content can be understood in response.
Irrespective of the value of the Accept request header field, the
client MUST be prepared to process "application/dns-message"

(and empirically isn't required by any provider)

Worth the bandwidth? With HTTP/2 it's not much, but iOS doesn't use HTTP/2 yet so it's a bit more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code with comment:

diff --git a/net/dns/resolver/forwarder.go b/net/dns/resolver/forwarder.go
index 8a15c099..a3184f8c 100644
--- a/net/dns/resolver/forwarder.go
+++ b/net/dns/resolver/forwarder.go
@@ -259,6 +259,12 @@ func (f *forwarder) sendDoH(ctx context.Context, urlBase string, c *http.Client,
                return nil, err
        }
        req.Header.Set("Content-Type", dohType)
+       // Note: we don't currently set the Accept header (which is
+       // only a SHOULD in the spec) as iOS doesn't use HTTP/2 and
+       // we'd rather save a few bytes on outgoing requests when
+       // empirically no provider cares about the Accept header's
+       // absence.
+
        hres, err := c.Do(req)
        if err != nil {
                return nil, err

…nown

Recognize Cloudflare, Google, Quad9 which are by far the
majority of upstream DNS servers that people use.

RELNOTE=MagicDNS now uses DNS-over-HTTPS when querying popular upstream resolvers,
so DNS queries aren't sent in the clear over the Internet.

Updates #915 (might fix it?)
Updates #988 (gets us closer, if it fixes Android)
Updates #74 (not yet configurable, but progress)
Updates #2056 (not yet configurable, dup of #74?)

Signed-off-by: Brad Fitzpatrick <[email protected]>
@bradfitz
Copy link
Copy Markdown
Member Author

Okay, fair. It's in a section talking about improving HTTP cache behavior, which POST obliterates anyway so
that's probably fine.

The whole cache part of the spec is super weird. There aren't going to be rando cache intermediates here and Google et al aren't using rando off-the-shelf HTTP caches in front of their DNS servers. Any caching they're doing is part of the application layer after it's parsed the HTTP framing.

@bradfitz bradfitz merged commit 236eb4d into main Jul 15, 2021
@bradfitz bradfitz deleted the bradfitz/doh branch July 15, 2021 19:03
@sreeram-dev
Copy link
Copy Markdown

Is it possible to support nextdns.io? Some of the power users have custom blocklists and adblock lists. DNS-Over-HTTPS with magicDNS and nextDNS nameservers would be a great addition.

@DentonGentry
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants