[PR #2959] fix: DNS resolver config respects MagicDNS superseding override_local_dns #2965

Open
opened 2025-12-29 04:19:51 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/juanfont/headscale/pull/2959
Author: @roganlynch
Created: 12/12/2025
Status: 🔄 Open

Base: mainHead: fix/dns-override-local-2899


📝 Commits (2)

  • 62a306e Squashed Commit for Fix of issue 2899
  • 05e9911 Merge branch 'main' into fix/dns-override-local-2899

📊 Changes

9 files changed (+767 additions, -9 deletions)

View changed files

📝 config-example.yaml (+16 -2)
📝 hscontrol/types/config.go (+87 -6)
📝 hscontrol/types/config_test.go (+128 -1)
hscontrol/types/testdata/dns_global_without_override.yaml (+20 -0)
hscontrol/types/testdata/dns_override_false_with_split.yaml (+29 -0)
hscontrol/types/testdata/dns_split_no_fallback_error.yaml (+20 -0)
hscontrol/types/testdata/dns_split_with_fallback.yaml (+30 -0)
hscontrol/types/testdata/dns_split_without_fallback.yaml (+26 -0)
📝 integration/dns_test.go (+411 -0)

📄 Description

Fixes #2899

Summary

This PR fixes the inconsistent DNS resolver behavior reported in issue #2899. The core issue was that DNS resolvers were not being sent correctly based on the override_local_dns setting.

Changes

Root Cause

When override_local_dns=false, the code was incorrectly setting FallbackResolvers instead of Resolvers. FallbackResolvers are only used when primary DNS fails, causing DNS to never work.

The Fix

Updated dnsToTailcfgDNS() in hscontrol/types/config.go to implement the correct logic:

  • MagicDNS supersedes override_local_dns: When MagicDNS is enabled, always send Resolvers
  • When MagicDNS is disabled:
    • override_local_dns=true → Send Resolvers
    • override_local_dns=false/unset → No Resolvers (clients use local DNS)

Behavior Matrix

MagicDNS override_local_dns Resolvers Sent?
true true/false/unset Always
false true Yes
false false/unset No

Testing

  • Updated unit tests in hscontrol/types/config_test.go
  • Added comprehensive integration tests in integration/dns_override_local_test.go
  • All unit tests pass

Files Changed

  • hscontrol/types/config.go: Fixed DNS configuration logic
  • hscontrol/types/config_test.go: Updated test expectations
  • integration/dns_override_local_test.go: Added integration tests

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/juanfont/headscale/pull/2959 **Author:** [@roganlynch](https://github.com/roganlynch) **Created:** 12/12/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/dns-override-local-2899` --- ### 📝 Commits (2) - [`62a306e`](https://github.com/juanfont/headscale/commit/62a306ed506de9d613192ded6db99dfbc3bed8fb) Squashed Commit for Fix of issue 2899 - [`05e9911`](https://github.com/juanfont/headscale/commit/05e991180f076303f0b4ac5d9ddc49232a561d77) Merge branch 'main' into fix/dns-override-local-2899 ### 📊 Changes **9 files changed** (+767 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `config-example.yaml` (+16 -2) 📝 `hscontrol/types/config.go` (+87 -6) 📝 `hscontrol/types/config_test.go` (+128 -1) ➕ `hscontrol/types/testdata/dns_global_without_override.yaml` (+20 -0) ➕ `hscontrol/types/testdata/dns_override_false_with_split.yaml` (+29 -0) ➕ `hscontrol/types/testdata/dns_split_no_fallback_error.yaml` (+20 -0) ➕ `hscontrol/types/testdata/dns_split_with_fallback.yaml` (+30 -0) ➕ `hscontrol/types/testdata/dns_split_without_fallback.yaml` (+26 -0) 📝 `integration/dns_test.go` (+411 -0) </details> ### 📄 Description Fixes #2899 ## Summary This PR fixes the inconsistent DNS resolver behavior reported in issue #2899. The core issue was that DNS resolvers were not being sent correctly based on the `override_local_dns` setting. ## Changes ### Root Cause When `override_local_dns=false`, the code was incorrectly setting `FallbackResolvers` instead of `Resolvers`. FallbackResolvers are only used when primary DNS fails, causing DNS to never work. ### The Fix Updated `dnsToTailcfgDNS()` in `hscontrol/types/config.go` to implement the correct logic: - **MagicDNS supersedes override_local_dns**: When MagicDNS is enabled, always send Resolvers - When MagicDNS is disabled: - `override_local_dns=true` → Send Resolvers - `override_local_dns=false/unset` → No Resolvers (clients use local DNS) ### Behavior Matrix | MagicDNS | override_local_dns | Resolvers Sent? | |----------|-------------------|-----------------| | true | true/false/unset | ✅ Always | | false | true | ✅ Yes | | false | false/unset | ❌ No | ## Testing - ✅ Updated unit tests in `hscontrol/types/config_test.go` - ✅ Added comprehensive integration tests in `integration/dns_override_local_test.go` - ✅ All unit tests pass ## Files Changed - `hscontrol/types/config.go`: Fixed DNS configuration logic - `hscontrol/types/config_test.go`: Updated test expectations - `integration/dns_override_local_test.go`: Added integration tests --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 04:19:51 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#2965