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

truststore feature does not work when set in a requirement file #12319

Open
1 task done
JCapul opened this issue Oct 5, 2023 · 5 comments
Open
1 task done

truststore feature does not work when set in a requirement file #12319

JCapul opened this issue Oct 5, 2023 · 5 comments
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior

Comments

@JCapul
Copy link

JCapul commented Oct 5, 2023

Description

Hi,

After digging a bit, I am quite confident that the truststore feature does not work as expected when the option is placed in a requirement file.

In my org, we have a PyPi server with self-signed certs. I managed to make pip install work with the truststore feature when used in command line option, but when used in a requirement files, I get the typical error unable to get local issuer certificate.

Expected behavior

I am expecting no difference in behaviour of the truststore feature whether it is set as command line option or in a requirement file (since the option use-feature is allowed in requirement files).

pip version

23.2.1

Python version

3.10

OS

Windows 10 and Ubuntu 20.04 (I checked both)

How to Reproduce

Not easy to reproduce, as you might need to set up a self signed pypi server or equivalent to reproduce the bug.
But basically, considering a requirements file like this:

requirements.txt

--use-feature truststore
--extra-index-url https://[custom_pypi_server]

some_package_on_custom_pypi_server

the command pip install -r requirements.txt will fail with an SSLContext error (see output after).

However, the command pip install --use-feature truststore -r requirements.txt works as expected.

After digging, I think the issue comes from the fact that without the commad line option, the PipSession object is instanciated with the default SSLContext. But this default context is not replaced by the truststore SSLContext when the --use-feature truststore line is parsed in the requirement file.

Output

$ pip install -r requirements.txt
Looking in indexes: https://pypi.org/simple, https://[custom_pypi_server]/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)'))': /simple/dlab-tools/

Code of Conduct

@JCapul JCapul added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Oct 5, 2023
@SpiderD555
Copy link

This is a chicken and egg problem. To use --use-feature truststore option you need to install truststore first.
My recommendation for you is to install truststore first this way pip install --trusted-host [custom_pypi_server] truststore. Only then you can proceed with the rest of requirements. Now keep in mind that each new venv you create won't have truststore installed, so you will need to repeat the procedure again.
If comment sethmlarson/truststore#116 (comment) is true, then the chicken and egg problem will be no more with pip v23.3

@JCapul
Copy link
Author

JCapul commented Oct 10, 2023

Thanks for you answer.
I forgot to mention that I did install the package truststore beforehand in my environment. And the option --use-feature truststore works as expected when I use it in the pip install command line, but not when embedded in the requirements file.

@uranusjr
Copy link
Member

The problem may be the certificate store is initialised too early in the process and it’s too late when the requirements file is parsed. In general I kind of doubt is --use-features is supposed to be allowed in the first place since it introduces a bunch of weird expectations, such as using the legacy resolver for only one requirements file (it would not work).

@pfmoore
Copy link
Member

pfmoore commented Oct 13, 2023

I agree. My first thought here was “--use-feature doesn’t work in requirements files anyway”, and I was surprised to find that it’s documented to work there. Does anyone know why it was allowed in the first place?

I’d prefer that we deprecate the use of --use-feature in requirements files, and immediately desupport specific cases like this that don’t work. I don’t think the effort of trying to make it work in general is worth it.

@JCapul
Copy link
Author

JCapul commented Oct 13, 2023

Personally, I can live eventually with --use-feature option only in command line. Since it was advertised as possible in documentation and that it looked to be broken for the truststore feature, I raised the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants