forked from mtusi2026/mtusi2026lab7
lab7: обязательное mTLS LB->API с allowlist identity (SAN lb), health только на loopback, скрипт отрицательных проверок mtls_check
This commit is contained in:
@@ -154,6 +154,11 @@ class Settings:
|
||||
queued_republish_seconds: float = 300.0
|
||||
fault_points: frozenset[str] = frozenset()
|
||||
fault_values: dict[str, int] = field(default_factory=dict)
|
||||
# Lab 7: TLS of the API listener (mTLS, src/messenger/tls.py) and the loopback health port.
|
||||
tls_cert_file: str = ""
|
||||
tls_key_file: str = ""
|
||||
tls_client_ca_file: str = ""
|
||||
health_port: int = 0
|
||||
|
||||
def fault_value(self, point: str, default: int = 0) -> int:
|
||||
return self.fault_values.get(point, default)
|
||||
@@ -210,6 +215,7 @@ class Settings:
|
||||
message_write_path=_choice("MESSAGE_WRITE_PATH", "function", {"function", "multi"}),
|
||||
**s3_settings(credentials_required=s3_credentials),
|
||||
**jobs_settings(broker_required=False),
|
||||
**tls_settings(),
|
||||
)
|
||||
|
||||
|
||||
@@ -304,6 +310,24 @@ def s3_settings(*, credentials_required: bool = True) -> dict:
|
||||
)
|
||||
|
||||
|
||||
def _path(name: str) -> str:
|
||||
"""Optional file path setting; if set, the file must exist (fail at start, not at first use)."""
|
||||
value = os.environ.get(name, "").strip()
|
||||
if value and not Path(value).is_file():
|
||||
raise ConfigError(f"{name}={value} does not exist")
|
||||
return value
|
||||
|
||||
|
||||
def tls_settings() -> dict:
|
||||
"""Lab 7, API listener: TLS_CERT_FILE/TLS_KEY_FILE = the replica's certificate (SAN `api`),
|
||||
TLS_CLIENT_CA_FILE = the internal CA that client certificates must chain to. All three or none."""
|
||||
cert, key, ca = _path("TLS_CERT_FILE"), _path("TLS_KEY_FILE"), _path("TLS_CLIENT_CA_FILE")
|
||||
if any((cert, key, ca)) and not all((cert, key, ca)):
|
||||
raise ConfigError("TLS_CERT_FILE, TLS_KEY_FILE and TLS_CLIENT_CA_FILE must be set together")
|
||||
return dict(tls_cert_file=cert, tls_key_file=key, tls_client_ca_file=ca,
|
||||
health_port=_int("APP_HEALTH_PORT", 0, 0, 65535))
|
||||
|
||||
|
||||
def jobs_settings(*, broker_required: bool) -> dict:
|
||||
"""Lab 5 pipeline: retries, lease, worker limits, cleanup, relay (docs/PIPELINE.md)."""
|
||||
from .pipeline import PIPELINES # local import: pipeline.py imports nothing from here
|
||||
|
||||
Reference in New Issue
Block a user