]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: file permission checks: format files docs-develop-iss9-itxv6i/deployments/5023
authorFrantisek Tobias <frantisek.tobias@nic.cz>
Wed, 21 Aug 2024 09:44:14 +0000 (11:44 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Mon, 2 Sep 2024 15:02:37 +0000 (17:02 +0200)
manager/knot_resolver_manager/datamodel/types/__init__.py
manager/knot_resolver_manager/datamodel/types/files.py
manager/knot_resolver_manager/server.py

index 52ab1cf8cf3eb596124ac3e468cc6eeab2aeb292..26675da3fb08bddbd7266e99378aa44076b27c71 100644 (file)
@@ -1,5 +1,5 @@
 from .enums import DNSRecordTypeEnum, PolicyActionEnum, PolicyFlagEnum
-from .files import AbsoluteDir, Dir, File, FilePath, WritableDir, ReadableFile
+from .files import AbsoluteDir, Dir, File, FilePath, ReadableFile, WritableDir
 from .generic_types import ListOrItem
 from .types import (
     DomainName,
index bcb439a05640107d440b0d50bf027efb800e0cad..98b9d86e46b0d41050ede7d8a385f67c39a8edcf 100644 (file)
@@ -1,11 +1,11 @@
-from pathlib import Path
-from typing import Any, Dict, Tuple, Type, TypeVar
 import os
 import stat
-from pwd import getpwnam
 from grp import getgrnam
+from pathlib import Path
+from pwd import getpwnam
+from typing import Any, Dict, Tuple, Type, TypeVar
 
-from knot_resolver_manager.constants import kresd_user, kresd_group
+from knot_resolver_manager.constants import kresd_group, kresd_user
 from knot_resolver_manager.datamodel.globals import get_resolve_root, get_strict_validation
 from knot_resolver_manager.utils.modeling.base_value_type import BaseValueType
 
@@ -139,7 +139,6 @@ class FilePath(UncheckedPath):
         if self.strict_validation and (not p.exists() or not p.is_dir()):
             raise ValueError(f"path '{self._value}' does not point inside an existing directory")
 
-        # WARNING: is_dir() fails for knot-resolver owned paths when using kresctl to validate config
         if self.strict_validation and self._value.is_dir():
             raise ValueError(f"path '{self._value}' points to a directory when we expected a file")
 
@@ -186,13 +185,14 @@ class ReadableFile(File):
     File, that is enforced to be:
     - readable by kresd
     """
+
     def __init__(
         self, source_value: Any, parents: Tuple["UncheckedPath", ...] = tuple(), object_path: str = "/"
     ) -> None:
         super().__init__(source_value, parents=parents, object_path=object_path)
 
         if self.strict_validation and not kresd_accesible(self._value, READ_MODE):
-            raise ValueError(f"{kresd_user()}:{kresd_group()} has insuficient permissions to read \"{self._value}\"")
+            raise ValueError(f'{kresd_user()}:{kresd_group()} has insuficient permissions to read "{self._value}"')
 
 
 class WritableDir(Dir):
@@ -200,10 +200,11 @@ class WritableDir(Dir):
     Dif, that is enforced to be:
     - writable to by kresd
     """
+
     def __init__(
         self, source_value: Any, parents: Tuple["UncheckedPath", ...] = tuple(), object_path: str = "/"
     ) -> None:
         super().__init__(source_value, parents=parents, object_path=object_path)
 
         if self.strict_validation and not kresd_accesible(self._value, WRITE_MODE):
-            raise ValueError(f"{kresd_user()}:{kresd_group()} has insuficient permissions to write to \"{self._value}\"")
+            raise ValueError(f'{kresd_user()}:{kresd_group()} has insuficient permissions to write to "{self._value}"')
index d05ac7b4a267e78b0ab3d941943186749c52e722..b27cadb339fc04571c53ed9170b7e1c896b4187a 100644 (file)
@@ -17,6 +17,7 @@ from aiohttp.web_app import Application
 from aiohttp.web_response import json_response
 from aiohttp.web_runner import AppRunner, TCPSite, UnixSite
 from typing_extensions import Literal
+
 import knot_resolver_manager.utils.custom_atexit as atexit
 from knot_resolver_manager import log, statistics
 from knot_resolver_manager.compat import asyncio as asyncio_compat