mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-19 11:57:07 +09:00
config: keep every default in Default
The DNS-01 challenge resolvers, dns.challenge.resolvers, now default to Quad9 (9.9.9.9:53, 149.112.112.112:53) instead of Cloudflare and Google. Updates #1926
This commit is contained in:
1 parent
d835c9c6bf
commit
90de2ed00d
28 files changed
+198
-118
No files matched your search
@@ -48,7 +48,10 @@ func Default() types.Config {
|
||||
OverrideLocalDNS: true,
|
||||
Nameservers: types.Nameservers{Global: []string{}, Split: map[string][]string{}},
|
||||
SearchDomains: []string{},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute},
|
||||
Challenge: types.DNSChallengeConfig{
|
||||
PropagationTimeout: 2 * time.Minute,
|
||||
Resolvers: types.DefaultChallengeResolvers(),
|
||||
},
|
||||
},
|
||||
TLS: types.TLSConfig{ACME: types.ACMEConfig{
|
||||
ChallengeType: types.HTTP01ChallengeType,
|
||||
@@ -68,6 +71,8 @@ func Default() types.Config {
|
||||
NodeMapSessionBufferedChanSize: 30,
|
||||
NodeStoreBatchSize: 100,
|
||||
NodeStoreBatchTimeout: 500 * time.Millisecond,
|
||||
RegisterCacheExpiration: 15 * time.Minute,
|
||||
RegisterCacheMaxEntries: 1024,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -28,6 +29,21 @@ func validConfig() types.Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// TestDefaultHoldsDefaults: the defaults consumers fall back to for a zero
|
||||
// value are Default's, so the loaded configuration shows them.
|
||||
func TestDefaultHoldsDefaults(t *testing.T) {
|
||||
d := Default()
|
||||
assert.Equal(t, 15*time.Minute, d.Tuning.RegisterCacheExpiration)
|
||||
assert.Equal(t, 1024, d.Tuning.RegisterCacheMaxEntries)
|
||||
assert.Equal(t, 100, d.Tuning.NodeStoreBatchSize)
|
||||
assert.Equal(t, 500*time.Millisecond, d.Tuning.NodeStoreBatchTimeout)
|
||||
assert.Zero(t, d.Tuning.BatcherWorkers, "auto: its count depends on the host")
|
||||
require.Equal(t, []string{"9.9.9.9:53", "149.112.112.112:53"}, d.DNSConfig.Challenge.Resolvers)
|
||||
|
||||
d.DNSConfig.Challenge.Resolvers[0] = "changed"
|
||||
assert.Equal(t, "9.9.9.9:53", Default().DNSConfig.Challenge.Resolvers[0], "each Default is its own copy")
|
||||
}
|
||||
|
||||
// TestValidateHintsNameDefaults: the defaults Validate's hints quote, which
|
||||
// types cannot read from Default, are Default's.
|
||||
func TestValidateHintsNameDefaults(t *testing.T) {
|
||||
|
||||
@@ -1404,7 +1404,7 @@ func plainValue(v reflect.Value, redact bool) any {
|
||||
|
||||
switch x := v.Interface().(type) {
|
||||
case time.Duration:
|
||||
return x.String()
|
||||
return formatDuration(x)
|
||||
case types.Secret:
|
||||
if redact {
|
||||
return x.Redacted()
|
||||
@@ -1480,6 +1480,21 @@ func plainValue(v reflect.Value, redact bool) any {
|
||||
}
|
||||
}
|
||||
|
||||
// formatDuration is d as Go writes it without trailing zero units: 3h,
|
||||
// not 3h0m0s.
|
||||
func formatDuration(d time.Duration) string {
|
||||
s := d.String()
|
||||
|
||||
if t, ok := strings.CutSuffix(s, "m0s"); ok {
|
||||
s = t + "m"
|
||||
if t, ok := strings.CutSuffix(t, "h0"); ok {
|
||||
s = t + "h"
|
||||
}
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func redactProvider(settings map[string]any) map[string]any {
|
||||
out := make(map[string]any, len(settings))
|
||||
for k, v := range settings {
|
||||
|
||||
@@ -912,7 +912,7 @@ func TestPlainMap(t *testing.T) {
|
||||
assert.Contains(t, prefixes, "v6")
|
||||
|
||||
node, _ := plain["node"].(map[string]any)
|
||||
assert.Equal(t, "1h30m0s", node["expiry"])
|
||||
assert.Equal(t, "1h30m", node["expiry"])
|
||||
|
||||
derp, _ := plain["derp"].(map[string]any)
|
||||
assert.Equal(t, []any{
|
||||
@@ -969,6 +969,37 @@ func TestPlainMap(t *testing.T) {
|
||||
assert.NotContains(t, plainProvider, "nothing", "a typed nil is left out")
|
||||
}
|
||||
|
||||
// TestFormatDuration: a duration prints without trailing zero units and
|
||||
// parses back to itself.
|
||||
func TestFormatDuration(t *testing.T) {
|
||||
tests := []struct {
|
||||
d time.Duration
|
||||
want string
|
||||
}{
|
||||
{0, "0s"},
|
||||
{3 * time.Hour, "3h"},
|
||||
{3*time.Hour + 30*time.Minute, "3h30m"},
|
||||
{time.Hour + 30*time.Second, "1h0m30s"},
|
||||
{2 * time.Minute, "2m"},
|
||||
{90 * time.Second, "1m30s"},
|
||||
{800 * time.Millisecond, "800ms"},
|
||||
{1500 * time.Millisecond, "1.5s"},
|
||||
{168 * time.Hour, "168h"},
|
||||
{-5 * time.Second, "-5s"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.want, func(t *testing.T) {
|
||||
got := formatDuration(tt.d)
|
||||
assert.Equal(t, tt.want, got)
|
||||
|
||||
back, err := time.ParseDuration(got)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tt.d, back)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlainMapLargeIntegers: JSON parsers read numbers as float64, so an
|
||||
// integer past 2^53 is written as text, which the integer hook takes back.
|
||||
func TestPlainMapLargeIntegers(t *testing.T) {
|
||||
@@ -1096,7 +1127,7 @@ func TestReadConfig(t *testing.T) {
|
||||
{Name: "prometheus.myvpn.example.com", Type: "A", Value: "100.64.0.4"},
|
||||
},
|
||||
SearchDomains: []string{"test.com", "bar.com"},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute, Resolvers: types.DefaultChallengeResolvers()},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1153,7 +1184,7 @@ func TestReadConfig(t *testing.T) {
|
||||
{Name: "prometheus.myvpn.example.com", Type: "A", Value: "100.64.0.4"},
|
||||
},
|
||||
SearchDomains: []string{"test.com", "bar.com"},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute, Resolvers: types.DefaultChallengeResolvers()},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1337,7 +1368,7 @@ func TestReadConfigFromEnv(t *testing.T) {
|
||||
// {Name: "prometheus.myvpn.example.com", Type: "A", Value: "100.64.0.4"},
|
||||
// },
|
||||
SearchDomains: []string{"test.com", "bar.com"},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute},
|
||||
Challenge: types.DNSChallengeConfig{PropagationTimeout: 2 * time.Minute, Resolvers: types.DefaultChallengeResolvers()},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -2212,7 +2243,7 @@ dns:
|
||||
// CertificateZone follows base_domain even when unused, so it is never empty.
|
||||
wantZone: "ts.example.com",
|
||||
wantNoProv: true,
|
||||
wantResolvers: []string{"1.1.1.1:53", "8.8.8.8:53"},
|
||||
wantResolvers: []string{"9.9.9.9:53", "149.112.112.112:53"},
|
||||
},
|
||||
{
|
||||
name: "resolvers default to port 53",
|
||||
|
||||
@@ -238,6 +238,16 @@ func TestMarshalNullablePrefix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestMarshalDurations: durations print without trailing zero units.
|
||||
func TestMarshalDurations(t *testing.T) {
|
||||
cfg := Default()
|
||||
|
||||
out, err := Marshal(&cfg, ".yaml")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, string(out), "update_frequency: 3h\n")
|
||||
assert.Contains(t, string(out), "revoked_retention: 168h\n")
|
||||
}
|
||||
|
||||
// fakeProvider is a Go-only DNS provider.
|
||||
type fakeProvider struct{ Token string }
|
||||
|
||||
|
||||
+4
-4
@@ -117,8 +117,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -166,8 +166,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -117,8 +117,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -166,8 +166,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -103,8 +103,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -152,8 +152,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -103,8 +103,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -152,8 +152,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -133,8 +133,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -184,8 +184,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -115,8 +115,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": "cloudflare"
|
||||
},
|
||||
@@ -167,8 +167,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -103,8 +103,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -152,8 +152,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -120,8 +120,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -171,8 +171,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -103,8 +103,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -152,8 +152,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -159,8 +159,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -216,8 +216,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -141,8 +141,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -190,8 +190,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -119,8 +119,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -168,8 +168,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -119,8 +119,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -168,8 +168,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -133,8 +133,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -182,8 +182,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -133,8 +133,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -182,8 +182,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -108,8 +108,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -157,8 +157,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
+4
-4
@@ -119,8 +119,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -168,8 +168,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -103,8 +103,8 @@
|
||||
"DNSChallenge": {
|
||||
"PropagationTimeout": 120000000000,
|
||||
"Resolvers": [
|
||||
"1.1.1.1:53",
|
||||
"8.8.8.8:53"
|
||||
"9.9.9.9:53",
|
||||
"149.112.112.112:53"
|
||||
],
|
||||
"ProviderName": ""
|
||||
},
|
||||
@@ -152,8 +152,8 @@
|
||||
"BatchChangeDelay": 800000000,
|
||||
"NodeMapSessionBufferedChanSize": 30,
|
||||
"BatcherWorkers": 0,
|
||||
"RegisterCacheExpiration": 0,
|
||||
"RegisterCacheMaxEntries": 0,
|
||||
"RegisterCacheExpiration": 900000000000,
|
||||
"RegisterCacheMaxEntries": 1024,
|
||||
"NodeStoreBatchSize": 100,
|
||||
"NodeStoreBatchTimeout": 500000000
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ func (s *State) DebugSSHPolicies() map[string]*tailcfg.SSHPolicy {
|
||||
func (s *State) DebugRegistrationCache() map[string]any {
|
||||
return map[string]any{
|
||||
"type": "expirable-lru",
|
||||
"expiration": registerCacheExpiration.String(),
|
||||
"expiration": s.authCacheExpiration.String(),
|
||||
"max_entries": s.authCacheMaxEntries,
|
||||
"ssh_reserve": authCacheSSHReserve,
|
||||
"current_len": s.authCache.Len(),
|
||||
|
||||
@@ -2,8 +2,10 @@ package state
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNodeStoreDebugString(t *testing.T) {
|
||||
@@ -64,15 +66,28 @@ func TestNodeStoreDebugString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestDebugRegistrationCache: the cache reports the expiration NewState
|
||||
// chose, the default for zero.
|
||||
func TestDebugRegistrationCache(t *testing.T) {
|
||||
// Create a minimal NodeStore for testing debug methods
|
||||
store := NewNodeStore(nil, allowAllPeersFunc, TestBatchSize, TestBatchTimeout)
|
||||
tests := []struct {
|
||||
name string
|
||||
set time.Duration
|
||||
want time.Duration
|
||||
}{
|
||||
{name: "configured", set: 20 * time.Minute, want: 20 * time.Minute},
|
||||
{name: "zero is the default", set: 0, want: 15 * time.Minute},
|
||||
}
|
||||
|
||||
debugStr := store.DebugString()
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := persistTestConfig(t.TempDir() + "/headscale.db")
|
||||
cfg.Tuning.RegisterCacheExpiration = tt.set
|
||||
|
||||
// Should contain basic debug information
|
||||
assert.Contains(t, debugStr, "=== NodeStore Debug Information ===")
|
||||
assert.Contains(t, debugStr, "Total Nodes: 0")
|
||||
assert.Contains(t, debugStr, "Users with Nodes: 0")
|
||||
assert.Contains(t, debugStr, "NodeKey Index: 0 entries")
|
||||
s, err := NewState(cfg)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() { require.NoError(t, s.Close()) })
|
||||
|
||||
assert.Equal(t, tt.want.String(), s.DebugRegistrationCache()["expiration"])
|
||||
})
|
||||
}
|
||||
}
|
||||
+12
-26
@@ -26,6 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||
"github.com/juanfont/headscale/hscontrol/config"
|
||||
hsdb "github.com/juanfont/headscale/hscontrol/db"
|
||||
"github.com/juanfont/headscale/hscontrol/derp"
|
||||
"github.com/juanfont/headscale/hscontrol/policy"
|
||||
@@ -49,26 +50,9 @@ import (
|
||||
"tailscale.com/util/truncate"
|
||||
)
|
||||
|
||||
const (
|
||||
// registerCacheExpiration defines how long node registration entries remain in cache.
|
||||
registerCacheExpiration = time.Minute * 15
|
||||
|
||||
// defaultRegisterCacheMaxEntries bounds pending authentication transactions.
|
||||
// Admission refuses new work at capacity instead of invalidating approvals.
|
||||
defaultRegisterCacheMaxEntries = 1024
|
||||
|
||||
// authCacheSSHReserve keeps registered nodes' SSH checks available when
|
||||
// unauthenticated registrations have filled their allocation.
|
||||
authCacheSSHReserve = 64
|
||||
|
||||
// defaultNodeStoreBatchSize is the default number of write operations to batch
|
||||
// before rebuilding the in-memory node snapshot.
|
||||
defaultNodeStoreBatchSize = 100
|
||||
|
||||
// defaultNodeStoreBatchTimeout is the default maximum time to wait before
|
||||
// processing a partial batch of node operations.
|
||||
defaultNodeStoreBatchTimeout = 500 * time.Millisecond
|
||||
)
|
||||
// authCacheSSHReserve keeps registered nodes' SSH checks available when
|
||||
// unauthenticated registrations have filled their allocation.
|
||||
const authCacheSSHReserve = 64
|
||||
|
||||
// ErrUnsupportedPolicyMode is returned for invalid policy modes. Valid modes are "file" and "db".
|
||||
var ErrUnsupportedPolicyMode = errors.New("unsupported policy mode")
|
||||
@@ -252,6 +236,7 @@ type State struct {
|
||||
authCache *expirable.LRU[types.AuthID, *types.AuthRequest]
|
||||
authCacheMu sync.Mutex
|
||||
authCacheMaxEntries int
|
||||
authCacheExpiration time.Duration
|
||||
authCacheClosed bool
|
||||
authCacheRegularEntries atomic.Int64
|
||||
|
||||
@@ -357,9 +342,11 @@ func (s *State) lockRegistration(machineKey key.MachinePublic) func() {
|
||||
// NewState creates and initializes a new [State] instance, setting up the database,
|
||||
// IP allocator, DERP map, policy manager, and loading existing users and nodes.
|
||||
func NewState(cfg *types.Config) (*State, error) {
|
||||
cacheExpiration := cmp.Or(cfg.Tuning.RegisterCacheExpiration, registerCacheExpiration)
|
||||
defaults := config.Default().Tuning
|
||||
|
||||
cacheMaxEntries := defaultRegisterCacheMaxEntries
|
||||
cacheExpiration := cmp.Or(cfg.Tuning.RegisterCacheExpiration, defaults.RegisterCacheExpiration)
|
||||
|
||||
cacheMaxEntries := defaults.RegisterCacheMaxEntries
|
||||
if cfg.Tuning.RegisterCacheMaxEntries > 0 {
|
||||
cacheMaxEntries = cfg.Tuning.RegisterCacheMaxEntries
|
||||
}
|
||||
@@ -440,11 +427,9 @@ func NewState(cfg *types.Config) (*State, error) {
|
||||
return nil, fmt.Errorf("initializing policy manager: %w", err)
|
||||
}
|
||||
|
||||
// Apply defaults for [NodeStore] batch configuration if not set.
|
||||
// This ensures tests that create Config directly (without config.Load) still work.
|
||||
batchSize := cmp.Or(cfg.Tuning.NodeStoreBatchSize, defaultNodeStoreBatchSize)
|
||||
batchSize := cmp.Or(cfg.Tuning.NodeStoreBatchSize, defaults.NodeStoreBatchSize)
|
||||
|
||||
batchTimeout := cmp.Or(cfg.Tuning.NodeStoreBatchTimeout, defaultNodeStoreBatchTimeout)
|
||||
batchTimeout := cmp.Or(cfg.Tuning.NodeStoreBatchTimeout, defaults.NodeStoreBatchTimeout)
|
||||
|
||||
nodeStore := NewNodeStore(nodes, policyPeersFunc(polMan), batchSize, batchTimeout)
|
||||
polMan.SetRouterSession(nodeStore.RouterSession)
|
||||
@@ -460,6 +445,7 @@ func NewState(cfg *types.Config) (*State, error) {
|
||||
ipAlloc: ipAlloc,
|
||||
polMan: polMan,
|
||||
authCacheMaxEntries: cacheMaxEntries,
|
||||
authCacheExpiration: cacheExpiration,
|
||||
nodeStore: nodeStore,
|
||||
pings: newPingTracker(),
|
||||
|
||||
|
||||
@@ -38,11 +38,13 @@ var (
|
||||
ErrInvalidAllocationStrategy = errors.New("invalid prefix allocation strategy")
|
||||
)
|
||||
|
||||
// defaultChallengeResolvers find a zone's nameservers when
|
||||
// DefaultChallengeResolvers find a zone's nameservers when
|
||||
// dns.challenge.resolvers is empty. The system resolver is not used: on a
|
||||
// host running MagicDNS it answers for base_domain itself instead of
|
||||
// asking the public zone.
|
||||
var defaultChallengeResolvers = []string{"1.1.1.1:53", "8.8.8.8:53"}
|
||||
func DefaultChallengeResolvers() []string {
|
||||
return []string{"9.9.9.9:53", "149.112.112.112:53"}
|
||||
}
|
||||
|
||||
// IPAllocationStrategy is how new node IPs are picked. "" decodes without
|
||||
// error to the zero value (unset).
|
||||
@@ -378,7 +380,7 @@ func (c DNSChallengeConfig) NewProvider(secret func(key, value string) (string,
|
||||
// are set. Like dns.nameservers, a resolver may be a bare IP.
|
||||
func (c DNSChallengeConfig) ResolverAddrs() []string {
|
||||
if len(c.Resolvers) == 0 {
|
||||
return slices.Clone(defaultChallengeResolvers)
|
||||
return DefaultChallengeResolvers()
|
||||
}
|
||||
|
||||
addrs := make([]string, len(c.Resolvers))
|
||||
|
||||
@@ -475,7 +475,7 @@ func TestDerivedValues(t *testing.T) {
|
||||
{"workers set", Tuning{BatcherWorkers: 7}.BatcherWorkerCount(), 7},
|
||||
{"zone unset", DNSConfig{BaseDomain: "ts.example.com"}.CertificateZone(), "ts.example.com"},
|
||||
{"zone set", DNSConfig{BaseDomain: "ts.example.com", Certificates: CertificatesConfig{Zone: "example.com"}}.CertificateZone(), "example.com"},
|
||||
{"resolvers unset", resolvers().ResolverAddrs(), []string{"1.1.1.1:53", "8.8.8.8:53"}},
|
||||
{"resolvers unset", resolvers().ResolverAddrs(), []string{"9.9.9.9:53", "149.112.112.112:53"}},
|
||||
{"resolver bare IPv4", resolvers("9.9.9.9").ResolverAddrs(), []string{"9.9.9.9:53"}},
|
||||
{"resolver bare IPv6", resolvers("2620:fe::fe").ResolverAddrs(), []string{"[2620:fe::fe]:53"}},
|
||||
{"resolver with port", resolvers("[::1]:5353").ResolverAddrs(), []string{"[::1]:5353"}},
|
||||
|
||||
Reference in new issue
Block a user