Implement Lab 7 service security
Application / https-smoke (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
dmice9
2026-12-03 20:56:06 +03:00
parent 20afc2c790
commit 9bf101b322
57 changed files with 3802 additions and 53 deletions
+42
View File
@@ -0,0 +1,42 @@
import logging
import os
import ssl
import uvicorn
from uvicorn.protocols.http.h11_impl import H11Protocol
class IngressProtocol(H11Protocol):
def connection_made(self, transport):
tls = transport.get_extra_info("ssl_object")
peer = tls.getpeercert() if tls else {}
if ("DNS", "lb-ingress") not in peer.get("subjectAltName", ()):
transport.close()
return
super().connection_made(transport)
def connection_lost(self, exc):
if self.transport is not None:
super().connection_lost(exc)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
logging.getLogger("messenger").info("environment=%s", os.environ.get("APP_ENV", "lab"))
port = int(os.environ.get("APP_PORT", "8080"))
if not 1 <= port <= 65535:
raise SystemExit("APP_PORT должен быть от 1 до 65535")
uvicorn.run(
"src.app:create_app",
factory=True,
host=os.environ.get("APP_HOST", "0.0.0.0"),
port=port,
workers=1,
http=IngressProtocol,
ssl_certfile="/run/tls/api.crt",
ssl_keyfile="/run/tls/api.key",
ssl_ca_certs="/run/tls/ca.crt",
ssl_cert_reqs=ssl.CERT_REQUIRED,
access_log=False,
timeout_graceful_shutdown=2,
)