ISSUE DESCRIPTION No split dns registered with the OS with an app connector. What is the…
- User
ISSUE DESCRIPTION
No split dns registered with the OS with an app connector.
What is the issue?
It's possible to have an app connector but tailscale fails to register split dns with the OS to route dns requests to it.
Steps to reproduce
Linux w/ systemd-resolved Turn off MagicDNS No global dns fallback results in Tailscale not being used for DNS by the operating system
Are there any recent changes that introduced the issue?
No response
OS
No response
OS version
No response
Tailscale version
No response
Other software
No response
Bug report
No response
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Assistant
Let me analyze the issue. The problem is about split DNS not being registered with the OS when using an app connector with MagicDNS turned off and no global DNS fallback. This is a Tailscale repository, so I need to explore the codebase to understand how DNS registration works and find where the bug might be.
Let me start by exploring the repository structure.
Assistant
I need to explore the repository structure to understand the DNS-related code. Let me look for DNS-related files.
Assistant
Let me look for the DNS and app connector related code more specifically. The issue mentions:
- App connector
- Split DNS not registered
- MagicDNS turned off
- No global DNS fallback
- Linux with systemd-resolved
Let me look for DNS-related code in the network stack or DNS directory.
Assistant
I see there's an
appcdirectory which is likely related to "app connector". Let me explore that and also look for DNS-related code in thenet/dnsdirectory.Assistant
The user wants me to fix an issue where split DNS is not being registered with the OS when using an app connector with MagicDNS turned off and no global DNS fallback on Linux with systemd-resolved.
Let me explore the codebase more to understand how DNS registration works.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /tailscale/net/dns/ </tool_call>
Assistant
Let me explore the net/dns directory to understand how DNS registration works.
Assistant
Let me look at the key DNS files and the app connector code:
Assistant
Now let me look at the manager.go file which contains the DNS manager logic.
Assistant
Let me see the rest of the manager.go file to understand the compileConfig function better. The file was truncated.
Assistant
Let me continue reading the compileConfig function:
Assistant
Let me see the rest of the compileConfig function and the manager_linux.go file for understanding how systemd-resolved is handled.
Assistant
Now let me look at the systemd-resolved implementation and the manager_linux.go:
Assistant
Now let me look at the manager_linux.go to understand how the DNS manager is set up on Linux:
Assistant
Now let me look at the app connector code:
Assistant
Let me look at where DNS configuration is generated and how app connectors integrate with the DNS system:
Assistant
Let me search for where DNS config is built for the OS with app connectors:
Assistant
Let me look at the DNS configuration code in ipnlocal to understand how DNS is generated:
Assistant
Let me look at the DNS configuration logic in ipnlocal/local.go:
Assistant
Let me look at the DNS configuration file:
Assistant
Let me look for how DNS config is generated. The
dnsConfigForNetmapfunction seems to be the key one:Assistant
Let me search for where
dnsConfigForNetmapis defined:Assistant
Let me look at the node_backend.go file to understand how DNS configuration is created.
Assistant
Now I understand the codebase much better. Let me examine the key file where DNS configuration is generated and also look at how app connectors contribute to split DNS routing:
Assistant
Let me look at the git log for recent changes related to DNS and app connectors:
Assistant
Now I have a good understanding of the issue. Let me look at the specific DNS config generation code in node_backend.go more closely:
Assistant
Now I have a good understanding of the codebase. Let me trace through the issue:
-
When an app connector is used with MagicDNS turned off and no global DNS fallback, the
dnsConfigForNetmapfunction adds split DNS routes with DoH (DNS over HTTPS) resolvers. -
In
compileConfiginmanager.go, whensingleResolverSet()returns a non-empty result (all routes use the same resolvers), the code setsocfg.Nameservers = toIPsOnly(cfg.singleResolverSet()). -
However,
toIPsOnly()only converts resolvers that are IP:port format (port 53). For DoH URLs likehttps://<peer_ip>:4160/dns-query,toIPsOnly()returns an empty slice. -
This results in
ocfg.Nameserversbeing empty, so systemd-resolved doesn't register any DNS routing for the app connector domains.
Let me verify this is the issue by examining the specific code path:
-
Assistant
Now I understand the issue. Let me look at the key code paths more carefully to understand the exact fix needed:
Assistant
Now I understand the issue. Let me trace through the exact code path:
-
When using an app connector with MagicDNS off and no global DNS fallback:
dnsConfigForNetmapadds split DNS routes with DoH resolvers (https://peer_ip:4160/dns-query)- No
DefaultResolversare set
-
In
compileConfig, the code takes the optimization path for OSes that support split DNS:goif len(cfg.singleResolverSet()) > 0 && m.os.SupportsSplitDNS() && !isWindows && !isApple { ocfg.Nameservers = toIPsOnly(cfg.singleResolverSet()) ocfg.MatchDomains = cfg.matchDomains() } -
The bug:
toIPsOnly()only returns IPs for port-53 resolvers. DoH URLs (likehttps://...) are filtered out, resulting in an emptyNameserverslist. -
This leaves systemd-resolved with routing-only domains but no nameservers, which doesn't work properly.
The fix is to check whether the single resolver set contains any port-53 IP resolvers. If not, we should fall through to the quad-100 resolver path where the internal resolver can handle DoH.
-
Assistant
Now I fully understand the issue. Let me trace through the complete code path:
-
When an app connector is used with MagicDNS off and no global DNS fallback:
dnsConfigForNetmapadds split DNS routes with DoH resolvers (https://peer_ip:4160/dns-query)- No
DefaultResolversare set
-
In
compileConfig, there's a fast path optimization for systemd-resolved:goif len(cfg.singleResolverSet()) > 0 && m.os.SupportsSplitDNS() && !isWindows && !isApple { ocfg.Nameservers = toIPsOnly(cfg.singleResolverSet()) ocfg.MatchDomains = cfg.matchDomains() return rcfg, ocfg, nil } -
The bug:
toIPsOnly()filters out DoH URLs because they aren't port-53 IPs. With only DoH resolvers in the routes, this results in emptyocfg.Nameservers, so systemd-resolved has no nameserver to route DNS queries to. -
The fix: We should only take this optimization path when the single resolver set actually contains port-53 IP resolvers. If all resolvers are DoH (or empty), we should fall through to the quad-100 path where the internal resolver handles them.
-
Assistant
Now I have a full understanding of the issue. Let me summarize and implement the fix.
Summary of the issue:
When using an app connector with MagicDNS turned off and no global DNS fallback on Linux with systemd-resolved, the DNS config contains split DNS routes with DoH resolvers (e.g.,
https://<peer_ip>:4160/dns-query). IncompileConfig, there's an optimization path that detects when all routes use the same resolver:goif len(cfg.singleResolverSet()) > 0 && m.os.SupportsSplitDNS() && !isWindows && !isApple { ocfg.Nameservers = toIPsOnly(cfg.singleResolverSet()) ocfg.MatchDomains = cfg.matchDomains() return rcfg, ocfg, nil }The bug is that
toIPsOnly()only returns port-53 IP addresses, filtering out DoH URLs. When all resolvers are DoH (as is the case with app connectors),Nameserversbecomes empty, so systemd-resolved has no nameserver to route DNS queries to.The fix:
Only take the OS split-DNS optimization path when the single resolver set actually contains port-53 IP resolvers. If all resolvers are DoH, fall through to the quad-100 path where the internal resolver handles them.
Assistant
Let me implement the fix. The issue is in the
compileConfigfunction where the optimization path takes even when all resolvers are DoH (not port-53 IPs), resulting in emptyNameservers.Assistant
Now I understand the issue completely. Let me apply the fix.
Assistant
Now I understand the issue. Let me apply the fix.
Assistant
Now I understand the issue. The problem is in
compileConfigwhere it takes an optimization path for split DNS even when the resolvers are DoH URLs (not port-53 IPs). WhentoIPsOnly()filters out DoH resolvers, theNameserversbecomes empty, and systemd-resolved has no nameserver configured.The fix is to check that the single resolver set actually contains port-53 IP resolvers before taking this optimization path. Let me implement this:
Assistant
I see the edit introduced duplicate lines. Let me fix that properly:
Assistant
I see the edit introduced duplicate lines. Let me fix this properly.
Assistant
Now I need to look at the original file again and make the edit properly this time. The issue is that I need to replace the lines 370-376 with the new code that checks for port-53 IP resolvers before taking the optimization path.
Let me first look at the exact lines I need to modify.
Assistant
I need to edit the file to fix the issue. Let me use the replace command to make the fix properly:
Assistant
Let me try the edit command properly:
Assistant
Let me look at the current file state and use the proper edit syntax to make the fix. I need to replace lines 370-376 with new code that checks for port-53 IP resolvers before taking the split DNS optimization path.
Assistant
The issue is that I need to edit lines 370-376 to check if the single resolver set contains port-53 IP resolvers before taking the split DNS optimization path. If the resolvers are DoH URLs (like from app connectors), we should fall through to the quad-100 path.
Let me use the bash terminal to make the edit using sed or a more direct approach.
Assistant
Let me use the edit command with the proper indentation for the fix.
Assistant
Let me try a different approach using a Python script to make the edit:
Assistant
Let me verify the edit was applied correctly:
Assistant
The edit was applied correctly. Now let me verify the fix by checking if the code compiles and running the existing tests.
Assistant
Let me set up the Go environment and try building again.
Assistant
Let me set up all necessary Go environment variables.
Assistant
The code compiles successfully. Now let me run the existing tests for the DNS package to make sure the fix doesn't break anything:
Assistant
Let me wait for the full test results:
Assistant
All DNS tests pass. Let me also run the tests for the related ipnlocal package to make sure the DNS configuration generation still works:
Assistant
All DNS tests pass. Let me also verify the fix by looking at the final diff:
Assistant
The fix looks good. Let me run a broader set of tests to ensure nothing is broken:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.