Skip to content

Commit ed91c43

Browse files
authored
CI: use patched PBS Python builds on Windows (#451)
Close the Windows interpreter gap left by #413. setup-python cannot provide the patched maintenance releases without upstream Windows installers, as confirmed in actions/setup-python#1383. Add setup-hardened-python using SHA-pinned setup-uv and checksum-verified python-build-standalone distributions. Create a venv and verify the interpreter before upgrading pip. Share the security-release guard with update-pip and the Windows LLVM container installer. Replace NuGet provisioning and its pinned pip bootstrap, and remove the tolerated guard failures in Windows tests. Keep cibuildwheel for wheel builds and pass the host interpreter explicitly. Track the nested setup-uv action pin with Dependabot.
1 parent 361a95e commit ed91c43

9 files changed

Lines changed: 216 additions & 140 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Set up hardened Python
5+
description: >-
6+
Install CPython with a pinned uv, create a venv from it, and put the venv
7+
first on PATH. setup-uv verifies the uv binary and uv verifies the
8+
python-build-standalone archive against embedded checksums, so the
9+
interpreter's integrity does not depend on TLS. The job then fails unless
10+
the interpreter meets the shared CVE-2026-115557 security release floor,
11+
and pip is updated through that interpreter's ssl module. Unlike setup-python,
12+
this provides patched Windows builds of maintenance series, for which
13+
python.org publishes no installers. See
14+
https://github.com/NVIDIA/cuda-python/pull/3275 and
15+
https://discuss.python.org/t/109678.
16+
17+
inputs:
18+
python-version:
19+
description: >-
20+
uv Python request, e.g. "3.12" or "3.14t" (free-threaded). The newest
21+
patch known to the pinned uv is installed. Only series with a fixed
22+
release listed in the interpreter check (3.11-3.15) are accepted.
23+
required: true
24+
venv:
25+
description: Directory for the venv. Defaults to a new directory under RUNNER_TEMP.
26+
default: ""
27+
28+
outputs:
29+
python-path:
30+
description: Absolute path of the venv's interpreter.
31+
value: ${{ steps.venv.outputs.python-path }}
32+
python-version:
33+
description: Full version of the interpreter, e.g. "3.14.10".
34+
value: ${{ steps.venv.outputs.python-version }}
35+
36+
runs:
37+
using: composite
38+
steps:
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
41+
with:
42+
# The newest uv whose checksum is embedded in this SHA-pinned action.
43+
# Dependabot updates the action pin and therefore the selected uv.
44+
version: "latest-known"
45+
enable-cache: false
46+
47+
- name: Install Python and create venv
48+
id: venv
49+
shell: bash --noprofile --norc -euo pipefail {0}
50+
env:
51+
PY_REQUEST: ${{ inputs.python-version }}
52+
VENV_DIR: ${{ inputs.venv }}
53+
# A per-job install directory ensures the newest patch known to the
54+
# pinned uv is used, never an older interpreter left on a persistent
55+
# self-hosted runner.
56+
UV_PYTHON_INSTALL_DIR: ${{ runner.temp }}/setup-hardened-python/interpreters
57+
UV_NO_CONFIG: "1"
58+
run: |
59+
uv python install --no-bin --no-registry "${PY_REQUEST}"
60+
base="$(uv python find --managed-python --no-project "${PY_REQUEST}")"
61+
venv="${VENV_DIR}"
62+
if [[ -z "${venv}" ]]; then
63+
# A fresh directory per call, so a second call in the same job
64+
# leaves the first venv intact.
65+
venv="$("${base}" -c 'import sys, tempfile; print(tempfile.mkdtemp(prefix="venv-", dir=sys.argv[1]))' "${RUNNER_TEMP}")"
66+
fi
67+
# The stdlib venv seeds pip from the interpreter's bundled wheel, so
68+
# nothing is downloaded before the ssl check below.
69+
"${base}" -m venv --clear "${venv}"
70+
if [[ "${RUNNER_OS}" == Windows ]]; then
71+
py="${venv}/Scripts/python.exe"
72+
else
73+
py="${venv}/bin/python"
74+
fi
75+
# Let the interpreter report native absolute paths (Windows included).
76+
python_path="$("${py}" -c 'import sys; print(sys.executable)')"
77+
"${py}" -c 'import os, sys; print(os.path.dirname(sys.executable))' >> "${GITHUB_PATH}"
78+
{
79+
echo "python-path=${python_path}"
80+
echo "python-version=$("${py}" -c 'import platform; print(platform.python_version())')"
81+
} >> "${GITHUB_OUTPUT}"
82+
83+
- name: Check interpreter and update pip
84+
uses: ./.github/actions/update-pip
85+
with:
86+
python-path: ${{ steps.venv.outputs.python-path }}

‎.github/actions/update-pip/action.yml‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ description: >-
99
workflow ever drifts below the required patch. Use a tilde-range spec
1010
(e.g. python-version: '~3.13.18') so setup-python enforces the floor while
1111
automatically picking up newer security patches. Operates on the `python`
12-
found on PATH, i.e. the one installed by setup-python.
12+
found on PATH; optionally verifies it is the expected virtualenv interpreter.
1313
See https://discuss.python.org/t/109576
1414
15+
inputs:
16+
python-path:
17+
description: Expected virtualenv interpreter; omit to check only the security release floor.
18+
default: ""
19+
1520
runs:
1621
using: composite
1722
steps:
1823
- name: Assert Python blocks compromised CAs
19-
shell: python
24+
shell: python {0}
25+
env:
26+
ACTION_PATH: ${{ github.action_path }}
27+
PYTHON: ${{ inputs.python-path }}
2028
run: |
21-
import sys
29+
import os
30+
import runpy
31+
from pathlib import Path
2232
23-
# Fail if the interpreter predates the CPython security releases whose
24-
# ssl module rejects the compromised eMudhra/emSign keys. The same
25-
# patch floors appear in the python-version specs of the calling
26-
# workflows; update them together.
27-
minima = {11: 18, 12: 16, 13: 18, 14: 10, 15: 2}
28-
v = sys.version_info
29-
if v.major != 3 or v.minor not in minima or v.micro < minima[v.minor]:
30-
sys.exit(
31-
f"Python {sys.version} is below the minimum patch release "
32-
"whose ssl module blocks the compromised eMudhra/emSign CAs. "
33-
"Update the python-version spec in the calling workflow."
34-
)
33+
root = Path(os.environ["ACTION_PATH"]).parents[2]
34+
runpy.run_path(str(root / "ci/tools/check_python_security.py"), run_name="__main__")
3535
- name: Upgrade pip
36-
shell: bash
36+
shell: bash --noprofile --norc -xeuo pipefail {0}
3737
run: |
3838
python -m pip install --disable-pip-version-check --upgrade pip
3939
python -m pip --version

‎.github/dependabot.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
version: 2
55
updates:
66
- package-ecosystem: github-actions
7-
directory: /
7+
directories:
8+
- /
9+
- /.github/actions/setup-hardened-python
810
schedule:
911
interval: "monthly"
1012
time: "09:00"

‎.github/workflows/build-llvm.yml‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ jobs:
181181
path: ${{ env.INSTALL_DIR }}/
182182
key: ${{ steps.params.outputs.key }}
183183

184+
- name: Install verified uv
185+
if: steps.gha-cache.outputs.cache-hit != 'true'
186+
id: uv
187+
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
188+
with:
189+
version: "latest-known"
190+
enable-cache: false
191+
184192
- name: Pull devcontainer image
185193
if: steps.gha-cache.outputs.cache-hit != 'true'
186194
shell: pwsh
@@ -195,6 +203,7 @@ jobs:
195203
env:
196204
BUILD_MODE: ${{ matrix.mode }}
197205
PYTHON_VERSION: ${{ matrix.python-version }}
206+
UV_PATH: ${{ steps.uv.outputs.uv-path }}
198207
run: |
199208
. ./ci/windows-common.ps1
200209
Import-EnvFile ci/windows-devcontainer.env
@@ -203,12 +212,14 @@ jobs:
203212
$py = $env:PYTHON_VERSION
204213
$mode = $env:BUILD_MODE
205214
$cname = $env:CONTAINER_NAME
215+
$uvDir = Split-Path -Parent $env:UV_PATH
206216
docker run --rm --name $cname --isolation=process `
207217
--mount "type=bind,source=$src,target=C:\workspace" `
218+
--mount "type=bind,source=$uvDir,target=C:\verified-uv,readonly" `
208219
--workdir C:\workspace `
209220
--env "PARALLEL=${{ env.PARALLEL }}" `
210221
$img `
211-
powershell -NoProfile -ExecutionPolicy Bypass -File C:\workspace\ci\windows-llvm-container-build.ps1 -PythonVersion $py -Mode $mode
222+
powershell -NoProfile -ExecutionPolicy Bypass -File C:\workspace\ci\windows-llvm-container-build.ps1 -PythonVersion $py -Mode $mode -UvPath C:\verified-uv\uv.exe
212223
if ($LASTEXITCODE -ne 0) {
213224
throw "$mode LLVM build container failed with exit code $LASTEXITCODE"
214225
}
@@ -272,14 +283,9 @@ jobs:
272283

273284
- name: Set up native Arm Python
274285
if: steps.gha-cache.outputs.cache-hit != 'true'
275-
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
286+
uses: ./.github/actions/setup-hardened-python
276287
with:
277288
python-version: ${{ matrix.python-version }}
278-
# Resolve the newest patch from the GitHub-maintained manifest so
279-
# setup-python cannot pick a cached pre-eMudhra-fix release. The
280-
# update-pip action asserts the floor and will fail if the resolved
281-
# version is still below it.
282-
check-latest: true
283289

284290
- name: Set up ARM64 MSVC
285291
if: steps.gha-cache.outputs.cache-hit != 'true'
@@ -288,10 +294,6 @@ jobs:
288294
arch: arm64
289295
toolset: ${{ steps.cache-key.outputs.msvc-toolset }}
290296

291-
- name: Update pip
292-
if: steps.gha-cache.outputs.cache-hit != 'true'
293-
uses: ./.github/actions/update-pip
294-
295297
- name: Install build dependencies
296298
if: steps.gha-cache.outputs.cache-hit != 'true'
297299
run: |

‎.github/workflows/build-wheel.yml‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@ jobs:
4141
with:
4242
fetch-depth: 0
4343

44-
- name: Set up Python
44+
# Both platforms pass an explicit host interpreter to cibuildwheel.
45+
# Windows uses the hardened PBS interpreter for the matrix Python.
46+
- name: Set up Linux host Python
47+
if: ${{ startsWith(inputs.host-platform, 'linux') }}
4548
id: setup-python
4649
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
4750
with:
48-
# Host Python only drives cibuildwheel; the wheel targets are set by
49-
# CIBW_BUILD and independent of this version. Pin to a floor that
50-
# setup-python can resolve on both Linux and Windows (3.11-3.13 have
51-
# no eMudhra-fixed Windows build in actions/python-versions as of
52-
# 2026-10-31; see https://github.com/actions/setup-python/issues/1383),
53-
# so the Windows wheel-build host runs update-pip on a CA-clean
54-
# interpreter too.
5551
python-version: "~3.14.10"
5652

5753
- name: Update pip
54+
if: ${{ startsWith(inputs.host-platform, 'linux') }}
5855
uses: ./.github/actions/update-pip
5956

57+
- name: Set up Windows host Python
58+
if: ${{ startsWith(inputs.host-platform, 'win') }}
59+
id: windows-python
60+
uses: ./.github/actions/setup-hardened-python
61+
with:
62+
python-version: ${{ matrix.python-version }}
63+
6064
- name: Install latest rapidsai/sccache
6165
if: ${{ startsWith(inputs.host-platform, 'linux') }}
6266
run: |
@@ -129,14 +133,11 @@ jobs:
129133
toolset: ${{ steps.wheel-tags.outputs.msvc-toolset }}
130134

131135
- name: Build numba-cuda-mlir wheel
132-
# Bumped for cp315: v4.1.0 hides 3.15 behind `enable = cpython-prerelease`
133-
# and only carries 3.15.0b2 for Windows. v4.2.0+ builds 3.15 by default
134-
# against an rc that upstream guarantees is ABI-compatible with the final
135-
# release, so no prerelease opt-in is needed here.
136136
uses: pypa/cibuildwheel@b9e566a2b284570af229f6c2a33673410d0389a3 # v4.3.4
137137
with:
138138
package-dir: .
139139
output-dir: dist
140+
python-path: ${{ steps.windows-python.outputs.python-path || steps.setup-python.outputs.python-path }}
140141
env:
141142
CIBW_BUILD: ${{ steps.wheel-tags.outputs.cibw-build }}
142143
# Let cibuildwheel use its own bundled SHA-pinned manylinux_2_28
@@ -154,20 +155,17 @@ jobs:
154155
ACTIONS_RESULTS_URL=${{ env.ACTIONS_RESULTS_URL }}
155156
ACTIONS_CACHE_URL=${{ env.ACTIONS_CACHE_URL }}
156157
ACTIONS_CACHE_SERVICE_V2=${{ env.ACTIONS_CACHE_SERVICE_V2 }}
157-
CIBW_ENVIRONMENT_WINDOWS: >
158-
MLIR_DIR="$(cygpath -w ${{ env.LLVM_MODERN_INSTALL_DIR }}/lib/cmake/mlir)"
159-
${{ inputs.host-platform != 'win-arm64' && format('LIBLLVM7="$(cygpath -w {0}/bin/LLVM-C.dll)"', env.LLVM7_INSTALL_DIR) || '' }}
160158
CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
161159
auditwheel -v repair {wheel} --wheel-dir {dest_dir}
162160
--exclude libMLIRPythonCAPI.so
163161
--exclude libMLIRPythonSupport-numba_cuda_mlir.so
164162
--exclude libLLVM-7.so &&
165163
"/host/${{ env.SCCACHE_PATH }}" --show-adv-stats &&
166164
"/host/${{ env.SCCACHE_PATH }}" --show-stats --stats-format=json > /host/${{ github.workspace }}/sccache_NUMBA_CUDA_MLIR.json
167-
# Windows wheels are built with /MT (static CRT) per PR #127, so the
168-
# wheel is self-contained and needs no DLL bundling. cibuildwheel v4
169-
# made `delvewheel repair` the Windows default; opt out explicitly
170-
# to restore the v3.x no-op behavior we rely on.
165+
CIBW_ENVIRONMENT_WINDOWS: >
166+
MLIR_DIR="$(cygpath -w ${{ env.LLVM_MODERN_INSTALL_DIR }}/lib/cmake/mlir)"
167+
${{ inputs.host-platform != 'win-arm64' && format('LIBLLVM7="$(cygpath -w {0}/bin/LLVM-C.dll)"', env.LLVM7_INSTALL_DIR) || '' }}
168+
# Windows wheels use the static CRT and need no DLL repair.
171169
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: ""
172170

173171
- name: Report sccache stats (numba-cuda-mlir)
@@ -176,7 +174,7 @@ jobs:
176174
with:
177175
json-file: sccache_NUMBA_CUDA_MLIR.json
178176
label: "numba-cuda-mlir"
179-
build-step: "Build numba-cuda-mlir wheel (Linux)"
177+
build-step: "Build numba-cuda-mlir wheel"
180178

181179
- name: List the numba-cuda-mlir artifacts directory
182180
run: |

‎.github/workflows/test-wheel-windows.yml‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,9 @@ jobs:
115115
run: ls -lahR "$NUMBA_CUDA_MLIR_CUDA_ARTIFACTS_DIR"
116116

117117
- name: Set up Python ${{ matrix.PY_VER }}
118-
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
118+
uses: ./.github/actions/setup-hardened-python
119119
with:
120120
python-version: ${{ matrix.PY_VER }}
121-
allow-prereleases: ${{ startsWith(matrix.PY_VER, '3.15') }}
122-
# Resolve the newest patch from the GitHub-maintained manifest. On
123-
# Windows, actions/python-versions tops out at 3.11.9, 3.12.10, and
124-
# 3.13.17 (no eMudhra-fixed Windows build for the 3.11-3.13 series
125-
# as of 2026-10-31; see
126-
# https://github.com/actions/setup-python/issues/1383), so the
127-
# update-pip action's ssl-module assertion will fail those three
128-
# series. 3.14 and 3.15 Windows lanes stay green.
129-
check-latest: true
130-
131-
- name: Update pip
132-
uses: ./.github/actions/update-pip
133-
# Scoped tolerance for Windows 3.11/3.12/3.13 while
134-
# actions/setup-python#1383 is open; downstream steps still run on the
135-
# unpatched interpreter but pip is already 26.2.2 from setup-python.
136-
continue-on-error: ${{ contains(fromJSON('["3.11","3.12","3.13"]'), matrix.PY_VER) }}
137121

138122
- name: Set up mini CTK
139123
if: ${{ matrix.LOCAL_CTK == '1' }}

‎ci/tools/check_python_security.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Check security release floors; also verify the venv when PYTHON is supplied."""
4+
5+
import os
6+
import sys
7+
8+
9+
FIXED_PATCHES = {(3, 11): 18, (3, 12): 16, (3, 13): 18, (3, 14): 10, (3, 15): 2}
10+
11+
12+
def main():
13+
expected = os.environ.get("PYTHON")
14+
if expected:
15+
if os.path.normcase(sys.executable) != os.path.normcase(expected):
16+
sys.exit(f"PATH resolves Python to {sys.executable}, not {expected}")
17+
if sys.prefix == sys.base_prefix:
18+
sys.exit("Hardened Python must run inside the selected virtual environment")
19+
version = sys.version_info
20+
series = (version.major, version.minor)
21+
minimum = FIXED_PATCHES.get(series)
22+
if minimum is None:
23+
sys.exit(f"No patched release is known for Python {version.major}.{version.minor}")
24+
if version.micro < minimum or version.releaselevel != "final":
25+
sys.exit(
26+
f"Python {sys.version} predates the required stable {version.major}."
27+
f"{version.minor}.{minimum} eMudhra/emSign security release"
28+
)
29+
print(f"Python {version.major}.{version.minor}.{version.micro}: patched interpreter verified")
30+
31+
32+
if __name__ == "__main__":
33+
main()

0 commit comments

Comments
 (0)