Add ssl_context_factory for custom SSLContext configuration#2920
Merged
Add ssl_context_factory for custom SSLContext configuration#2920
ssl_context_factory for custom SSLContext configuration#2920Conversation
Contributor
|
📖 Docs preview: https://3a5dd082.uvicorn.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 185e0d4f02
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… without ssl_certfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ssl_context_factoryparameter for custom SSL contexts #2833Summary
Adds an
ssl_context_factoryparameter toConfiganduvicorn.run()for advanced TLS scenarios that the existingssl_*flags don't cover (mutual TLS, certificate pinning, customSSLContext.options, password-protected keys loaded from memory, etc.).The factory receives the
Configand adefault_ssl_context_factorycallable that builds the standard context from thessl_*settings. Users can either start from the default and mutate it, or build their own context from scratch.The design is inspired by gunicorn's
ssl_contexthook.Usage
Behaviour
Config.load(), which runs in each worker process, so it works with--reloadand--workers > 1. The factory itself must be picklable in those modes (a top-level function works; a lambda or local closure does not).ssl_context_factoryis set together withssl_keyfile/ssl_certfile, a warning is logged - those values are only used by the default factory the user receives, not directly by uvicorn.TypeErroris raised if the factory returns something other than anssl.SSLContext.is_sslreturnsTruewhen the factory is set, even withoutssl_keyfile/ssl_certfile.Checklist
AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.