forked from mtusi2026/mtusi2026lab7
solution
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user