Repository navigation
SSL: Trust CA file in addition to default CA bundle and use it for all requests - #380
Conversation
A CA file in 'ssl_verify' (or 'AYON_CA_FILE') replaced the default CA bundle of 'requests' and 'websocket', so a server signed by a private CA was trusted but nothing else. Sessions now use an adapter with SSL context trusting both, and websockets get the same context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Requests of 'ServerAPI' without authorized session (server version, login, downloads and uploads) used plain 'requests' functions without 'ssl_verify' and 'cert'. They now use the validation session. Also 'login_to_server' and 'logout_from_server' use 'AYON_CA_FILE' and 'AYON_CERT_FILE'. Login in AYON launcher failed with only 'AYON_CA_FILE' set because of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
'take_web_action_event' and 'abort_web_action_event' did not use 'AYON_CA_FILE' and 'AYON_CERT_FILE', so web actions in AYON launcher failed with server signed by private CA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
'server_api' subclasses 'requests.adapters.HTTPAdapter' on import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Helpers in 'utils' and token check of 'EventHub' passed the CA file to plain 'requests', which replaces the default CA bundle. With only a studio CA in 'AYON_CA_FILE', a server with public certificate failed in server check, login and web actions, while 'ServerAPI' worked. SSL helpers moved to 'utils' and the helpers use '_send_request', which sends the request through a session with the CA file adapter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
'resolve_ssl_args' fills 'None' values from 'AYON_CA_FILE' and 'AYON_CERT_FILE' and documents that 'verify=True' and 'cert=""' skip them, e.g. for a process connected to multiple servers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BigRoy
left a comment
There was a problem hiding this comment.
Code changes make sense, not sure if the string operations with the request type .lower() check is really needed and whether it can't be done matching it more directly through some constant dict instead of having to do those every time on every request.
@MustafaJafar can probably test whether it does indeed solve his use cases.
There was a problem hiding this comment.
🟡 Changes recommended
The security-critical trust-store merge and verification transitions are not covered by local HTTPS tests, leaving regressions to default-only, additional-CA, or boolean verification behavior undetected.
1 open issue
What changed in this PR
This pull request updates AYON SSL handling so custom CA files are trusted alongside the default CA bundle and applied consistently across REST, WebSocket, authentication, web-action, and event requests.
Changes:
- Adds shared SSL context, CA resolution, adapter, and request-session helpers.
- Applies SSL configuration to authenticated and unauthenticated API requests, WebSockets, login/logout, web actions, and event-token checks.
- Updates API-generation request stubs to support the new adapter dependency.
- Nit (2 votes): Add HTTPS integration coverage for default-only trust, additional CA trust, and switching back to boolean verification.
| File | Description |
|---|---|
ayon_api/utils.py |
Adds CA bundle resolution, SSL context creation, request-session configuration, and SSL-aware helper requests. |
ayon_api/server_api.py |
Applies merged CA trust to API sessions, unauthenticated requests, WebSockets, and logout operations. |
ayon_api/events.py |
Uses the SSL-aware request helper for event-hub token validation. |
automated_api.py |
Extends the request-module stub to support the new HTTP adapter dependency. |
Review effort: Lite
| def create_ssl_context(ca_path: str) -> ssl.SSLContext: | ||
| """SSL context trusting default CA bundle and CA certificates from path. | ||
|
|
||
| A CA file passed to 'requests' or 'websocket' replaces their default | ||
| CA bundle, so a server signed by a private CA would be trusted but | ||
| nothing else (e.g. redirects to cloud storage). The context trusts | ||
| both instead. | ||
|
|
||
| Args: | ||
| ca_path (str): Path to CA file or directory with CA certificates. | ||
|
|
||
| Returns: | ||
| ssl.SSLContext: SSL context for client connections. | ||
|
|
||
| """ | ||
| default_bundle = get_requests_ca_bundle() | ||
| if default_bundle and os.path.isdir(default_bundle): | ||
| context = ssl.create_default_context(capath=default_bundle) | ||
| elif default_bundle: | ||
| context = ssl.create_default_context(cafile=default_bundle) | ||
| else: | ||
| context = ssl.create_default_context() | ||
|
|
||
| if os.path.isdir(ca_path): | ||
| context.load_verify_locations(capath=ca_path) | ||
| else: | ||
| context.load_verify_locations(cafile=ca_path) |
- Websocket loads client certificate to the custom SSL context, because 'websocket' ignores 'certfile' when context is passed. - 'set_cert' recreates CA file adapter, 'urllib3' loads client certificate to its shared SSL context so the previous one was sent. - SSL context does not match 'commonName' of certificates without 'subjectAltName', same as 'urllib3' 2 default context. - Error of CA file that can't be loaded contains its path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BigRoy
left a comment
There was a problem hiding this comment.
Tests run with Caddy seemed to pass via this but fail on develop.

Changelog Description
A CA file set in
AYON_CA_FILE(or passed asssl_verify) is now trusted in addition to the default CA bundle instead of replacing it, and it's used by all requests to the server. A server with a certificate from a private CA (e.g. Caddy'stls internal) works with onlyAYON_CA_FILEset to that CA. Merging it with certifi'scacert.pemand settingREQUESTS_CA_BUNDLE/SSL_CERT_FILE, as described in Running a self-hosted AYON server with HTTPS, is no longer needed.Additional info
Two separate problems:
requestsandwebsocket-clientuse a CA file as the only trusted authorities. With only the private CA, the AYON server was trusted, but nothing else was, e.g. redirects to cloud storage.ServerAPImade without an authorized session used plainrequests.get/requests.postwithoutverifyandcert. That includes server version,login(), and downloads and uploads without a session.login_to_server,logout_from_server,take_web_action_eventandabort_web_action_eventdidn't readAYON_CA_FILEeither. So the AYON launcher login (server check and password login) and web actions failed with onlyAYON_CA_FILEset, which is the "known bug" from the community guide.Changes:
HTTPAdapterwith an SSL context that has the default bundle (REQUESTS_CA_BUNDLE,CURL_CA_BUNDLEor certifi, same asrequests) and the CA file loaded.session.verifystays the path, so olderrequestsversions, which override the SSL context of the adapter forverify=True, behave the same.ssl_verifyis a path, and replaced by the default adapter whenset_ssl_verifychanges it to a bool.check_hostnamedisabled becauseurllib3matches the hostname itself, as it does with its own context. Without that,urllib31.26 fails for servers reached by IP address (check_hostname requires server_hostname).sslopt["context"], unless the caller passes their own, with the client certificate loaded into it, becausewebsocket-clientignorescertfileandca_certswith a custom context.commonNameof certificates without asubjectAltName, same as the default context ofurllib32.urllib3loads the client certificate into it.set_certmounts a new adapter, so the previous certificate isn't sent anymore. Passingverifyper request to the session doesn't restrict trust to it, documented in the adapter docstring.ssl_verifyandcert._base_functions_mappingis kept, so code and tests replacing its functions still work.login_to_server,logout_from_server,take_web_action_eventandabort_web_action_eventgotverifyandcertarguments, with the same defaults fromAYON_CA_FILE/AYON_CERT_FILEasget_user_info_by_token.ServerAPIpasses its values on logout.utils.py(validate_url, the four above,get_user_info_by_tokenwithout a session) and the token check ofEventHubsend requests throughsend_request, a short-lived session with the same adapter. So the CA file is trusted in addition to the default bundle everywhere, not only inServerAPI. The SSL helpers moved fromserver_api.pytoutils.pyfor that.resolve_ssl_argsinutils.pyis the one place that fillsNonevalues fromAYON_CA_FILE/AYON_CERT_FILE, used byServerAPIand all helpers. Its docstring documents thatverify=True(default bundle only) andcert=""(no client certificate) skip the environment variables, e.g. for a process syncing between a server with a studio CA and a publicly signed one. An emptycertis kept, soServerAPIpassing it to helpers doesn't fill it from the environment again.AYON_CA_FILEdid before, also setREQUESTS_CA_BUNDLEto it. It's used as the default bundle. This is a behaviour change worth mentioning in the release notes.Testing notes:
Tested with a local HTTPS server whose certificate is signed by a generated CA:
pypi.org,ws.postman-echo.com). Ondevelopthe public ones fail.ssl_verify=Trueagainst the private server, and going back toTrueviaset_ssl_verify.qml_login.py) and web actions (start.py) make, with onlyAYON_CA_FILEset:validate_url,ServerAPI(url).server_version_tuple,login_to_server,ServerAPI(url).raw_get("info"),ServerAPI(url, token).get_user,ServerAPI(url).login,logout_from_server,take_web_action_eventandabort_web_action_eventall work. On 1.2.27, which the launcher pins, all butvalidate_urlandget_userfail withCERTIFICATE_VERIFY_FAILED.AYON_CA_FILE, all those calls also work against a server with a public certificate (pypi.org). With a different CA inAYON_CA_FILE, the helpers reject the local server.python automated_api.pymakes no changes.subjectAltName, on all four stacks: the websocket sends the client certificate,set_cert(None)stops sending it, the certificate withoutsubjectAltNameis rejected (onurllib31.26 REST still accepts it, as ondevelop), and a missing CA file raises an error with the path.To test against a real server, set
AYON_CA_FILEto Caddy'sroot.crtonly (no merge, noREQUESTS_CA_BUNDLE/SSL_CERT_FILE) and log in with the AYON launcher.