The question is, how do I install packages securely with pip, on Ubuntu Trusty? Of course I need to clarify why I believe it's insecure.
urllib3 gives an InsecurePlatformWarning
if you make an https request without a few extra openssl related python libraries installed, before Python 2.7.9. This is a well established question and answer:
InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately
The problem is, if you install pip version 6 or so, it starts giving you this very warning, as you install anything. From reading the official answer to the problem:
https://urllib3.readthedocs.org/en/latest/security.html#pyopenssl
it sounds like the problem lies in the Python ssl library. Did Pip just switch to the Python ssl library from openssl in the latest version? My guess (perhaps a bad guess) is that pip used the Python library before, it just used an older version of urllib that didn't even give the warning. So it's been insecure the whole time (though the particular vuln of concern seems to be somewhat recent).
Well if that's the case, the stock version of pip on Ubuntu isn't safe. I can't use it to safely install the stuff to make it safe. No matter, I can just install the same things from Ubuntu's repo, which verifies packages with GPG:
http://packages.ubuntu.com/search?keywords=python-ndg-httpsclient
Except the above is only available starting in Utopic. On Trusty I appear to be stuck.
So what's the deal? Do I have to roll the dice and install this stuff insecurely once, and then use pip securely only after that? Or am I misreading the situation altogether?
install openssl-devel and then reconfigure/rebuild/reinstall python fixed the problem for me.
This is likely due to libssl being installed, then your python virtualenv env created, then something happening to libssl, such as being upgraded/removed. The first step to resolve is to ensure you have libssl installed. If you're not using pyenv, then however you installed Python remove it and reinstall.
This module provides access to Transport Layer Security (often known as “Secure Sockets Layer”) encryption and peer authentication facilities for network sockets, both client-side and server-side.
pip uses the standard library ssl module by default (unless you also install the extra libraries you've mentioned). Prior to Python 2.7.9 and Python 3.2(ish, I believe it was 3.2, might have been 3.1) the ssl module inside of the standard library lacked the ability to control certain settings related to ssl.
Some of these settings:
As far as what you should do, it's really up to you. If you're installing from PyPI itself a lot of these things simply don't matter much because we disable them on the server side instead of relying on the clients to implement them. However requests (the underlying library pip uses to access a repository) raises these warnings (and pip doesn't silence them) because PyPI is often not the only place you're going to connect to and those additional places may or may not take the same precautions that PyPI has.
Source: I am a core pip developer and administrator of PyPI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With