Skip to content

Commit ed88470

Browse files
committed
fixup! fixup! datamodel: forward: server: added 'insecure' config
1 parent d6e1755 commit ed88470

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

doc/_static/config.schema.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,6 @@
10221022
"description": "Transport protocol for a forward server.",
10231023
"default": null
10241024
},
1025-
"insecure": {
1026-
"type": "boolean",
1027-
"description": "Allow insecure TLS configuration.",
1028-
"default": false
1029-
},
10301025
"pin-sha256": {
10311026
"anyOf": [
10321027
{
@@ -1087,11 +1082,17 @@
10871082
"type": "boolean",
10881083
"description": "Enable/disable DNSSEC.",
10891084
"default": true
1085+
},
1086+
"insecure": {
1087+
"type": "boolean",
1088+
"description": "Allow insecure TLS configuration.",
1089+
"default": false
10901090
}
10911091
},
10921092
"default": {
10931093
"authoritative": false,
1094-
"dnssec": true
1094+
"dnssec": true,
1095+
"insecure": false
10951096
}
10961097
}
10971098
}

python/knot_resolver/datamodel/forward_schema.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,20 @@ class ForwardServerSchema(ConfigSchema):
1111
---
1212
address: IP address(es) of a forward server.
1313
transport: Transport protocol for a forward server.
14-
insecure: Allow insecure TLS configuration.
1514
pin_sha256: Hash of accepted CA certificate.
1615
hostname: Hostname of the Forward server.
1716
ca_file: Path to CA certificate file.
1817
"""
1918

2019
address: ListOrItem[IPAddressOptionalPort]
2120
transport: Optional[Literal["tls"]] = None
22-
insecure: bool = False
2321
pin_sha256: Optional[ListOrItem[PinSha256]] = None
2422
hostname: Optional[DomainName] = None
2523
ca_file: Optional[ReadableFile] = None
2624

2725
def _validate(self) -> None:
2826
if self.pin_sha256 and (self.hostname or self.ca_file):
29-
raise ValueError("'pin-sha256' cannot be configurad together with 'hostname' or 'ca-file'")
30-
if not self.insecure and not (self.pin_sha256 or self.hostname or self.ca_file):
31-
raise ValueError("no way to authenticate and 'insecure' not set")
27+
raise ValueError("'pin-sha256' cannot be configured together with 'hostname' or 'ca-file'")
3228

3329

3430
class ForwardOptionsSchema(ConfigSchema):
@@ -38,10 +34,13 @@ class ForwardOptionsSchema(ConfigSchema):
3834
---
3935
authoritative: The forwarding target is an authoritative server.
4036
dnssec: Enable/disable DNSSEC.
37+
insecure: Allow insecure TLS configuration.
38+
4139
"""
4240

4341
authoritative: bool = False
4442
dnssec: bool = True
43+
insecure: bool = False
4544

4645

4746
class ForwardSchema(ConfigSchema):
@@ -78,3 +77,14 @@ def is_transport_tls(servers: List[Any]) -> bool:
7877

7978
if self.options.authoritative and is_transport_tls(self.servers):
8079
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

+5-5
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,7 +13,7 @@ tls=true,
1313
{%- else -%}
1414
tls=false,
1515
{%- endif -%}
16-
{%- if server.insecure -%}
16+
{%- if options.insecure -%}
1717
insecure=true,
1818
{%- else -%}
1919
insecure=false,
@@ -34,14 +34,14 @@ ca_file='{{ server.ca_file }}',
3434
{%- endif -%}
3535
{%- endmacro %}
3636

37-
{% macro forward_servers(servers) -%}
37+
{% macro forward_servers(servers, options) -%}
3838
{
3939
{%- for server in servers -%}
40-
{{ forward_server(server) }}
40+
{{ forward_server(server, options) }}
4141
{%- endfor -%}
4242
}
4343
{%- endmacro %}
4444

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

0 commit comments

Comments
 (0)