36 lines
1009 B
Python
36 lines
1009 B
Python
"""Uvicorn listener that accepts the configured load balancer certificate."""
|
|
|
|
import os
|
|
import ssl
|
|
from pathlib import Path
|
|
from uuid import uuid4
|
|
|
|
import uvicorn
|
|
|
|
|
|
def main() -> None:
|
|
alias = uuid4().hex
|
|
os.environ['INSTANCE_ID'] = alias
|
|
Path('/tmp/lab-instance-id').write_text(alias, encoding='ascii')
|
|
config = uvicorn.Config(
|
|
'app.main:app',
|
|
host='0.0.0.0',
|
|
port=8443,
|
|
ssl_certfile=os.environ['TLS_CERT_FILE'],
|
|
ssl_keyfile=os.environ['TLS_KEY_FILE'],
|
|
ssl_ca_certs=os.environ['TLS_LB_CERT_FILE'],
|
|
ssl_cert_reqs=ssl.CERT_REQUIRED,
|
|
proxy_headers=False,
|
|
access_log=False,
|
|
timeout_graceful_shutdown=5,
|
|
)
|
|
config.load()
|
|
# Trust the pinned LB leaf. Other client certificates issued by the same CA
|
|
# are rejected, since the issuing CA is absent from this trust store.
|
|
config.ssl.verify_flags |= ssl.VERIFY_X509_PARTIAL_CHAIN
|
|
uvicorn.Server(config).run()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|