-
-
Notifications
You must be signed in to change notification settings - Fork 844
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
Drop certifi, use system trust store by default #302
Comments
It's been a while since this was raised has been brought up recently a couple of times, could we go into detail of what's needed here? For reference oscrypto lists other related libraries, would any of those fit our needs? (I'd look myself but I just don't know enough about the subject 🙂 ) |
Hey! So considering the amount of 👍's on this issue I thought it would make sense to take some kind of decision on this as part of 1.0 - #947 (comment) I'm personally on the side of dropping I'm pretty much a n00b in terms of TLS implementations, let alone system compatibility, so let me ask what I feel might be a n00b question but maybe not after all… What if we just used From the docs (emphasis mine):
TL;DR: it looks to me (*The usage of "can" in the docs looks suspicious to me. Are there cases when Python wouldn't trust the default system CA? And what happens if it doesn't? Would the default I'm wondering if this wouldn't be an okay default, mainly because two notable projects use and/or recommend the use of |
Not my core expertise, but pretty sure it's not a solved issue. I sat down with @Lukasa last year briefly, and one of the technical issues we talked about was dropping certifi, and the complexities of accessing the system trust store on different O/S's. I'm sure @sethmlarson has a much better handle on the current state of affairs here. I think either @tiran's or @glyph's name might also have come up in my conversation with Cory, wrt. folks having done some work in this area, but I might be getting that wrong. Kinda a PyCon type thing that would've benefited from being able to chat it out with relevant folks, but... In any case, assuming I have got the landscape correct here, I think "use system trust store by default" sits firmly in "make this work in an independent, tightly-scoped third party package", rather than specifically "solve this in httpx". If and when such a package exists, then yup we can take a look at using it, otherwise it's in the realm of "this isn't a resolved issue in the Python ecosystem, certifi is the best we can do until then". |
Just found out about this discussion starting back from 2016 in the Requests repo, loads of good background there: psf/requests#2966 Edit, after reading it:
Agreed. (Also I think I found an answer there to "Wouldn't |
I need to finish my prototype... |
Another data point in favor of us keeping certifi at this time: In a lot of these issues the solutions are often a mix of "disable cert validation" or "use certifi". |
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=960869 should help to solve a bunch of problems. Fedora / RHEL should have root CA certificates installed. I'll verify UBI mini tomorrow. |
@tiran How far along is that prototype? 😄 |
A short-term solution might be to support pulling a CA bundle from environment variables (requests also supports this). This gives a knob for system administrators to make httpx behave. On the prior art pile, urllib3 supports SecureTransport, but not SChannel. EDIT: Oh, they stole code from https://github.com/wbond/oscrypto which looks a lot more complete Since this hasn't been mentioned in the thread, TLS has several knobs with regards to security, the big ones being algorithm selection and server certificate policies. Per the docs:
This is basically drops the horribly insecure options and presents an ok default. (I am not enough of a security expert to say how good these defaults are.) In general, OpenSSL is complex, probably more complex than necessary. |
Also, a moment of silence for PEP 543. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Bump. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Linking to Seth's work on this... https://github.com/sethmlarson/truststore |
We're hitting this issue as well when using ZTNA, for requests we are able to set the We can implement the cert logic at the application level; however, this will lead to inconsistent behavior as the use of HTTPX grows. |
Are https://www.python-httpx.org/environment_variables/#ssl_cert_file
Can you be more specific? |
Using import httpx
import ssl
import truststore
ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client = httpx.Client(verify=ssl_context) |
EDIT: I misread it the first time. Setting SSL_CERT_FILE environment like I do REQUESTS_CA_CERT works. |
@madkinsz my bad, I must have developed a reading comprehension failure. Yes, SSL_CERT_FILE solves the problem. |
I'd suggest that we add this example to our documentation here either verbatim or as a gist, and then close this issue. Related... I believe that our ssl context API would be better as |
Please make it clear to admins (not just developers) how to set this. The problem is that most developers only care about this in the "please forward this option" sense, and laziness/ignorance means they won't. It is dependent on the environment the end software is used in what is the reasonable default. But as someone that's been the enterprise sysadmin that's thrice-cursed certifi's lack of overrides, the use of |
you saved my day! |
Problem with the proposed solution is that this only work for direct uses of httpx. HTH |
Closes #1474 Using the `rustls-tls-native-roots` feature > `rustls-tls`: Enables TLS functionality provided by rustls. Equivalent to rustls-tls-webpki-roots. > > `rustls-tls-webpki-roots`: Enables TLS functionality provided by rustls, while using root certificates from the webpki-roots crate. > > `rustls-tls-native-roots`: Enables TLS functionality provided by rustls, while using root certificates from the rustls-native-certs crate. Additional context: - seanmonstar/reqwest#1554 - encode/httpx#302 - [Should I use the native certs or webpki-roots?](https://github.com/rustls/rustls-native-certs#should-i-use-this-or-webpki-roots) Prior discussion at #609
I'm using a package which uses httpx as it's http client. there is no constructor arguments to pass client or the httpx verify arg to it. basically stuck here. |
So @sethmlarson's |
Truststore is used by pip and PDM, so should be good to adopt if you are still interested. Still requires Python 3.10 or later, though. We also already have integration tests for HTTPX specifically: https://github.com/sethmlarson/truststore/blob/main/tests/test_inject.py#L116 |
Yup, very much interested.
Okay, that's a consideration for us, tho we could potentially have a fallback to certifi for 3.8 and 3.9.
I knew truststore was an option in |
I would love if it became the default on 3.10+ for v1.0! It's what I plan to do for Hatch anyway so it would save me time and it's what is desirable everywhere I've ever worked. |
It's worth noting that the Rust community is also going in the direction of making system certificate verification the default with this new package that everyone is transitioning to https://github.com/rustls/rustls-platform-verifier |
Hm interesting. uv does not use system certificates by default (and we don't really get complaints about it). |
It looks like you do astral-sh/uv#1512 Edit: ah by default you mean but is supported. I assume by not getting complaints is because you have support for it via an option |
This is an issue that many people have been trying to tackle for Python but hasn't been done yet. I think we're in a pretty good position to try to tackle this in a way that can be available to everyone.
This should probably be implemented as a separate library, maybe use a stripped-down oscrypto project as a starting point.
Reasons to do this:
The text was updated successfully, but these errors were encountered: