Skip to content

MagicDNS domains don't get registered as expected in WSL /etc/resolv.conf #775

Closed

Description

@apenwarr

Version: 1.1.424 (Windows)

Steps:

  • Install WSL1 (Windows Subsystem for Linux, version 1. I haven't tested version 2 but I suspect it might be the same)
  • Enable MagicDNS
  • From the cmd.exe prompt, try ping <node1> (a valid nodename in MagicDNS)
  • Notice that the lookup works as expected
  • Enter a WSL1 console
  • Try ping <node1>

Expected:

  • The name lookup works like it did in cmd.exe

Actual:

  • No such hostname

In /etc/resolv.conf, I found this:

# This file was automatically generated by WSL. To stop automatic generation of 
this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver <my router's DNS server>
nameserver 100.100.100.100
nameserver fec0:0:0:ffff::1
search <my router's DNS domain> <the first search domain set in the tailscale admin panel> ts.tailscale.com

The search list should also contain the MagicDNS domain. Adding it by hand makes the name lookup work, but slowly.

The <my router's DNS server> entry also should not be present. Commenting it out fixes the slowness. If that's not possible, another option might be to have the global tailscale.net domain respond with NS records pointing at 100.100.100.100 I guess? But that wouldn't work well for non-tailscale.net magicdns domains that we want to support eventually.

Activity

  1. added
    OS-windows
    L5 All users
    P2 Aggravating
    on Sep 22, 2020
  2. chancecarey commented on Mar 22, 2021

    @chancecarey

    Same issue with WSL2.

  3. crawshaw commented on Jun 12, 2021

    @crawshaw
    Contributor

    I attempted the "obvious" fix for this in https://github.com/tailscale/tailscale/tree/crawshaw/magicdnsalways, making 100.100.100.100 resolve shortened magicdns names directly without the OS having to add a search prefix.

    Unfortunately that doesn't work any more now we do split DNS using the OS API. If we want to fix this WSL2 bug, and I think we do, then we should consider going back to setting the OS blanket DNS to 100.100.100.100 and implementing the OS DNS settings there ourselves.

  4. crawshaw commented on Jun 12, 2021

    @crawshaw
    Contributor
  5. apenwarr commented on Jun 12, 2021

    @apenwarr
    MemberAuthor
  6. crawshaw commented on Jun 12, 2021

    @crawshaw
    Contributor

    That's exactly what I described.

    If we go back to setting the Windows host OS DNS to 100.100.100.100, the patch I linked to fixes WSL2. (Probably WSL1 too.) The problem is we gave up our global OS hook with split DNS, instead we started telling the OS how to cleverly avoid us, and WSL{,2} completely ignores the clever OS settings.

  7. apenwarr commented on Jun 12, 2021

    @apenwarr
    MemberAuthor
  8. crawshaw commented on Jun 12, 2021

    @crawshaw
    Contributor

    We only recently started being fancy, but we never had the commit I linked to above.

    In the past we relied on the OS to set search path prefixes, which WSL does not inherit from the host windows OS. What I changed is you can now directly dig <shortname> @100.100.100.100 and it internally appends the MagicDNS suffix for domains that have only one component. It's a bit of a hack, but one I think with some work we can make reliable.

  9. apenwarr commented on Jun 12, 2021

    @apenwarr
    MemberAuthor

    Oh, I see. I didn't realize that was on the table (or that resolvers would even work with it). Although now that I'm thinking of it, now I'm having deja vu that maybe we used to do that in Nitix.

    It's quite possibly a major DNS spec violation, so we might want to look carefully. For example, what should happen if we have a one-element hostname that overlaps with a TLD?

    If it works though and we can figure out the edge cases, this might be approach I can get behind.

    cc: @danderson for the voice of realism :)

  10. mnordhoff commented on Jun 12, 2021

    @mnordhoff

    DNSMasq and IIRC systemd-resolved support doing the same thing. So it has precedent and, presumably, doesn't cause massive problems for most users.

    (I'm a DNS purist and it makes me uncomfortable, but I'm not gonna complain.)

  11. danderson commented on Jun 13, 2021

    @danderson
    Member

    I'm uncomfortable doing this.

    • The philosophical reason: this is violating what a DNS resolver is required to do. When we receive a DNS question for the FQDN foo., we are not at liberty to interpret that as "maybe you meant foo plus whatever I feel like". We are required to respond to the question as phrased, and the correct response is NXDOMAIN.
      • systemd-resolved would appear to do this, but it does not. It only does search path expansion and other single-label special treatment (e.g. delegation to LLMNR) when queried through non-DNS APIs where it is expected to do that work. It does not do this when queried through 127.0.0.53.
    • Doing this breaks dnssec validation, because the record contents and associated names no longer match. We'd have to implement dnssec validation in quad-100 to work around that, and, um, please, no.
    • Reconfiguring the resolver in this way still results in incorrect behavior in WSL, because quad-100 doesn't apply the split-DNS policies configured within Windows. We'll end up with WSL having access to a subset of the DNS resolutions available to its host, which will just lead to more bug reports. Right now, we're broken in WSL exactly as much as other Windows DNS facilities are.
    • We already have a viable workaround for WSL users, which is to override resolv.conf and point it manually to quad-100 with their desired configuration. Given that we already have an option that has users explicitly acknowledge the shortcomings of WSL, I'd rather not make too many compromises on correctness in the pursuit of another fix.

    Trying to mangle the host's configuration in the hopes that WSL will happen to extract some random subset of the configuration that happens to work is not a viable option, IMO. The evolution of how WSL configures DNS over time tells me that we'll forever be chasing the latest change, trying to trick it into installing the right config.

    To make this work right, we need to either have the host tailscaled be aware of WSL containers and manage their DNS config itself (in which case we can set up something similar to exit node DNS routing, and make WSL DNS fully work the way it should), or have Microsoft fix their operating system. Neither of these are very satisfying options, but I would rather have WSL remain "broken due to OS limitations, with a known workaround" than implement this hack.

  12. 2 remaining items

  13. crawshaw commented on Jun 13, 2021

    @crawshaw
    Contributor

    I took at a look at how DNS works on windows and it looks like implementing a stub resolver is gluing registry keys together. I'll give it a try tomorrow.

  14. danderson commented on Jun 13, 2021

    @danderson
    Member

    Alternatively to quad100+1: can we identify that requests are coming from a WSL container? Combined with patching the container's resolv.conf to point at quad-100 (which already tries to adopt a mostly-correct configuration even in split-DNS mode, as a WSL workaround), I think I'm more okay implementing what you suggested if it's limited to just WSL - so we can keep the sadness limited to just WSL, at least.

  15. crawshaw commented on Jun 13, 2021

    @crawshaw
    Contributor

    Indeed that may be possible because of the vEth that WSL uses. I’ll investigate that.

    One nice thing about quad100+1 is that while it’s a hack, it’s a consistent cross-platform hack, so it may be better to go that way. A particularly easy impl I’m going to try: do the magicdns single element host check, and if it’s not, forward to quad100.

  16. danderson commented on Jun 13, 2021

    @danderson
    Member

    Note that quad100 doesn't have the full split-DNS config from windows (stuff potentially added by Active Directory admins), because currently we assume that Windows will have peeled those off before sending to us. So, forwarding to quad100 won't get you exactly the behavior of resolving the name on Windows - though it'll probably get you something close enough for non-enterprise users.

  17. crawshaw commented on Jun 13, 2021

    @crawshaw
    Contributor

    It would be reasonably easy to extract all search domains from the registry. Perhaps quad100+1 should be: forward to quad100, trying every OS search domain?

  18. danderson commented on Jun 13, 2021

    @danderson
    Member

    So, the bit that's missing from quad100 isn't that, rather it's the NRPT (Name Resolution Policy Table) rules that admins can install. They're how Windows implements split-DNS at the OS level, and it supports more stuff than merely "use this different DNS resolver for this domain". It also has a whole host of stuff related to access to remote device management infrastructure over some kind of whacky auto-IPSec based thing that ships in Windows, which is allegedly popular with enterprise Windows admins - think BeyondCorp but only works for device management stuff. AFAICT, we can't simply extract those rules and do something reasonable with them in quad-100, they only kick in and work if we ask the OS to resolve names for us.

    So, to get 100% the same behavior inside WSL as outside, the plumbing we need is to have something like quad100+1, but it delegates to whatever win32 name resolution API exists, which would correctly hook up all this NRPT nonsense and give correct answers.

    Alternatively, if we forward to quad100 and do as you suggest, filling out each search path in order - that works, but means WSL containers will only get acces to the "default" resolver + MagicDNS, not the full Windows DNS configuration. With a bunch of extra work, we could extract the NRPT rules that only deal with normal DNS resolvers, and install those as split-DNS configs in quad100, but we'd still be missing the more advanced NRPT rules that we can't reimplement without being the OS.

  19. crawshaw commented on Jun 13, 2021

    @crawshaw
    Contributor

    Well that points at what I started doing, which is implement a stub resolver directly on the go resolver. Unfortunately the opinionated high level api of the net package makes it hard to map values back properly. I’ll dig into what actual win32 calls happen underneath.

  20. danderson commented on Jun 13, 2021

    @danderson
    Member

    Yeah, the net package resolver isn't well suited to the subtle things we're trying to do.

    To get off the ground, pointing statically at today's quad-100 and populating search paths in resolv.conf from outside WSL would get us roughly "the not-quite-right thing WSL did before, plus MagicDNS". Maybe that's enough and I'm wrong about folks then blaming us for the remaining long-tail things not working.

  21. added 4 commits that reference this issue on Jun 26, 2021
    ff6ee7d
    4d1ae05
    f7253f5
    fb2ac01
  22. added a commit that references this issue on Jun 28, 2021
    1147c7f
  23. changed the title [-]MagicDNS domains don't get registered as expected in WSL1 /etc/resolv.conf[/-] [+]MagicDNS domains don't get registered as expected in WSL /etc/resolv.conf[/+] on Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L5 All usersOS-windowsP2 AggravatingT6 Major usabilitydns

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions