-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update SSLContext handling #2649
Conversation
Notes for reviewers
|
* Change deprecated ssl.wrap_socket() to SSLContext.wrap_context(). * Add new server hook to allow user to create custom SSLContext. * Updated the documentation. Signed-off-by: Tero Saarni <tero.saarni@est.tech>
I'm going to try to give this a review, but before I forget I just want to link it to #2118 so that we don't forget to consider implication for reload. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean. I like it a lot.
Kind reminder, I'd still be interested in getting this merged :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsaarni good stuff here, thanks.
Having considered implementing this myself in the past ... one of the things I was trying to decide is whether SSLContext
should come from a factory, and if so, how often instances should be created, and where and how long they should be retained. This would presumably have performance impacts and potentially runtime considerations for how TLS configuration such as certificates etc. could be allowed to change.
IIUC your implementation is a factory via a config callable
... which is called for each TLS wrap of a socket when handling connections. My interest is - is that necessary, or should we be reusing SSLContext
instances. I don't have details of what, if anything could be expensive in their construction, but provided safe, reusing a SSLContext
should have some performance benefit, assuming loading certs and keys costs at least something.
Could you confirm my understanding and comment on whether it would be beneficial to change the lifecycle of SSLContext
instances to be something other than single use, e.g. storing them in an attribute in BaseSocket
?
I think that most servers do not use If changing the current logic and reusing the
|
@tsaarni agreed. Now that I look at the deprecated ... it is simply chaining to construct a disposable In future though, without a reused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
def ssl_context(conf): | ||
context = conf.ssl_context(conf) | ||
if context is None: | ||
context = ssl.SSLContext(conf.ssl_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsaarni I wanted to check whether you considered using ssl.create_default_context(...) here instead of constructing directly.
From docs:
The protocol and settings may change anytime without prior
deprecation. The values represent a fair balance between maximum
compatibility and security.
The settings are chosen by the ssl module, and usually represent a higher security level than when calling the SSLContext constructor directly.
Looks like Python is encouraging use here if you want to adopt over-time the baseline secure default-options and features for ssl, with a leaning towards most-secure-defaults. When changes are made in future versions of Python to disable or enable features, they might be made here.
So I think a trade-off between no-unplanned-changes seen by Gunicorn, vs auto-adopt best defaults, which are then overridable.
Interesting also that when the key-logging option was added in python/cpython@c7f7069 , it was added to create_default_context()
and not the ctor.
WDYT?
Edit: I have a commit for this I can push.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @javabrett, thanks for your comments!
I wanted to check whether you considered using ssl.create_default_context(...) here instead of constructing directly.
...
Looks like Python is encouraging use here if you want to adopt over-time the baseline secure default-options and features for ssl, with a leaning towards most-secure-defaults. When changes are made in future versions of Python to disable or enable features, they might be made here.
Using that would mean removing the existing --ssl_version
config option since ssl.create_default_context()
does not accept that option, unlike SSLContext
does. People who care about TLS details are likely aware that --ssl_version
has not fully worked anymore with recent versions of Python, but I was bit unsure about touching that. I assumed the PR might be easier to accept if it is fully backwards compatible, especially since there has not been that much development activity in the project recently. But I do understand if some kind of deprecation process might be wanted to reduce old baggage!
Looking at the current implementation of ssl.create_default_context()
there is not much there at this point besides of the SSLKEYLOGFILE
support. But of course in future this may change and in that case it wuold be nice to pick up secure defaults from there.
(edit 2022-02-18: moved part of the comment down below to better preserve chronological order of discussion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i kepe that discussio open. I would like also go to defaults. A release is planned this week, i will try to add that change myself. If it's a quick change for you feel free to dit by now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benoitc How should the deprecation of the existing config option be done? Should it raise some error that points out the new way? Are we ok with non-backwards compatible change that might potentially break applications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question. That will be a major version, so breaking changes will need at least to be documented. If we want to make it cleaner maybe we can raise a Deprecation warning when the option is used and just ignore it?
@tsaarni I did some ergonomics testing on the new config setting and it highlighted another idea I had earlier ... to test, I took a subset of the functionality in the example config you provided: say just want to set TLSv1.3 only (minimum). I found I wanted to write something like
Changes being:
The difficulty in doing that is that it makes default config harder, since the default value of
I have a commit for this - keen for your thoughts and can push it to your branch for review. |
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
(edit 2022-02-18: moved below part from my previous comment here to better preserve chronological order of discussion)
Good idea! I added a commit in this PR that adds the functionality but I'd like to propose following: It looked to me like |
I think only the |
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
Good catch @dumblob, thanks! I've rebased and regenerated the |
Whoa! Wouldn't expect this sneaky evil behavior. Thanks for pointing it out! Anyone with permissions to merge this? |
@javabrett I've been kinda expecting you to push the button. Any reason we're not ready to merge this? |
What exactly is holding this up? This PR blocks a lot of TLS improvements we'd like to roll out, so if there is anything I could help with to get this merged and released, please let me know! |
@uedvt359 It seems there has not been much activity overall in the project, so I guess the likely reason is that maintainers are just busy and not able to look at this PR. But in case there is any concerns with this PR, I'm of course also interested to work and address them.. |
Kind reminder ❤️ I'm still interested in workign for this getting merged :) |
It looks like this PR is stuck waiting for approval/rereview by @javabrett. Brett, could you please take a look at this again? In your last comment you mentioned you wanted to publish a patch regarding simplifying the default config. Alternatively, can @tilgovi and/or @shevisj and/or @benoitc go forward despite Brett's outstanding comments? |
Could some new maintainers get permission to push to this repo? I think gunicorn is still very useful nowadays despite all the async hype and it is a pity the community is being really slowed down, nearly stopped, by just the lack of permissions. |
i am testing this change. there is a new pending release coming.
On Mon 3 Oct 2022 at 11:31, dumblob ***@***.***> wrote:
Could some new maintainers get permission to push to this repo? I think
gunicorn is still very useful nowadays despite all the async hype and it is
a pity the community is being really slowed down, nearly stopped, by just
the lack of permissions.
—
Reply to this email directly, view it on GitHub
<#2649 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADRISM5LGHTKFXJI3EUT3WBKRVPANCNFSM5D2UAOGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Sent from my Mobile
|
@benoitc: I noticed you made a "prepare for release " commit a week ago. Will this PR be included in this upcoming release? |
yes among other stuffs. I am side tracked by some PR reviews at the moment :) |
Apologies for pestering, but is there an update to the situation? |
merged. I think we shoudl remove some options and just use the default context , will introduce it in a separate change. Thanks for the patch anyway and sorry for that delay to commit it. |
Fixes #1140
Signed-off-by: Tero Saarni tero.saarni@est.tech