1
1
import logging
2
2
import os
3
3
import socket
4
- from pathlib import Path
5
4
from typing import Any , Dict , List , Literal , Optional , Tuple , Union
6
5
7
- from knot_resolver .constants import API_SOCK_NAME , RUN_DIR , VERSION
6
+ from knot_resolver .constants import API_SOCK_FILE , RUN_DIR , VERSION
8
7
from knot_resolver .datamodel .cache_schema import CacheSchema
9
8
from knot_resolver .datamodel .defer_schema import DeferSchema
10
9
from knot_resolver .datamodel .dns64_schema import Dns64Schema
@@ -96,7 +95,7 @@ class Raw(ConfigSchema):
96
95
rundir: Directory where the resolver can create files and which will be it's cwd.
97
96
workers: The number of running kresd (Knot Resolver daemon) workers. If set to 'auto', it is equal to number of CPUs available.
98
97
max_workers: The maximum number of workers allowed. Cannot be changed in runtime.
99
- management: Configuration of management HTTP API. By default, unix-socket is located in 'rundir'.
98
+ management: Configuration of management HTTP API.
100
99
webmgmt: Configuration of legacy web management endpoint.
101
100
options: Fine-tuning global parameters of DNS resolver operation.
102
101
network: Network connections and protocols configuration.
@@ -119,7 +118,7 @@ class Raw(ConfigSchema):
119
118
rundir : WritableDir = lazy_default (WritableDir , str (RUN_DIR ))
120
119
workers : Union [Literal ["auto" ], IntPositive ] = IntPositive (1 )
121
120
max_workers : IntPositive = IntPositive (WORKERS_MAX )
122
- management : ManagementSchema = lazy_default (ManagementSchema , {"unix-socket" : str (API_SOCK_NAME )})
121
+ management : ManagementSchema = lazy_default (ManagementSchema , {"unix-socket" : str (API_SOCK_FILE )})
123
122
webmgmt : Optional [WebmgmtSchema ] = None
124
123
options : OptionsSchema = OptionsSchema ()
125
124
network : NetworkSchema = NetworkSchema ()
@@ -174,14 +173,6 @@ def _workers(self, obj: Raw) -> Any:
174
173
)
175
174
return obj .workers
176
175
177
- def _management (self , obj : Raw ) -> Any :
178
- if obj .management .unix_socket :
179
- soc = Path (obj .management .unix_socket .serialize ())
180
- if soc .is_absolute ():
181
- return obj .management
182
- return ManagementSchema ({"unix-socket" : str (obj .rundir .to_path () / soc )})
183
- return obj .management
184
-
185
176
def _dnssec (self , obj : Raw ) -> Any :
186
177
if obj .dnssec is True :
187
178
return DnssecSchema ()
@@ -193,6 +184,14 @@ def _dns64(self, obj: Raw) -> Any:
193
184
return obj .dns64
194
185
195
186
def _validate (self ) -> None :
187
+ # warn about '/management/unix-socket' not located in '/rundir'
188
+ if self .management .unix_socket and self .management .unix_socket .to_path ().parent != self .rundir .to_path ():
189
+ logger .warning (
190
+ f"The management API unix-socket '{ self .management .unix_socket } '"
191
+ f" is not located in the resolver's rundir '{ self .rundir } '."
192
+ " This can lead to permissions issues."
193
+ )
194
+
196
195
# enforce max-workers config
197
196
workers_max = _workers_max_count ()
198
197
if int (self .workers ) > workers_max :
0 commit comments