app.tls¶
The TLS context shared by every outbound HTTPS client.
The OIDC discovery request and the GitLab client (httpx) and the JWKS
fetch (PyJWT) all use the ssl.SSLContext built here, so they
trust exactly the same certificate authorities.
Trust store, with verification on (ADRIANO_TLS_VERIFY, the
default):
Base: the Mozilla bundle shipped with
certifi. When theSSL_CERT_FILEenvironment variable is set, that file replaces it; otherwise, whenSSL_CERT_DIRis set, that directory replaces it. This is the precedence httpx itself applies, so setting either variable keeps its documented “replace the standard set” meaning.Extra CAs (
ADRIANO_EXTRA_CA_CERTS): every certificate in the configured PEM files (bundles allowed) and in the*.pemand*.crtfiles of the configured directories is added on top of the base, so public endpoints keep working. Each file is parsed withcryptographyfirst; an unreadable file, a file without a PEM certificate or a directory without matching files raisesConfigurationErrornaming it. The added certificates are logged at INFO with their subjects.
With verification off the context checks neither certificates nor host names, and the extra CAs are ignored; one warning says so.
outbound_ssl_context() is cached per argument pair, so a process
builds each context (and logs about it) once. Processes build it at
startup (app.cli.main(), app.main.create_app()) so a bad
CA file stops them instead of failing the first login or poll.
Public API: outbound_ssl_context(),
ssl_context_from_settings(), unverified_ssl_context().
- app.tls.outbound_ssl_context(verify=True, extra_ca_certs=())¶
Build (once per arguments) the context for outbound HTTPS.
- Parameters:
- Return type:
- Returns:
The shared context; callers must not modify it.
- Raises:
ConfigurationError – If an extra CA path cannot be loaded.
- app.tls.ssl_context_from_settings(settings)¶
Return the outbound context for the application settings.
- Parameters:
settings (
Settings) – Application settings.- Return type:
- Returns:
The shared context (see
outbound_ssl_context()).- Raises:
ConfigurationError – If an extra CA path cannot be loaded.
- app.tls.unverified_ssl_context()¶
Build a TLS context that skips certificate and hostname checks.
Used only when
ADRIANO_TLS_VERIFYis false.- Return type:
- Returns:
The context.