Skip to content

cpython: make bundled pip prefer the system CA bundle - #576524

Open
zimbatm wants to merge 1 commit into
NixOS:stagingfrom
zimbatm:cacert-python3
Open

zimbatm wants to merge 1 commit into
NixOS:stagingfrom
zimbatm:cacert-python3

Conversation

@zimbatm

@zimbatm zimbatm commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

pip vendors certifi and adds its cacert.pem to the trust store next to the system store. Every venv made with python -m venv gets this pip from ensurepip. Thus a cacert update alone does not remove a distrusted root (for example emSign ECC Root CA - G3) from pip in a venv.

Rewrite the bundled pip wheel so that its vendored certifi returns NIX_SSL_CERT_FILE, SSL_CERT_FILE or /etc/ssl/certs/ca-certificates.crt when one exists. The vendored bundle stays as a fallback.

The override lives in pkgs/development/interpreters/python/pip-certifi-override.py. The python3Packages.pip PR appends the same file to its own vendored certifi: #576525

Tested on x86_64-linux with python3 3.14 (same diff on master): in a venv, pip download six with SSL_CERT_FILE set to an unrelated self-signed cert fails, and with the system bundle it works. Before the change both worked, because pip also trusted its vendored bundle.

Related to: #576485
Related to: #576542

Assisted-by: Claude Code (claude-opus-5)

Things done

pip vendors certifi and adds its cacert.pem to the trust store next to
the system store. Every venv made with `python -m venv` gets this pip
from ensurepip. Thus a cacert update alone does not remove a distrusted
root (for example emSign ECC Root CA - G3) from pip in a venv.

Rewrite the bundled pip wheel so that its vendored certifi returns
NIX_SSL_CERT_FILE, SSL_CERT_FILE or /etc/ssl/certs/ca-certificates.crt
when one exists. The vendored bundle stays as a fallback.

The override lives in pkgs/development/interpreters/python/pip-certifi-override.py,
so that python3Packages.pip can append the same code to its vendored certifi.

Assisted-by: Claude Code (claude-opus-5)
@nixpkgs-ci
nixpkgs-ci Bot requested a review from mweinelt October 20, 2026 19:58
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. llm-assisted Contributions that include code generation with LLMs 6.topic: python Python is a high-level, general-purpose programming language. labels Oct 20, 2026
@hesiod hesiod added the 1.severity: security Issues which raise a security issue, or PRs that fix one label Oct 20, 2026
@zimbatm zimbatm added the backport staging-26.05 Backport PR automatically label Oct 20, 2026

@dotlambda dotlambda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Include a sitecustomize.py file
cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
''
+ optionalString withOpenssl ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip is bundled even in python3Minimal where this is false.

@mBornand mBornand mentioned this pull request Oct 29, 2026
3 of 13 tasks
@mBornand

Copy link
Copy Markdown
Contributor

Apply https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/python-modules/certifi/env.patch to the vendored certifi instead. We don't want to maintain the same patch in multiple places.

#580722 uses it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.severity: security Issues which raise a security issue, or PRs that fix one 6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. backport staging-26.05 Backport PR automatically llm-assisted Contributions that include code generation with LLMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants