lab7: обязательное mTLS LB->API с allowlist identity (SAN lb), health только на loopback, скрипт отрицательных проверок mtls_check
This commit is contained in:
@@ -20,7 +20,7 @@ from types import FrameType
|
||||
|
||||
import uvicorn
|
||||
|
||||
from . import __version__, logging_setup, telemetry
|
||||
from . import __version__, logging_setup, telemetry, tls
|
||||
from .app import create_app
|
||||
from .config import ConfigError, Settings
|
||||
|
||||
@@ -64,8 +64,18 @@ def main() -> int:
|
||||
logging_setup.configure(settings.log_level)
|
||||
telemetry.setup("messenger-api", settings.instance_id, __version__)
|
||||
app = create_app(settings)
|
||||
mtls: dict = {}
|
||||
if settings.tls_cert_file:
|
||||
# Lab 7: mandatory mTLS (client certificate of the internal CA) + identity allowlist
|
||||
# MTLS_ALLOWED_CLIENTS checked by the protocol class right after the handshake (tls.py).
|
||||
context = tls.server_context(settings.tls_cert_file, settings.tls_key_file, settings.tls_client_ca_file)
|
||||
protocol = tls.protocol_class()
|
||||
mtls = {"ssl_context_factory": lambda _config, _default: context, "http": protocol,
|
||||
"ssl_certfile": settings.tls_cert_file}
|
||||
log.info("mtls_enabled", extra={"fields": {"allowed_clients": sorted(protocol.allowed)}})
|
||||
config = uvicorn.Config(
|
||||
app,
|
||||
**mtls,
|
||||
host=settings.host,
|
||||
port=settings.port,
|
||||
log_config=None,
|
||||
|
||||
Reference in New Issue
Block a user