Repository navigation
CI: harden build-wheel.yml for the eMudhra/emSign CA incident (12.9.x backport) #3306
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
Merged
+1,360
−74
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| name: Set up hardened Python | ||
| description: >- | ||
| Install CPython with a pinned uv, create a venv from it, and put the venv | ||
| first on PATH. setup-uv verifies the uv binary and uv verifies the | ||
| python-build-standalone archive against embedded checksums, so the | ||
| interpreter's integrity does not depend on TLS. The job then fails unless | ||
| the interpreter's ssl module rejects the compromised eMudhra/emSign CA keys | ||
| (CVE-2026-115557; first fixed releases: 3.11.18, 3.12.16, 3.13.18, 3.14.10, | ||
| 3.15.2), and pip is updated through that ssl module. Unlike setup-python, | ||
| this provides patched Windows builds of maintenance series, for which | ||
| python.org publishes no installers. Series that have no fixed release | ||
| (3.10 and older, which this branch still builds and tests) are installed | ||
| with a warning instead, and their pip is replaced by a sha256-pinned | ||
| wheel, so that the pip update does not depend on TLS. See | ||
| https://github.com/NVIDIA/cuda-python/issues/3195 and | ||
| https://discuss.python.org/t/109678. | ||
|
|
||
| inputs: | ||
| python-version: | ||
| description: >- | ||
| uv Python request, e.g. "3.12" or "3.14t" (free-threaded). The newest | ||
| patch known to the pinned uv is installed. Series with a fixed release | ||
| listed in the interpreter check (3.11-3.15) must carry it. Series | ||
| without a fixed release (3.10 and older) are accepted with a warning, | ||
| and pip is installed from a sha256-pinned wheel. | ||
| required: true | ||
| venv: | ||
| description: Directory for the venv. Defaults to a new directory under RUNNER_TEMP. | ||
| default: "" | ||
|
|
||
| outputs: | ||
| python-path: | ||
| description: Absolute path of the venv's interpreter. | ||
| value: ${{ steps.venv.outputs.python-path }} | ||
| python-version: | ||
| description: Full version of the interpreter, e.g. "3.14.10". | ||
| value: ${{ steps.venv.outputs.python-version }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 | ||
| with: | ||
| # The newest uv whose checksum ships inside the pinned setup-uv, so | ||
| # the binary is verified against the SHA-pinned action itself. The uv | ||
| # release determines the newest patch of each CPython series, so | ||
| # bumping the setup-uv SHA also moves the CPython patch versions. | ||
| version: "latest-known" | ||
| enable-cache: false | ||
| # Some callers (e.g. release verification) have no checkout. | ||
| ignore-empty-workdir: true | ||
|
|
||
| - name: Install Python and create venv | ||
| id: venv | ||
| shell: bash --noprofile --norc -euo pipefail {0} | ||
| env: | ||
| PY_REQUEST: ${{ inputs.python-version }} | ||
| VENV_DIR: ${{ inputs.venv }} | ||
| # A per-job install directory ensures the newest patch known to the | ||
| # pinned uv is used, never an older interpreter left on a persistent | ||
| # self-hosted runner. | ||
| UV_PYTHON_INSTALL_DIR: ${{ runner.temp }}/setup-hardened-python/interpreters | ||
| UV_NO_CONFIG: "1" | ||
| run: | | ||
| uv python install --no-bin --no-registry "${PY_REQUEST}" | ||
| base="$(uv python find --managed-python --no-project "${PY_REQUEST}")" | ||
| venv="${VENV_DIR}" | ||
| if [[ -z "${venv}" ]]; then | ||
| # A fresh directory per call, so a second call in the same job | ||
| # (e.g. build-wheel.yml) leaves the first venv intact. | ||
| venv="$("${base}" -c 'import sys, tempfile; print(tempfile.mkdtemp(prefix="venv-", dir=sys.argv[1]))' "${RUNNER_TEMP}")" | ||
| fi | ||
| # The stdlib venv seeds pip from the interpreter's bundled wheel, so | ||
| # nothing is downloaded before the ssl check below. | ||
| "${base}" -m venv --clear "${venv}" | ||
| if [[ "${RUNNER_OS}" == Windows ]]; then | ||
| py="${venv}/Scripts/python.exe" | ||
| else | ||
| py="${venv}/bin/python" | ||
| fi | ||
| # Let the interpreter report native absolute paths (Windows included). | ||
| python_path="$("${py}" -c 'import sys; print(sys.executable)')" | ||
| "${py}" -c 'import os, sys; print(os.path.dirname(sys.executable))' >> "${GITHUB_PATH}" | ||
| { | ||
| echo "python-path=${python_path}" | ||
| echo "python-version=$("${py}" -c 'import platform; print(platform.python_version())')" | ||
| } >> "${GITHUB_OUTPUT}" | ||
|
|
||
| - name: Check Python interpreter is patched (CVE-2026-115557) | ||
| id: check | ||
| # Runs the venv's python through the PATH entry added above. | ||
| shell: python {0} | ||
| env: | ||
| PYTHON: ${{ steps.venv.outputs.python-path }} | ||
| run: | | ||
| import os | ||
| import platform | ||
| import sys | ||
|
|
||
| if os.path.normcase(sys.executable) != os.path.normcase(os.environ["PYTHON"]): | ||
| print(f"::error::PATH resolves python to {sys.executable}, not the venv interpreter {os.environ['PYTHON']}.") | ||
| sys.exit(1) | ||
|
|
||
| FIXED = {(3, 11): 18, (3, 12): 16, (3, 13): 18, (3, 14): 10, (3, 15): 2} | ||
| # Series that will never get a fixed release (end of life before the | ||
| # fix). Their pip is installed from a pinned wheel instead. | ||
| UNPATCHABLE_BELOW = (3, 11) | ||
| ssl_patched = "true" | ||
| v = sys.version_info | ||
| series = (v.major, v.minor) | ||
| name = f"{v.major}.{v.minor}" | ||
| full = platform.python_version() | ||
| print("sys.version:", sys.version) | ||
| if series in FIXED: | ||
| floor = f"{name}.{FIXED[series]}" | ||
| if v.micro < FIXED[series]: | ||
| print(f"::error::Python {full} is older than {floor}, the first {name} release whose ssl module rejects the compromised eMudhra CA keys (CVE-2026-115557).") | ||
| sys.exit(1) | ||
| print(f"Python {full}: ssl module carries the fix (first fixed: {floor}).") | ||
| elif series < UNPATCHABLE_BELOW: | ||
| ssl_patched = "false" | ||
| print(f"::warning::Python {full}: no {name} release rejects the compromised eMudhra CA keys (CVE-2026-115557); pip will be installed from a sha256-pinned wheel instead.") | ||
| else: | ||
| # Fail closed: a newer series is only accepted once its fixed release is listed. | ||
| print(f"::error::Python {full}: no {name} release is known to reject the compromised eMudhra CA keys (CVE-2026-115557).") | ||
| sys.exit(1) | ||
|
|
||
| with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f: | ||
| f.write(f"ssl-patched={ssl_patched}\n") | ||
|
|
||
| - name: Update pip | ||
| shell: bash --noprofile --norc -xeuo pipefail {0} | ||
| env: | ||
| PYTHON: ${{ steps.venv.outputs.python-path }} | ||
| SSL_PATCHED: ${{ steps.check.outputs.ssl-patched }} | ||
| run: | | ||
| if [[ "${SSL_PATCHED}" == "true" ]]; then | ||
| "${PYTHON}" -m pip install -U pip | ||
| else | ||
| # The interpreter's ssl module still trusts the compromised CA keys, | ||
| # so do not fetch pip through it. The sha256 fragment guarantees the | ||
| # wheel's integrity regardless of the transport. | ||
| "${PYTHON}" -m pip install \ | ||
| "pip @ https://files.pythonhosted.org/packages/3f/06/3e4420302363fbb71be3c7f35ce042f54bfca330e3e66b3a2e3c4cca579f/pip-26.2.2-py3-none-any.whl#sha256=fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70" | ||
| fi |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.