]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
python: datamodel: added missing 'enable' options
authorAleš Mrázek <ales.mrazek@nic.cz>
Thu, 5 Jun 2025 17:58:39 +0000 (19:58 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 31 Oct 2025 14:11:38 +0000 (15:11 +0100)
In order to be consistent throughout the datamodel, it will only be possible to enable individual resolver features using the 'enable' option.

15 files changed:
NEWS
doc/_static/config.schema.json
doc/user/config-cache-predict.rst
doc/user/config-logging-dnstap.rst
doc/user/config-network-server.rst
etc/config/config.migrate-test.yaml
etc/config/config.migrate-test2.yaml
python/knot_resolver/client/commands/migrate.py
python/knot_resolver/datamodel/cache_schema.py
python/knot_resolver/datamodel/logging_schema.py
python/knot_resolver/datamodel/network_schema.py
python/knot_resolver/datamodel/templates/cache.lua.j2
python/knot_resolver/datamodel/templates/logging.lua.j2
python/knot_resolver/datamodel/templates/network.lua.j2
python/knot_resolver/datamodel/view_schema.py

diff --git a/NEWS b/NEWS
index d6a759df4976bfd1d81d834ec414a7e67427bc9c..150c3e2c4e559dcf44824867e8fdf1f5ae85cd26 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,15 +21,18 @@ https://www.knot-resolver.cz/documentation/v6.0.16/upgrading.html
   - /webmgmt
 - Renamed/moved options in the declarative configuration model (YAML). (!1672)
   - /cache/garbage-collector -> /cache/garbage-collector/enable
+  - /cache/prefetch/prediction -> /cache/prefetch/prediction/enable
   - /dns64: true|false -> /dns64/enable: true|false
   - /dns64/rev-ttl -> /dns64/reverse-ttl
   - /dnssec: true|false -> /dnssec/enable: true|false
   - /dnssec/keep-removed -> /dnssec/trust-anchors-keep-removed
   - /dnssec/trust-anchor-sentinel -> /dnssec/sentinel
   - /dnssec/trust-anchor-signal-query -> /dnssec/signal-query
+  - /logging/dnstap -> /logging/dnstap/enable
   - /logging/dnssec-bogus -> /dnssec/log-bogus
   - /monitoring/enabled -> /monitoring/metrics
   - /monitoring/graphite -> /monitoring/graphite/enable
+  - /network/proxy_protocol -> /network/proxy_protocol/enable
   - /network/tls/files-watchdog -> /network/tls/watchdog
   - /rate-limiting -> /rate-limiting/enable
 
index b14113186e1e8687bb01bc47f3bb107a3db2dc7e..5200eadd4614c9ee9ddf9c02af92145d0e52e450 100644 (file)
                     }
                 },
                 "proxy-protocol": {
-                    "anyOf": [
-                        {
-                            "type": "string",
-                            "enum": [
-                                false
-                            ]
+                    "description": "PROXYv2 protocol configuration.",
+                    "type": "object",
+                    "properties": {
+                        "enable": {
+                            "type": "boolean",
+                            "description": "Enable/disable PROXYv2 protocol.",
+                            "default": false
                         },
-                        {
-                            "description": "PROXYv2 protocol configuration.",
-                            "type": "object",
-                            "properties": {
-                                "allow": {
-                                    "type": "array",
-                                    "items": {
-                                        "anyOf": [
-                                            {
-                                                "type": "string"
-                                            },
-                                            {
-                                                "type": "string"
-                                            },
-                                            {
-                                                "type": "string"
-                                            }
-                                        ]
+                        "allow": {
+                            "type": [
+                                "array",
+                                "null"
+                            ],
+                            "items": {
+                                "anyOf": [
+                                    {
+                                        "type": "string"
                                     },
-                                    "description": "Allow usage of the PROXYv2 protocol headers by clients on the specified addresses."
-                                }
-                            }
+                                    {
+                                        "type": "string"
+                                    },
+                                    {
+                                        "type": "string"
+                                    }
+                                ]
+                            },
+                            "description": "Allow usage of the PROXYv2 protocol headers by clients on the specified addresses.",
+                            "default": null
                         }
-                    ],
-                    "description": "PROXYv2 protocol configuration.",
-                    "default": false
+                    },
+                    "default": {
+                        "enable": false,
+                        "allow": null
+                    }
                 },
                 "listen": {
                     "type": "array",
                     "sticket_secret_file": null,
                     "padding": true
                 },
-                "proxy_protocol": false,
+                "proxy_protocol": {
+                    "enable": false,
+                    "allow": null
+                },
                 "listen": [
                     {
                         "interface": [
                         },
                         "prediction": {
                             "description": "Prefetch record by predicting based on usage patterns and repetitive queries.",
-                            "type": [
-                                "object",
-                                "null"
-                            ],
+                            "type": "object",
                             "properties": {
+                                "enable": {
+                                    "type": "boolean",
+                                    "description": "Enable/disable prediction.",
+                                    "default": false
+                                },
                                 "window": {
                                     "type": "string",
                                     "pattern": "^(\\d+)(us|ms|s|m|h|d)$",
                                     "default": 24
                                 }
                             },
-                            "default": null
+                            "default": {
+                                "enable": false,
+                                "window": "15m",
+                                "period": 24
+                            }
                         }
                     },
                     "default": {
                         "expiring": false,
-                        "prediction": null
+                        "prediction": {
+                            "enable": false,
+                            "window": "15m",
+                            "period": 24
+                        }
                     }
                 }
             },
                 "prefill": null,
                 "prefetch": {
                     "expiring": false,
-                    "prediction": null
+                    "prediction": {
+                        "enable": false,
+                        "window": "15m",
+                        "period": 24
+                    }
                 }
             }
         },
                     "default": null
                 },
                 "dnstap": {
-                    "anyOf": [
-                        {
-                            "type": "string",
-                            "enum": [
-                                false
-                            ]
+                    "description": "Logging DNS requests and responses to a unix socket.",
+                    "type": "object",
+                    "properties": {
+                        "enable": {
+                            "type": "boolean",
+                            "description": "Enable/disable DNS queries logging.",
+                            "default": false
                         },
-                        {
-                            "description": "Logging DNS queries and responses to a unix socket.",
-                            "type": "object",
-                            "properties": {
-                                "unix-socket": {
-                                    "type": "string",
-                                    "description": "Path to unix domain socket where dnstap messages will be sent."
-                                },
-                                "log-queries": {
-                                    "type": "boolean",
-                                    "description": "Log queries from downstream in wire format.",
-                                    "default": true
-                                },
-                                "log-responses": {
-                                    "type": "boolean",
-                                    "description": "Log responses to downstream in wire format.",
-                                    "default": true
-                                },
-                                "log-tcp-rtt": {
-                                    "type": "boolean",
-                                    "description": "Log TCP RTT (Round-trip time).",
-                                    "default": true
-                                }
-                            }
+                        "unix-socket": {
+                            "type": [
+                                "string",
+                                "null"
+                            ],
+                            "description": "Path to unix domain socket where dnstap messages will be sent.",
+                            "default": null
+                        },
+                        "log-queries": {
+                            "type": "boolean",
+                            "description": "Log queries from downstream in wire format.",
+                            "default": true
+                        },
+                        "log-responses": {
+                            "type": "boolean",
+                            "description": "Log responses to downstream in wire format.",
+                            "default": true
+                        },
+                        "log-tcp-rtt": {
+                            "type": "boolean",
+                            "description": "Log TCP RTT (Round-trip time).",
+                            "default": true
                         }
-                    ],
-                    "description": "Logging DNS requests and responses to a unix socket.",
-                    "default": false
+                    },
+                    "default": {
+                        "enable": false,
+                        "unix_socket": null,
+                        "log_queries": true,
+                        "log_responses": true,
+                        "log_tcp_rtt": true
+                    }
                 }
             },
             "default": {
                 "level": "notice",
                 "target": "stdout",
                 "groups": null,
-                "dnstap": false
+                "dnstap": {
+                    "enable": false,
+                    "unix_socket": null,
+                    "log_queries": true,
+                    "log_responses": true,
+                    "log_tcp_rtt": true
+                }
             }
         },
         "monitoring": {
index b270bbbd2b0ac5d069623157fbed9c8600973ee0..8b3fd3330d820a61049a9444e404bc8fb13ba0d8 100644 (file)
@@ -35,8 +35,10 @@ though this mechanism is a prototype and **not recommended** for use in producti
      prefetch:
        # this mode is NOT RECOMMENDED for use in production
        prediction:
-          window: 15m  # 15 minutes sampling window
-          period: 24   # track last 6 hours
+         enable: true
+         # optionally, you can edit prediction configuration
+         window: 15m  # default, 15 minutes sampling window
+         period: 24   # default, track last 6 hours
 
 
 Window length is in minutes, period is a number of windows that can be kept in memory.
index 1c7ced716464fb13cecf42734bba81c38ff5f189..c9de7bea3060dda63bf9faf5c850d99be19acdf4 100644 (file)
@@ -29,6 +29,7 @@ Tunables:
 
     logging:
       dnstap:
+        enable: true
         unix-socket: /tmp/dnstap.sock
         # by default log is enabled for all
         log-queries: true
index 0d1806efce3385f74f4d3d3f62c2cc9c56c6406d..cff3ea2e7403a5cbdd2ff929806909559668a929 100644 (file)
@@ -123,6 +123,7 @@ will be discarded.
 
    network:
      proxy-protocol:
+       enable: true
        allow:
          - 172.22.0.1     # allows '172.22.0.1' specifically
          - 172.18.1.0/24  # allows everyone at '172.18.1.*'
index ccb1fadb8f1572c7e08c5bcce6670db7374f334c..7666e8b8a69faf4e16e81cc3fdd1ea7a66d44baf 100644 (file)
@@ -1,6 +1,10 @@
 cache:
   garbage-collector:
     interval: 2s
+  prefetch:
+    prediction:
+      window: 15m
+      period: 24
 
 dns64:
   rev-ttl: 1d
@@ -22,6 +26,8 @@ local-data:
     - rfa.zone
 
 logging:
+  dnstap:
+    unix-socket: dnstap.sock
   dnssec-bogus: true
   debugging:
     assertion-abort: false
@@ -33,6 +39,8 @@ monitoring:
     host: 127.0.0.1
 
 network:
+  proxy-protocol:
+    allow: [172.22.0.1]
   tls:
     auto-discovery: true
     files-watchdog: true
index 2b309be67ee45d36e75a4aa0a55d2ed475718b83..3a11080daf3651164e332251399cce531b27675f 100644 (file)
@@ -1,10 +1,18 @@
 
 cache:
   garbage-collector: false
+  prefetch:
+    prediction: null
 
 dns64: true
 
 dnssec: false
 
+logging:
+  dnstap: null
+
 monitoring:
   graphite: false
+
+network:
+  proxy-protocol: null
index 2b11f83d11b060fef9280baf9ce0ea4a455c1701..6a7eda14d08e356159ef0114e923e1de927d53f0 100644 (file)
@@ -132,6 +132,15 @@ class MigrateCommand(Command):
                     _add(new, "/cache/garbage-collector/enable", False)
                 else:
                     _add(new, "/cache/garbage-collector/enable", True)
+            prefetch_key = "prefetch"
+            if prefetch_key in new[cache_key]:
+                prediction_key = "prediction"
+                if prediction_key in new[cache_key][prefetch_key]:
+                    prediction = new[cache_key][prefetch_key][prediction_key]
+                    if prediction is None:
+                        _add(new, "/cache/prefetch/prediction/enable", False)
+                    else:
+                        _add(new, "/cache/prefetch/prediction/enable", True)
         dns64_key = "dns64"
         if dns64_key in new:
             if new[dns64_key] is False:
@@ -149,6 +158,16 @@ class MigrateCommand(Command):
         _rename(new, "/dnssec/keep-removed", "/dnssec/trust-anchors-keep-removed")
         _rename(new, "/dnssec/trust-anchor-sentinel", "/dnssec/sentinel")
         _rename(new, "/dnssec/trust-anchor-signal-query", "/dnssec/signal-query")
+        logging_key = "logging"
+        if logging_key in new:
+            dnstap_key = "dnstap"
+            if dnstap_key in new[logging_key]:
+                dnstap = new[logging_key][dnstap_key]
+                if dnstap is None:
+                    _add(new, "/logging/dnstap/enable", False)
+                else:
+                    _add(new, "/logging/dnstap/enable", True)
+
         _rename(new, "/logging/dnssec-bogus", "/dnssec/log-bogus")
         _rename(new, "/monitoring/enabled", "/monitoring/metrics")
         monitoring_key = "monitoring"
@@ -160,6 +179,15 @@ class MigrateCommand(Command):
                     _add(new, "/monitoring/graphite/enable", False)
                 else:
                     _add(new, "/monitoring/graphite/enable", True)
+        network_key = "network"
+        if network_key in new:
+            proxy_protocol_key = "proxy-protocol"
+            if proxy_protocol_key in new[network_key]:
+                proxy_protocol = new[network_key][proxy_protocol_key]
+                if proxy_protocol is None:
+                    _add(new, "/network/proxy-protocol/enable", False)
+                else:
+                    _add(new, "/network/proxy-protocol/enable", True)
         _rename(new, "/network/tls/files-watchdog", "/network/tls/watchdog")
         rate_limiting_key = "rate-limiting"
         if rate_limiting_key in new:
index a4d525c6c5c6a455a81482c45e5a026294af0a3c..80e41fb4ca441e7677e3d379e666c9bc707b79ee 100644 (file)
@@ -91,10 +91,12 @@ class PredictionSchema(ConfigSchema):
     Helps keep the cache hot by prefetching expiring records and learning usage patterns and repetitive queries.
 
     ---
+    enable: Enable/disable prediction.
     window: Sampling window length.
     period: Number of windows that can be kept in memory.
     """
 
+    enable: bool = False
     window: TimeUnit = TimeUnit("15m")
     period: IntPositive = IntPositive(24)
 
@@ -108,7 +110,7 @@ class PrefetchSchema(ConfigSchema):
     """
 
     expiring: bool = False
-    prediction: Optional[PredictionSchema] = None
+    prediction: PredictionSchema = PredictionSchema()
 
 
 class CacheSchema(ConfigSchema):
index bca23d5e855821030a34771a28704564565380a3..b6587584bc6c28ef7ec6e527957675973475f795 100644 (file)
@@ -68,17 +68,23 @@ class DnstapSchema(ConfigSchema):
     Logging DNS queries and responses to a unix socket.
 
     ---
+    enable: Enable/disable DNS queries logging.
     unix_socket: Path to unix domain socket where dnstap messages will be sent.
     log_queries: Log queries from downstream in wire format.
     log_responses: Log responses to downstream in wire format.
     log_tcp_rtt: Log TCP RTT (Round-trip time).
     """
 
-    unix_socket: WritableFilePath
+    enable: bool = False
+    unix_socket: Optional[WritableFilePath] = None
     log_queries: bool = True
     log_responses: bool = True
     log_tcp_rtt: bool = True
 
+    def _validate(self) -> None:
+        if self.enable and self.unix_socket is None:
+            raise ValueError("DNS queries logging enabled, but 'unix-socket' not specified")
+
 
 class LoggingSchema(ConfigSchema):
     class Raw(ConfigSchema):
@@ -95,14 +101,14 @@ class LoggingSchema(ConfigSchema):
         level: LogLevelEnum = "notice"
         target: Union[LogTargetEnum, Literal["from-env"]] = "from-env"
         groups: Optional[List[LogGroupsEnum]] = None
-        dnstap: Union[Literal[False], DnstapSchema] = False
+        dnstap: DnstapSchema = DnstapSchema()
 
     _LAYER = Raw
 
     level: LogLevelEnum
     target: LogTargetEnum
     groups: Optional[List[LogGroupsEnum]]
-    dnstap: Union[Literal[False], DnstapSchema]
+    dnstap: DnstapSchema
 
     def _target(self, raw: Raw) -> LogTargetEnum:
         if raw.target == "from-env":
index 21f3db56fc8ca1f0e4917b75fcbcdf7c895092e7..5282cc680b215cb9aad6d25d121424841090acae 100644 (file)
@@ -161,10 +161,12 @@ class ProxyProtocolSchema(ConfigSchema):
     PROXYv2 protocol configuration.
 
     ---
+    enable: Enable/disable PROXYv2 protocol.
     allow: Allow usage of the PROXYv2 protocol headers by clients on the specified addresses.
     """
 
-    allow: List[Union[IPAddress, IPNetwork]]
+    enable: bool = False
+    allow: Optional[List[Union[IPAddress, IPNetwork]]] = None
 
 
 class NetworkSchema(ConfigSchema):
@@ -194,7 +196,7 @@ class NetworkSchema(ConfigSchema):
     edns_buffer_size: EdnsBufferSizeSchema = EdnsBufferSizeSchema()
     address_renumbering: Optional[List[AddressRenumberingSchema]] = None
     tls: TLSSchema = TLSSchema()
-    proxy_protocol: Union[Literal[False], ProxyProtocolSchema] = False
+    proxy_protocol: ProxyProtocolSchema = ProxyProtocolSchema()
     listen: List[ListenSchema] = [
         ListenSchema({"interface": "127.0.0.1"}),
         ListenSchema({"interface": "::1", "freebind": True}),
index b37186005830abbfe5d76ed0f69a0558de7fe73e..679169159a561a43e4d4e62d3c3d3d610fcf614a 100644 (file)
@@ -22,7 +22,7 @@ prefill.config({
 modules.load('prefetch')
 {% endif %}
 
-{% if cfg.cache.prefetch.prediction %}
+{% if cfg.cache.prefetch.prediction.enable %}
 -- cache.prefetch.prediction
 modules.load('predict')
 predict.config({
index a173ad75466e276f4f7bc2eea35ac8c13d03c46f..14e11b51addc284baa08e4a018f88e2972dbbf37 100644 (file)
@@ -19,7 +19,7 @@ log_groups({
 })
 {% endif %}
 
-{% if cfg.logging.dnstap -%}
+{% if cfg.logging.dnstap.enable -%}
 -- logging.dnstap
 modules.load('dnstap')
 dnstap.config({
index e01ca330393e0da0ac59121645b935e1f7b5d351..81ec14595edcc68560524e066d1afa3f30e1ea6d 100644 (file)
@@ -78,7 +78,7 @@ modules.load('http')
 {{ http_config(cfg.network.tls,"doh_legacy") }}
 {% endif %}
 
-{% if cfg.network.proxy_protocol %}
+{% if cfg.network.proxy_protocol.enable %}
 -- network.proxy-protocol
 net.proxy_allowed({
 {% for item in cfg.network.proxy_protocol.allow %}
index fc9de6c74d1f377794c30ff9435ef9f5e4680c04..d46ea5442c3943ce0a06d409fdf69aa21023044c 100644 (file)
@@ -37,7 +37,6 @@ class ViewSchema(ConfigSchema):
     subnets: List[IPNetwork]
     dst_subnet: Optional[IPNetwork] = None  # could be a list as well, iterated in template
     protocols: Optional[List[Literal["udp53", "tcp53", "dot", "doh", "doq"]]] = None
-
     tags: Optional[List[IDPattern]] = None
     answer: Optional[Literal["allow", "refused", "noanswer"]] = None
     options: ViewOptionsSchema = ViewOptionsSchema()