Skip to content
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

SSLCertVerificationError when behind a firewall — system SSL certs are not respected #6038

Closed
sm-Fifteen opened this issue Jul 21, 2022 · 5 comments
Labels
enhancement An improvement of an existing feature

Comments

@sm-Fifteen
Copy link

Every now and then (not sure what triggers it), when running a Prefect Orion server on Windows while behind a corporate VPN, I get strange SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1108)') errors from this line:

async with httpx.AsyncClient() as client:
result = await client.post(
"https://sens-o-matic.prefect.io/",
json=heartbeat,
headers={"x-prefect-event": "prefect_server"},
)

The error doesn't seem to affect the user-facing behavior of the application, but it certainly clutters the logs.

This is occuring because httpx uses certifi for its SSL validation, which is completely fine on normally configured machines, but a lot of corporate firewalls do SSL inspection, where all external traffic is intercepted and re-encrypted using a self-signed authority (so basically a man-in-the-middle on all employee workstations). That CA certificate is present in the device CA stores, but is naturally absent from stores like certifi, so httpx will reject all responses to external HTTP ressources.

The httpx doc says this can easily be fixed by using the system SSL context instead of the default one.

import ssl
import httpx
context = ssl.create_default_context()

async with httpx.AsyncClient(verify=context) as client:
        response = await client.get('https://example.org')

This also affects some example flows, like the "Basic Orchestration" github stars one, which also uses httpx.

@jawnsy jawnsy added the v2 label Jul 21, 2022
@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment.

@github-actions github-actions bot added the status:stale This may not be relevant anymore label Mar 30, 2023
@zanieb
Copy link
Contributor

zanieb commented Mar 30, 2023

We're willing to accept the addition of a setting that changes the default behavior as discussed in #7596 (comment)

@zanieb zanieb added status:accepted We may work on this; we will accept work from external contributors and removed status:stale This may not be relevant anymore v2 labels Mar 30, 2023
@zanieb zanieb changed the title SLL error from Orion server when telemetry is sent from behind corporate firewall SSLCertVerificationError when behind a firewall — system SSL certs are not respected Mar 30, 2023
@zanieb zanieb added priority:medium enhancement An improvement of an existing feature labels Mar 30, 2023
@jawnsy
Copy link
Contributor

jawnsy commented Mar 30, 2023

Hey there! After further investigation, we believe that you can handle this situation by setting SSL_CERT_FILE or SSL_CERT_DIR as needed to use your own certificates. For more information, please see the httpx documentation for SSL_CERT_FILE.

We're therefore closing this issue. Please feel free to reply if this is insufficient for your needs.

@jawnsy jawnsy closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2023
@github-actions github-actions bot removed the status:accepted We may work on this; we will accept work from external contributors label Mar 30, 2023
@sm-Fifteen
Copy link
Author

Actually, now that truststore is starting to become stable (it hit beta status earlier this month and is being integrated with pip), it should be possible to swap certifi with it and just do this on Python 3.10 and above:

import httpx
import ssl
import truststore

ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client = httpx.Client(verify=ssl_context)

It might end up being fixed upstream on httpx's side at some point. though.

We're therefore closing this issue. Please feel free to reply if this is insufficient for your needs.

The issue was never really a showstopper in my case, since like I mentionned in my original post, it mainly affects (or rather affected at the time, it's been a while since I last checked) outgoing telemetry, and httpx usage as portrayed in the tutorial. User flows can still disable HTTPS validation or use truststore explicitly if your Python version is compatible.

Note for bystanders: Using SSL_CERT_FILE on Windows is a bit of a hassle, since you need to use certlm.msc to dump the certificates (in base64 PEM encoding) from the system store and then concatenate the contents of these files (in order, starting from the root) manually to have the full trust chain in a single file. Once you have it, though, you can also use it with Pip (which uses REQUESTS_CA_BUNDLE) and Npm (which uses NODE_EXTRA_CA_CERTS).

@zanieb
Copy link
Contributor

zanieb commented Mar 30, 2023

Thanks for the additional context!

Additionally, note that telemetry can always be disabled :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants