Skip to content

SSL: Trust CA file in addition to default CA bundle and use it for all requests - #380

Merged
iLLiCiTiT merged 8 commits into
developfrom
enhancement/extra-ca-file
Nov 10, 2026
Merged

iLLiCiTiT merged 8 commits into
developfrom
enhancement/extra-ca-file

Conversation

@iLLiCiTiT

@iLLiCiTiT iLLiCiTiT commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Changelog Description

A CA file set in AYON_CA_FILE (or passed as ssl_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's tls internal) works with only AYON_CA_FILE set to that CA. Merging it with certifi's cacert.pem and setting REQUESTS_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:

  1. CA file replaced the default bundle. requests and websocket-client use 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.
  2. Some requests ignored the CA file. Requests of ServerAPI made without an authorized session used plain requests.get/requests.post without verify and cert. That includes server version, login(), and downloads and uploads without a session. login_to_server, logout_from_server, take_web_action_event and abort_web_action_event didn't read AYON_CA_FILE either. So the AYON launcher login (server check and password login) and web actions failed with only AYON_CA_FILE set, which is the "known bug" from the community guide.

Changes:

  • Sessions get an HTTPAdapter with an SSL context that has the default bundle (REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE or certifi, same as requests) and the CA file loaded. session.verify stays the path, so older requests versions, which override the SSL context of the adapter for verify=True, behave the same.
  • The adapter is mounted only when ssl_verify is a path, and replaced by the default adapter when set_ssl_verify changes it to a bool.
  • The context has check_hostname disabled because urllib3 matches the hostname itself, as it does with its own context. Without that, urllib3 1.26 fails for servers reached by IP address (check_hostname requires server_hostname).
  • Websockets get the same context through sslopt["context"], unless the caller passes their own, with the client certificate loaded into it, because websocket-client ignores certfile and ca_certs with a custom context.
  • The context doesn't match the commonName of certificates without a subjectAltName, same as the default context of urllib3 2.
  • All connections of the adapter share one context, and urllib3 loads the client certificate into it. set_cert mounts a new adapter, so the previous certificate isn't sent anymore. Passing verify per request to the session doesn't restrict trust to it, documented in the adapter docstring.
  • An error loading the CA file names its path.
  • Requests without an authorized session go through the validation session, which already has ssl_verify and cert. _base_functions_mapping is kept, so code and tests replacing its functions still work.
  • login_to_server, logout_from_server, take_web_action_event and abort_web_action_event got verify and cert arguments, with the same defaults from AYON_CA_FILE/AYON_CERT_FILE as get_user_info_by_token. ServerAPI passes its values on logout.
  • Helpers in utils.py (validate_url, the four above, get_user_info_by_token without a session) and the token check of EventHub send requests through send_request, a short-lived session with the same adapter. So the CA file is trusted in addition to the default bundle everywhere, not only in ServerAPI. The SSL helpers moved from server_api.py to utils.py for that.
  • resolve_ssl_args in utils.py is the one place that fills None values from AYON_CA_FILE/AYON_CERT_FILE, used by ServerAPI and all helpers. Its docstring documents that verify=True (default bundle only) and cert="" (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 empty cert is kept, so ServerAPI passing it to helpers doesn't fill it from the environment again.
  • No new environment variables. To trust only the private CA, as AYON_CA_FILE did before, also set REQUESTS_CA_BUNDLE to 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:

  1. On requests 2.27.1 + urllib3 1.26, requests 2.32.0 + urllib3 1.26, requests 2.32.3 + urllib3 2.6 and requests 2.34.2 + urllib3 2.7, with the CA file:
    • Sessions and websockets connect both to the local server and to public servers (pypi.org, ws.postman-echo.com). On develop the public ones fail.
    • Still rejected: other CA, hostname mismatch, ssl_verify=True against the private server, and going back to True via set_ssl_verify.
    • Server with an IP address SAN reached by IP works.
  2. The calls the launcher login (qml_login.py) and web actions (start.py) make, with only AYON_CA_FILE set: 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_event and abort_web_action_event all work. On 1.2.27, which the launcher pins, all but validate_url and get_user fail with CERTIFICATE_VERIFY_FAILED.
  3. With only the generated CA in AYON_CA_FILE, all those calls also work against a server with a public certificate (pypi.org). With a different CA in AYON_CA_FILE, the helpers reject the local server.
  4. python automated_api.py makes no changes.
  5. Offline tests pass (token validation, download resume, EventHub lifecycle and ping, request retries, max retries kwarg, server version validation, GraphQL pagination).
  6. Against a local server requiring a client certificate, and one with a certificate without subjectAltName, on all four stacks: the websocket sends the client certificate, set_cert(None) stops sending it, the certificate without subjectAltName is rejected (on urllib3 1.26 REST still accepts it, as on develop), and a missing CA file raises an error with the path.

To test against a real server, set AYON_CA_FILE to Caddy's root.crt only (no merge, no REQUESTS_CA_BUNDLE/SSL_CERT_FILE) and log in with the AYON launcher.

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>
@iLLiCiTiT iLLiCiTiT added the type: enhancement New feature or request label Nov 9, 2026
@iLLiCiTiT
iLLiCiTiT requested a review from BigRoy November 9, 2026 08:57
@iLLiCiTiT iLLiCiTiT self-assigned this Nov 9, 2026
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>
@iLLiCiTiT iLLiCiTiT changed the title SSL: Trust CA file in addition to default CA bundle SSL: Trust CA file in addition to default CA bundle and use it for all requests Nov 9, 2026
'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>
iLLiCiTiT and others added 4 commits November 9, 2026 10:36
'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>
Comment thread ayon_api/server_api.py Resolved

@BigRoy BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread ayon_api/utils.py Outdated
Comment on lines +610 to +636
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 BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests run with Caddy seemed to pass via this but fail on develop.

@iLLiCiTiT
iLLiCiTiT merged commit 4b248d4 into develop Nov 10, 2026
3 checks passed
@iLLiCiTiT
iLLiCiTiT deleted the enhancement/extra-ca-file branch November 10, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants