This commit is contained in:
k00kzaAntonovaIra
2026-11-25 20:16:24 +03:00
parent 20afc2c790
commit 9dcf5b1118
197 changed files with 21197 additions and 182 deletions
+20
View File
@@ -0,0 +1,20 @@
"""Проверка TLS на внутреннем входе каждой реплики."""
import asyncio
import ssl
from uvicorn.protocols.http.h11_impl import H11Protocol
class LoadBalancerProtocol(H11Protocol):
def connection_made(self, transport: asyncio.Transport) -> None:
# TLS уже проверил цепочку и clientAuth. SAN ограничивает роль клиента.
super().connection_made(transport)
tls = transport.get_extra_info("ssl_object")
certificate = tls.getpeercert() if tls else None
if not certificate or ("DNS", "load-balancer") not in certificate.get("subjectAltName", ()):
transport.abort()
def client_context(ca_file: str | None) -> ssl.SSLContext | None:
return ssl.create_default_context(cafile=ca_file) if ca_file else None