Skip to content

Commit 73e3a4e

Browse files
committed
datamodel: forward: server: added 'insecure' config
This commit is related to GitHub issue #123.
1 parent 7779e85 commit 73e3a4e

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

doc/_static/config.schema.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1082,11 +1082,17 @@
10821082
"type": "boolean",
10831083
"description": "Enable/disable DNSSEC.",
10841084
"default": true
1085+
},
1086+
"insecure": {
1087+
"type": "boolean",
1088+
"description": "Allow insecure TLS configuration.",
1089+
"default": false
10851090
}
10861091
},
10871092
"default": {
10881093
"authoritative": false,
1089-
"dnssec": true
1094+
"dnssec": true,
1095+
"insecure": false
10901096
}
10911097
}
10921098
}

python/knot_resolver/datamodel/forward_schema.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ForwardServerSchema(ConfigSchema):
2424

2525
def _validate(self) -> None:
2626
if self.pin_sha256 and (self.hostname or self.ca_file):
27-
raise ValueError("'pin-sha256' cannot be configurad together with 'hostname' or 'ca-file'")
27+
raise ValueError("'pin-sha256' cannot be configured together with 'hostname' or 'ca-file'")
2828

2929

3030
class ForwardOptionsSchema(ConfigSchema):
@@ -34,10 +34,13 @@ class ForwardOptionsSchema(ConfigSchema):
3434
---
3535
authoritative: The forwarding target is an authoritative server.
3636
dnssec: Enable/disable DNSSEC.
37+
insecure: Allow insecure TLS configuration.
38+
3739
"""
3840

3941
authoritative: bool = False
4042
dnssec: bool = True
43+
insecure: bool = False
4144

4245

4346
class ForwardSchema(ConfigSchema):
@@ -74,3 +77,14 @@ def is_transport_tls(servers: List[Any]) -> bool:
7477

7578
if self.options.authoritative and is_transport_tls(self.servers):
7679
raise ValueError("Forwarding to authoritative servers using TLS protocol is not supported.")
80+
81+
if not self.options.insecure:
82+
for server in self.servers:
83+
if (
84+
isinstance(server, ForwardServerSchema)
85+
and server.transport == "tls"
86+
and not (server.pin_sha256 or server.hostname or server.ca_file)
87+
):
88+
raise ValueError(
89+
"no way to authenticate server (hostname, ca-file or pin-sha256) and 'insecure' is not set"
90+
)

python/knot_resolver/datamodel/templates/macros/forward_macros.lua.j2

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{dnssec={{ boolean(options.dnssec) }},auth={{ boolean(options.authoritative) }}}
55
{%- endmacro %}
66

7-
{% macro forward_server(server) -%}
7+
{% macro forward_server(server, options) -%}
88
{%- if server.address -%}
99
{%- for addr in server.address -%}
1010
{'{{ addr }}',
@@ -13,6 +13,11 @@ tls=true,
1313
{%- else -%}
1414
tls=false,
1515
{%- endif -%}
16+
{%- if options.insecure -%}
17+
insecure=true,
18+
{%- else -%}
19+
insecure=false,
20+
{%- endif -%}
1621
{%- if server.hostname -%}
1722
hostname='{{ server.hostname }}',
1823
{%- endif -%}
@@ -29,14 +34,14 @@ ca_file='{{ server.ca_file }}',
2934
{%- endif -%}
3035
{%- endmacro %}
3136

32-
{% macro forward_servers(servers) -%}
37+
{% macro forward_servers(servers, options) -%}
3338
{
3439
{%- for server in servers -%}
35-
{{ forward_server(server) }}
40+
{{ forward_server(server, options) }}
3641
{%- endfor -%}
3742
}
3843
{%- endmacro %}
3944

4045
{% macro policy_rule_forward_add(subtree,options,servers) -%}
41-
policy.rule_forward_add('{{ subtree }}',{{ forward_options(options) }},{{ forward_servers(servers) }})
46+
policy.rule_forward_add('{{ subtree }}',{{ forward_options(options) }},{{ forward_servers(servers, options) }})
4247
{%- endmacro %}

tests/manager/datamodel/templates/test_forward_macros.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_policy_rule_forward_add():
1717
},
1818
}
1919
)
20-
result = "policy.rule_forward_add('.',{dnssec=true,auth=false},{{'2001:148f:fffe::1',tls=false,hostname='odvr.nic.cz',},{'185.43.135.1',tls=false,hostname='odvr.nic.cz',},})"
20+
result = "policy.rule_forward_add('.',{dnssec=true,auth=false},{{'2001:148f:fffe::1',tls=false,insecure=false,hostname='odvr.nic.cz',},{'185.43.135.1',tls=false,insecure=false,hostname='odvr.nic.cz',},})"
2121

2222
tmpl = template_from_str(tmpl_str)
2323
assert tmpl.render(rule=rule) == result

0 commit comments

Comments
 (0)