config: reject empty list items

A resolver became the local one, an allowed user one without an email.
Updates #1926
This commit is contained in:
Kristoffer Dalby committed 2026-11-11 16:42:44 +01:00
1 parent 68424bbb4a
commit e35af45066
4 files changed
+34 -3

No files matched your search

+18
View File
@@ -232,6 +232,24 @@ func TestValidateGoData(t *testing.T) {
},
wantErr: "tls.acme.hostname and tls.cert_path/tls.key_path are mutually exclusive",
},
{
name: "empty resolver",
set: func(c *types.Config) { c.DNSConfig.Challenge.Resolvers = []string{""} },
wantErr: "dns.challenge.resolvers[0] is empty",
},
{
name: "empty derp url",
set: func(c *types.Config) {
c.DERP.URLs = []types.HTTPURL{"https://derp.example.com/map.json", ""}
},
wantErr: "derp.urls[1] is empty",
},
{
// Would admit a user whose provider sends no email.
name: "empty allowed user",
set: func(c *types.Config) { c.OIDC.AllowedUsers = []string{""} },
wantErr: "oidc.allowed_users[0] is empty",
},
{
name: "url",
set: func(c *types.Config) {
+3
View File
@@ -4081,6 +4081,7 @@ dns:
extra_records: [{name: a.example.com, type: A, value: 100.64.0.1}]
extra_records_path: /var/lib/headscale/records.json
challenge:
resolvers: [""]
provider:
name: bogus
tls:
@@ -4117,6 +4118,7 @@ oidc:
name: "every rule, in order",
file: everyRule,
want: []string{
"dns.challenge.resolvers[0] is empty",
"OIDC configuration is invalid",
"dns.extra_records and dns.extra_records_path are mutually exclusive",
"tls.acme.hostname and tls.cert_path/tls.key_path are mutually exclusive",
@@ -4149,6 +4151,7 @@ oidc:
"database:\n type: \"\"\n", "database:\n type: sqlite\n sqlite:\n path: \"\"\n",
).Replace(everyRule),
want: []string{
"dns.challenge.resolvers[0] is empty",
"OIDC configuration is invalid",
"dns.extra_records and dns.extra_records_path are mutually exclusive",
"tls.acme.hostname and tls.cert_path/tls.key_path are mutually exclusive",
+1 -1
View File
@@ -146,7 +146,7 @@ var leafTypes = []leafType{
},
{
Kinds: []reflect.Kind{reflect.Slice}, Label: "list",
Format: "A list. A variable holds it as a JSON array or, unless its values are objects, separated by spaces.",
Format: "A list. A variable holds it as a JSON array or, unless its values are objects, separated by spaces. An empty item is an error.",
Sample: "`[9.9.9.9, 2620:fe::fe]`", Nix: "lib.types.listOf",
},
{
+12 -2
View File
@@ -248,7 +248,7 @@ func Validate(c *types.Config) error {
// validateValues parses every value whose type parses text, and each
// element of a list of them, from its own text, as the loader did: a
// Config built in Go was never parsed.
// Config built in Go was never parsed. An empty text in a list is an error.
func validateValues(c *types.Config, v *configValidator) {
for _, f := range types.ConfigFields(c) {
if f.Value.Kind() != reflect.Slice {
@@ -258,7 +258,17 @@ func validateValues(c *types.Config, v *configValidator) {
}
for i := range f.Value.Len() {
validateValue(v, fmt.Sprintf("%s[%d]", f.Path, i), f.Value.Index(i))
key, elem := fmt.Sprintf("%s[%d]", f.Path, i), f.Value.Index(i)
// No list gives "" a meaning: a resolver would be the local one,
// an allowed user one without an email.
if elem.Kind() == reflect.String && elem.Len() == 0 {
v.Add(&types.ConfigError{Reason: key + " is empty", Hint: "remove the empty entry"})
continue
}
validateValue(v, key, elem)
}
}
}