From ca8bca98edca4dced2331071ef67fa0e0b0d0942 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 31 Oct 2022 16:26:18 +0100 Subject: [PATCH] Add support for "override local DNS" (#905) * Add support for "override local DNS" Signed-off-by: Kristoffer Dalby * Update changelog Signed-off-by: Kristoffer Dalby * Update cli dump test Signed-off-by: Kristoffer Dalby Signed-off-by: Kristoffer Dalby --- CHANGELOG.md | 1 + config-example.yaml | 3 +++ config.go | 10 +++++++++- integration_test/etc/alt-config.dump.gold.yaml | 1 + integration_test/etc/alt-config.yaml | 1 + integration_test/etc/alt-env-config.dump.gold.yaml | 1 + integration_test/etc/alt-env-config.yaml | 1 + integration_test/etc/config.dump.gold.yaml | 1 + integration_test/etc/config.yaml | 1 + 9 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb90e957..aa993fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Add config flag to allow Headscale to start if OIDC provider is down [#829](https://github.com/juanfont/headscale/pull/829) - Random node DNS suffix only applied if names collide in namespace. [#766](https://github.com/juanfont/headscale/issues/766) - Remove `ip_prefix` configuration option and warning [#899](https://github.com/juanfont/headscale/pull/899) +- Add `dns_config.override_local_dns` option [#905](https://github.com/juanfont/headscale/pull/905) - Fix some DNS config issues [#660](https://github.com/juanfont/headscale/issues/660) ## 0.16.4 (2022-08-21) diff --git a/config-example.yaml b/config-example.yaml index 5dec5353..c23c7428 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -192,6 +192,9 @@ acl_policy_path: "" # - https://tailscale.com/blog/2021-09-private-dns-with-magicdns/ # dns_config: + # Whether to prefer using Headscale provided DNS or use local. + override_local_dns: true + # List of DNS servers to expose to clients. nameservers: - 1.1.1.1 diff --git a/config.go b/config.go index 056d93f0..e38a9f2a 100644 --- a/config.go +++ b/config.go @@ -160,6 +160,7 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("log.format", TextLogFormat) viper.SetDefault("dns_config", nil) + viper.SetDefault("dns_config.override_local_dns", true) viper.SetDefault("derp.server.enabled", false) viper.SetDefault("derp.server.stun.enabled", true) @@ -377,6 +378,8 @@ func GetDNSConfig() (*tailcfg.DNSConfig, string) { if viper.IsSet("dns_config") { dnsConfig := &tailcfg.DNSConfig{} + overrideLocalDNS := viper.GetBool("dns_config.override_local_dns") + if viper.IsSet("dns_config.nameservers") { nameserversStr := viper.GetStringSlice("dns_config.nameservers") @@ -399,7 +402,12 @@ func GetDNSConfig() (*tailcfg.DNSConfig, string) { } dnsConfig.Nameservers = nameservers - dnsConfig.Resolvers = resolvers + + if overrideLocalDNS { + dnsConfig.Resolvers = resolvers + } else { + dnsConfig.FallbackResolvers = resolvers + } } if viper.IsSet("dns_config.restricted_nameservers") { diff --git a/integration_test/etc/alt-config.dump.gold.yaml b/integration_test/etc/alt-config.dump.gold.yaml index 9df870fa..c30b1ae7 100644 --- a/integration_test/etc/alt-config.dump.gold.yaml +++ b/integration_test/etc/alt-config.dump.gold.yaml @@ -14,6 +14,7 @@ derp: urls: - https://controlplane.tailscale.com/derpmap/default dns_config: + override_local_dns: true base_domain: headscale.net domains: [] magic_dns: true diff --git a/integration_test/etc/alt-config.yaml b/integration_test/etc/alt-config.yaml index 837ba6c8..df776ea3 100644 --- a/integration_test/etc/alt-config.yaml +++ b/integration_test/etc/alt-config.yaml @@ -8,6 +8,7 @@ ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 dns_config: + override_local_dns: true base_domain: headscale.net magic_dns: true domains: [] diff --git a/integration_test/etc/alt-env-config.dump.gold.yaml b/integration_test/etc/alt-env-config.dump.gold.yaml index 2fa8ef44..5b9297a1 100644 --- a/integration_test/etc/alt-env-config.dump.gold.yaml +++ b/integration_test/etc/alt-env-config.dump.gold.yaml @@ -14,6 +14,7 @@ derp: urls: - https://controlplane.tailscale.com/derpmap/default dns_config: + override_local_dns: true base_domain: headscale.net domains: [] magic_dns: true diff --git a/integration_test/etc/alt-env-config.yaml b/integration_test/etc/alt-env-config.yaml index 3856048d..392be6ab 100644 --- a/integration_test/etc/alt-env-config.yaml +++ b/integration_test/etc/alt-env-config.yaml @@ -8,6 +8,7 @@ ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 dns_config: + override_local_dns: true base_domain: headscale.net magic_dns: true domains: [] diff --git a/integration_test/etc/config.dump.gold.yaml b/integration_test/etc/config.dump.gold.yaml index 7bdd2c3e..3370ad99 100644 --- a/integration_test/etc/config.dump.gold.yaml +++ b/integration_test/etc/config.dump.gold.yaml @@ -14,6 +14,7 @@ derp: urls: - https://controlplane.tailscale.com/derpmap/default dns_config: + override_local_dns: true base_domain: headscale.net domains: [] magic_dns: true diff --git a/integration_test/etc/config.yaml b/integration_test/etc/config.yaml index 8b4d7db1..efe75fec 100644 --- a/integration_test/etc/config.yaml +++ b/integration_test/etc/config.yaml @@ -8,6 +8,7 @@ ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 dns_config: + override_local_dns: true base_domain: headscale.net magic_dns: true domains: []