ЛР 7: безопасность, mTLS и OpenBao на оценку 3

This commit is contained in:
2026-12-06 15:19:24 +03:00
parent 20afc2c790
commit 280c5a3300
101 changed files with 5950 additions and 63 deletions
+35
View File
@@ -0,0 +1,35 @@
"""Require a verified certificate with the ingress identity before parsing HTTP."""
import ssl
import uvicorn
from uvicorn.protocols.http.h11_impl import H11Protocol
class IngressOnlyProtocol(H11Protocol):
def connection_made(self, transport):
super().connection_made(transport)
tls = transport.get_extra_info("ssl_object")
if tls is None or ("URI", "spiffe://lab7/ingress") not in tls.getpeercert().get(
"subjectAltName", ()
):
transport.close()
return
if __name__ == "__main__":
config = uvicorn.Config(
"app.main:app",
host="0.0.0.0",
port=8443,
http=IngressOnlyProtocol,
proxy_headers=False,
access_log=False,
ssl_certfile="/run/identity/server.crt",
ssl_keyfile="/run/identity/server.key",
ssl_ca_certs="/run/ca/ca.crt",
ssl_cert_reqs=ssl.CERT_REQUIRED,
timeout_graceful_shutdown=5,
)
config.load()
config.ssl.minimum_version = ssl.TLSVersion.TLSv1_2
uvicorn.Server(config).run()