mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-19 20:04:32 +09:00
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:
1 parent
68424bbb4a
commit
e35af45066
4 files changed
+34
-3
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user