Skip to content

Commit 1b4da6d

Browse files
committed
CI: fix fail-open checks and wire coverage.yml Windows build
Three review fixes: - Wire upgrade-ca-certificates into coverage.yml's build-wheel-windows job, which is a standalone inline job (not a call to build-wheel.yml) running on windows-2022 with actions/checkout. - Linux path: fail closed when openssl is absent or the CA bundle cannot be parsed (cert_count == 0), mirroring the probe script's guard. - Windows path: use -ErrorAction Stop when reading LocalMachine\Root (an unreadable store is not a clean state) and keep SilentlyContinue only for Disallowed; replace the manual SHA256::Create()/BitConverter block with GetCertHashString('SHA256'), which is available in PS7 (shell: pwsh).
1 parent 43e36ad commit 1b4da6d

3 files changed

Lines changed: 42 additions & 10 deletions

File tree

‎.github/actionlint.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ paths:
4141
".github/workflows/test-sdist-windows.yml":
4242
ignore:
4343
- 'specifying action "\$/[^"]+" in invalid format because ref is missing'
44+
".github/workflows/coverage.yml":
45+
ignore:
46+
- 'specifying action "\$/[^"]+" in invalid format because ref is missing'

‎.github/actions/upgrade-ca-certificates/action.yml‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ runs:
3838
$ErrorActionPreference = 'Stop'
3939
$targetFP = '86A1ECBA089C4A8D3BBE2734C612BA341D813E043CF9E8A862CD5C57A36BBE6B'
4040
41-
function Find-CertBySHA256FP([string]$StoreName) {
42-
Get-ChildItem "Cert:\LocalMachine\$StoreName" -ErrorAction SilentlyContinue |
43-
Where-Object {
44-
$sha = [System.Security.Cryptography.SHA256]::Create()
45-
try { [System.BitConverter]::ToString($sha.ComputeHash($_.RawData)).Replace('-', '').ToUpper() -eq $targetFP }
46-
finally { $sha.Dispose() }
47-
} | Select-Object -First 1
41+
# Use -ErrorAction Stop for Root (an unreadable store is a failure, not
42+
# a "clean" state). Use SilentlyContinue for Disallowed, which may be
43+
# empty on a fresh runner. GetCertHashString('SHA256') is available in
44+
# PS7 (shell: pwsh) and avoids the manual SHA256::Create() block.
45+
function Find-CertBySHA256FP([string]$StoreName, [switch]$Required) {
46+
$ea = if ($Required) { 'Stop' } else { 'SilentlyContinue' }
47+
Get-ChildItem "Cert:\LocalMachine\$StoreName" -ErrorAction $ea |
48+
Where-Object { $_.GetCertHashString('SHA256').ToUpper() -eq $targetFP } |
49+
Select-Object -First 1
4850
}
4951
50-
$inRoot = Find-CertBySHA256FP 'Root'
52+
$inRoot = Find-CertBySHA256FP 'Root' -Required
5153
$inDisallowed = Find-CertBySHA256FP 'Disallowed'
5254
5355
if (-not $inRoot) {
@@ -86,13 +88,31 @@ runs:
8688
CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt"
8789
VERSION_ID="$(. /etc/os-release && echo "${VERSION_ID}")"
8890
91+
# Fail closed if openssl is missing or the bundle cannot be parsed
92+
# (mirrors ci/tools/runner_trust_probe.sh).
93+
if ! command -v openssl >/dev/null 2>&1; then
94+
echo "::error::openssl not found; cannot verify CA bundle"
95+
exit 1
96+
fi
97+
if [[ ! -f "${CA_BUNDLE}" ]]; then
98+
echo "::error::CA bundle not found: ${CA_BUNDLE}"
99+
exit 1
100+
fi
101+
89102
fingerprints_in_bundle() {
90103
awk '/-----BEGIN CERTIFICATE-----/{cert=""} {cert=cert $0 "\n"}
91104
/-----END CERTIFICATE-----/{print cert | "openssl x509 -noout -fingerprint -sha256 2>/dev/null"; close("openssl x509 -noout -fingerprint -sha256 2>/dev/null")}' \
92105
"${CA_BUNDLE}"
93106
}
94107
95-
if grep -qiF "${EMSIGN_G3_FP}" <<< "$(fingerprints_in_bundle)"; then
108+
fps="$(fingerprints_in_bundle)"
109+
cert_count="$(grep -c . <<< "${fps}" || true)"
110+
if (( cert_count == 0 )); then
111+
echo "::error::No certificates parsed from ${CA_BUNDLE}; openssl may have failed"
112+
exit 1
113+
fi
114+
115+
if grep -qiF "${EMSIGN_G3_FP}" <<< "${fps}"; then
96116
before_state="not fixed"
97117
else
98118
before_state="already fixed"
@@ -118,7 +138,13 @@ runs:
118138
done
119139
120140
after_ver="$(dpkg-query -W -f='${Version}' ca-certificates 2>/dev/null || echo unknown)"
121-
if grep -qiF "${EMSIGN_G3_FP}" <<< "$(fingerprints_in_bundle)"; then
141+
after_fps="$(fingerprints_in_bundle)"
142+
after_count="$(grep -c . <<< "${after_fps}" || true)"
143+
if (( after_count == 0 )); then
144+
echo "::error::No certificates parsed after upgrade; cannot verify fix"
145+
exit 1
146+
fi
147+
if grep -qiF "${EMSIGN_G3_FP}" <<< "${after_fps}"; then
122148
echo "::error::emSign ECC Root CA - G3 still present after upgrade (ca-certificates ${after_ver} on ${VERSION_ID})"
123149
exit 1
124150
fi

‎.github/workflows/coverage.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ jobs:
236236
CUDA_PYTHON_COVERAGE: "1"
237237
CUDA_VER: ${{ needs.coverage-vars.outputs.CUDA_VER }}
238238
steps:
239+
- name: Harden OS certificate trust (eMudhra/emSign CA stopgap)
240+
uses: $/.github/actions/upgrade-ca-certificates
241+
239242
- name: Enable Git symlinks (Windows, must precede checkout)
240243
run: git config --global core.symlinks true
241244

0 commit comments

Comments
 (0)