-
Notifications
You must be signed in to change notification settings - Fork 0
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
Set the SSL_CERT_FILE environment variables via an activation script on Windows #21
Set the SSL_CERT_FILE environment variables via an activation script on Windows #21
Conversation
…on Windows to make sure Python can do HTTPS requests by default without requiring certifi.
3bf0f8f
to
2fa0139
Compare
…FIX and properly unset __CONDA_OPENSLL_CERT_FILE_SET
47637b1
to
ff7e5a1
Compare
@chenghlee do you know if I need to add a PowerShell activation script? |
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.
These look ok to me. I don't see anything that raises a red flag. We require ca_certificates so we should be ok to always find them as well.
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.
could you please tell us the reason of that PR why export SSL_CERT_FILE is better than the certifi ?
@M-Waszkiewicz-Anaconda I updated the PR description. |
I think you do need to add them. From what I see: |
thank you, so if I understand correctly the %CONDA_PREFIX%\Library\ssl\cacert.pem wasn't part of certifi or for some other reason it was not working |
No, |
d481cd4
to
e4cd4a1
Compare
- python -c "import certifi; import ssl; import urllib.request as urlrq; urlrq.urlopen('https://pypi.org', context=ssl.create_default_context(cafile=certifi.where()))" # [win] | ||
- if "%SSL_CERT_FILE%"=="" exit 1 # [win] | ||
- if not exist "%SSL_CERT_FILE%" exit 1 # [win] | ||
- python -c "import urllib.request; urllib.request.urlopen('https://pypi.org')" |
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.
Wouldn't it be extra beneficial to also check in the test.commands
section that cacert.pem
are also delivered and present in the intended ${CONDA_PREFIX}
path?
As described in the PR description, this change standardize the way of setting certificate location regardless of the platform. Personally, I'm unsure of any unintended consequences on Windows. Otherwise this change seems fine to me. |
Set the
SSL_CERT_FILE
environment variable via an activation script on Windows to make sure Python can do HTTPS requests by default without requiringcertifi
.Note that the activation scripts will only be bundled on Windows. Also note that we will only set
SSL_CERT_FILE
if not not yet set. If a customer has set its ownSSL_CERT_FILE
, we don't want to override it to something else.For more context, when compiling OpenSSL, we can pass the
--openssldir
flag. The openssl dir is the directory wherethe OpenSSL config can be found. The path given to
--openssldir
gets hardcoded in the libraries.On Linux and macOS, we set it to
$PREFIX/ssl
(implicitly by setting--prefix
) and when the package is installed inan environment, conda takes care of replacing the the prefix in the DSOs with the path to the environment where the package is being installed.
$PREFIX/ssl
is populated with a file namedcacert.pem
which comes from theca-certificates
package. So when we use the openssl package, it uses this file.But on Windows, conda doesn't do any DSO prefix replacement. So we hardcode the value to
%CommonProgramFiles%\ssl
for security reasons (see
openssl-feedstock/recipe/bld.bat
Lines 7 to 15 in 67f77d1
and https://anaconda.atlassian.net/browse/DSNC-2391). Because of that, openssl doesn't know anything about CA root certs and calling
urllib.request.urlopen
in python on Windows will result in an error likeThis is because Python doesn't use the Windows system truststore and since
%CommonProgramFiles%\ssl
likely doesn't exist, then it fails.Setting
$SSL_CERT_FILE
avoids this problem. It makes it consistent across all platforms.