Skip to content

python3Packages.certifi: Update and use system ca-bundle - #205127

Merged
mweinelt merged 3 commits into
NixOS:stagingfrom
mweinelt:certifi
Dec 8, 2022
Merged

mweinelt merged 3 commits into
NixOS:stagingfrom
mweinelt:certifi

Conversation

@mweinelt

@mweinelt mweinelt commented Dec 8, 2022 •

Copy link
Copy Markdown
Member

We update the system ca-bundle more reliably, and it allows ties in with module based
configuration applied through security.pki.

Fixes: CVE-2022-23491

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@mweinelt mweinelt added the 1.severity: security Issues which raise a security issue, or PRs that fix one label Dec 8, 2022
@github-actions github-actions Bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Dec 8, 2022
@mweinelt mweinelt added backport staging-22.11 and removed 6.topic: python Python is a high-level, general-purpose programming language. labels Dec 8, 2022
@github-actions github-actions Bot added the 6.topic: python Python is a high-level, general-purpose programming language. label Dec 8, 2022
@vcunat

vcunat commented Dec 8, 2022

Copy link
Copy Markdown
Member

@ofborg eval

We update that one more reliably and it allows ties in with module based
configuration applied through `security.pki`.

Also allow overwriting the CA bundle used through `NIX_SSL_CERT_FILE`
as is common throughout nixpkgs.

Fixes: CVE-2022-23491
The where() function in certifi has been patched to allow more consumers
of the certifi package to use the system ca-bundle.
@ofborg
ofborg Bot requested review from SuperSandro2000 and fabaff December 8, 2022 15:31
@ofborg ofborg Bot added 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-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. labels Dec 8, 2022

@SuperSandro2000 SuperSandro2000 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.

didn't double check the patch with the original code but LGTM

@github-actions

github-actions Bot commented Dec 8, 2022

Copy link
Copy Markdown
Contributor

Successfully created backport PR #205191 for staging-22.11.

@vcunat

vcunat commented Dec 9, 2022

Copy link
Copy Markdown
Member

This broke the build of python3.pkgs.sphinx:
https://hydra.nixos.org/log/mlnd1mlnk9gr9zg79p5yqxbdkyf82mvq-python3.10-sphinx-5.1.1.drv
(I checked that reverting this merge fixes it.)

@mweinelt

mweinelt commented Dec 9, 2022 •

Copy link
Copy Markdown
Member Author

Happens because of the dummy NIX_SSL_CERT_FILE path passed in from stdenv/generic/setup.sh. Two solutions two this.

  • Unset NIX_SSL_CERT_FILE in preCheck
  • Pass cacert into checkInputs, because its setup script sets up the variable correctly

I think unsetting is fine.

@vcunat

vcunat commented Dec 9, 2022 •

Copy link
Copy Markdown
Member

I wonder if certifi should fix this automatically, e.g. simply propagate cacert as it's in runtime closure anyway.

@vcunat

vcunat commented Dec 9, 2022 •

Copy link
Copy Markdown
Member

Let me elaborate. My understanding of the current design:

  • TLS-related libs prefer not to have any CA certs in closure and during runtime default to OS's current bundle (impure... similarly to the impure changes to real date and servers on the internet)
  • in case certs are needed in tests (not common because they don't have internet access), they put cacert into inputs
  • I'd expect that certifi will be used similarly to cacert

@vcunat

vcunat commented Dec 10, 2022 •

Copy link
Copy Markdown
Member

Hmm, apparently it didn't cover all the cases. I hoped it would work better.

Right now I see pytest-param-files, more-itertools, google-auth* and there will probably be more. Any idea about a more general fix, or will we add cacert or certifi as some input to each of them?

* for google-auth only part of the test failures is due to the missing certs

@trofi

trofi commented Dec 10, 2022

Copy link
Copy Markdown
Contributor

Bisect claims that 8d7cc9c python3Packages.certifi: use system ca-bundle broke python3Packages.scikit-build tests in staging and staging-next:

$ nix build --no-link -f. -L python3Packages.scikit-build
...
python3.10-scikit-build> ==================================== ERRORS ====================================
python3.10-scikit-build> _____________________ ERROR collecting tests/test_setup.py _____________________
python3.10-scikit-build> tests/test_setup.py:329: in <module>
python3.10-scikit-build>     @pytest.mark.skipif(not is_site_reachable("https://pypi.org/simple/cmake/"), reason="pypi.org website not reachable")
python3.10-scikit-build>         CMAKE_INSTALL_DIR = <function CMAKE_INSTALL_DIR at 0x7ffff4b30280>
python3.10-scikit-build>         SKBUILD_DIR = <function SKBUILD_DIR at 0x7ffff4b300d0>
python3.10-scikit-build>         SKBuildError = <class 'skbuild.exceptions.SKBuildError'>
python3.10-scikit-build>         __builtins__ = <builtins>
python3.10-scikit-build>         __cached__ = '/build/scikit-build-0.15.0/tests/__pycache__/test_setup.cpython-310.pyc'
python3.10-scikit-build>         __doc__    = 'test_setup\n----------------------------------\n\nTests for `skbuild.setup` function.\n'
python3.10-scikit-build>         __file__   = '/build/scikit-build-0.15.0/tests/test_setup.py'
python3.10-scikit-build>         __loader__ = <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7ffff6a40a60>
python3.10-scikit-build>         __name__   = 'tests.test_setup'
python3.10-scikit-build>         __package__ = 'tests'
...

@mweinelt

Copy link
Copy Markdown
Member Author

Annoying. The most simple fix would be to ignore NIX_SSL_CERT_FILE when set to /no-cert-file.crt, so we'll force to use the symlinked ca-bundle from cacert.

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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants