Skip to content

Commit 317655d

Browse files
committed
Harden CI security
Backport of: #13966
1 parent 3ba1dd4 commit 317655d

6 files changed

Lines changed: 126 additions & 348 deletions

File tree

‎.github/actions/core-build-pgo-wheel/action.yml‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,28 @@ outputs:
1818
runs:
1919
using: composite
2020
steps:
21+
# The working directory is mounted in the maturin container, so the installer can be verified on the host:
22+
- name: Get uv installer
23+
if: runner.os == 'Linux'
24+
working-directory: ${{ inputs.working-directory }}
25+
run: |
26+
curl -LsSf https://astral.sh/uv/install.sh -o uv-installer.sh
27+
gh attestation verify uv-installer.sh \
28+
--repo astral-sh/uv \
29+
--signer-workflow astral-sh/uv/.github/workflows/release.yml \
30+
--deny-self-hosted-runners
31+
shell: bash
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
2135
- name: Build PGO-optimized wheel
2236
uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # v1.50.1
2337
with:
2438
working-directory: ${{ inputs.working-directory }}
2539
manylinux: auto
2640
# `uv` is needed for the maturin `pgo-command` to use it
2741
before-script-linux: |
28-
curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL=/usr/local/bin sh
42+
env UV_UNMANAGED_INSTALL=/usr/local/bin sh uv-installer.sh
2943
args: >
3044
--release
3145
--pgo

‎.github/workflows/ci.yml‎

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ jobs:
4949
core-build-sdist:
5050
runs-on: ubuntu-latest
5151
name: core / Build sdist
52+
permissions:
53+
contents: read
54+
# Required to attest build provenance, verified by the release job:
55+
id-token: write
56+
attestations: write
5257
steps:
5358
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
5459
with:
@@ -62,6 +67,10 @@ jobs:
6267
command: sdist
6368
args: --out dist
6469
rust-toolchain: stable
70+
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
71+
if: startsWith(github.ref, 'refs/tags/')
72+
with:
73+
subject-path: pydantic-core/dist/*
6574
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
6675
with:
6776
name: pydantic_core_pypi_files_sdist
@@ -71,6 +80,11 @@ jobs:
7180
name: core / Build on ${{ matrix.os }} (${{ matrix.target }} - ${{ matrix.interpreter || 'all' }}${{ matrix.os == 'linux' && format(' - {0}', matrix.manylinux == 'auto' && 'manylinux' || matrix.manylinux) || '' }})
7281
# only run on push to main, if a full build was requested or on release:
7382
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'full build')
83+
permissions:
84+
contents: read
85+
# Required to attest build provenance, verified by the release job:
86+
id-token: write
87+
attestations: write
7488
strategy:
7589
fail-fast: false
7690
matrix:
@@ -178,6 +192,11 @@ jobs:
178192

179193
- run: uv run --no-sync twine check --strict pydantic-core/dist/*
180194

195+
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
196+
if: startsWith(github.ref, 'refs/tags/')
197+
with:
198+
subject-path: pydantic-core/dist/*
199+
181200
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
182201
with:
183202
name: pydantic_core_pypi_files_${{ matrix.os }}_${{ matrix.target }}_${{ matrix.interpreter || 'all' }}_${{ matrix.manylinux }}
@@ -187,6 +206,11 @@ jobs:
187206
name: core / Build PGO-optimized on ${{ matrix.platform.os }} / ${{ matrix.interpreter }}
188207
# only run on push to main, if a full build was requested or on release:
189208
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'full build')
209+
permissions:
210+
contents: read
211+
# Required to attest build provenance, verified by the release job:
212+
id-token: write
213+
attestations: write
190214
strategy:
191215
fail-fast: false
192216
matrix:
@@ -234,6 +258,11 @@ jobs:
234258
- run: ${{ (startsWith(matrix.platform.os, 'windows') && 'dir') || 'ls -lh' }} dist/
235259
working-directory: pydantic-core
236260

261+
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
262+
if: startsWith(github.ref, 'refs/tags/')
263+
with:
264+
subject-path: pydantic-core/dist/*
265+
237266
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
238267
with:
239268
name: pydantic_core_pypi_files_${{ matrix.platform.os }}_${{ matrix.interpreter }}
@@ -242,6 +271,11 @@ jobs:
242271
core-build-pyemscripten:
243272
name: core / Build PyEmscripten (${{ matrix.python-version }})
244273
runs-on: ubuntu-latest
274+
permissions:
275+
contents: read
276+
# Required to attest build provenance, verified by the release job:
277+
id-token: write
278+
attestations: write
245279
strategy:
246280
fail-fast: false
247281
matrix:
@@ -299,6 +333,11 @@ jobs:
299333
- run: ls -lh dist/
300334
working-directory: pydantic-core
301335

336+
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
337+
if: startsWith(github.ref, 'refs/tags/')
338+
with:
339+
subject-path: pydantic-core/dist/*
340+
302341
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
303342
with:
304343
name: pydantic_core_pypi_files_pyemscripten_${{ matrix.python-version }}
@@ -353,6 +392,17 @@ jobs:
353392
merge-multiple: true
354393
path: dist
355394

395+
# The workspace is mounted in the container, so the installer can be verified on the host:
396+
- name: Get uv installer
397+
run: |
398+
curl -LsSf https://astral.sh/uv/install.sh -o uv-installer.sh
399+
gh attestation verify uv-installer.sh \
400+
--repo astral-sh/uv \
401+
--signer-workflow astral-sh/uv/.github/workflows/release.yml \
402+
--deny-self-hosted-runners
403+
env:
404+
GH_TOKEN: ${{ github.token }}
405+
356406
- uses: uraimo/run-on-arch-action@460cb8e6d9f726a588fc9b5e681c8a6cab09ae41 # v3.2.0
357407
name: Install and test
358408
with:
@@ -377,7 +427,7 @@ jobs:
377427
# and then sync the parent workspace:
378428
run: |
379429
set -x
380-
curl -LsSf https://astral.sh/uv/install.sh | sh
430+
sh uv-installer.sh
381431
source $HOME/.local/bin/env
382432
uv sync --directory pydantic-core --group testing-extra --no-install-package pydantic-core
383433
uv sync --group testing-extra --no-install-package pydantic-core --no-install-package pytest-memray --no-install-package memray --no-install-package pytest-codspeed --no-install-package cffi --no-install-package time-machine --inexact
@@ -636,6 +686,11 @@ jobs:
636686
build-pydantic:
637687
runs-on: ubuntu-latest
638688
if: startsWith(github.ref, 'refs/tags/')
689+
permissions:
690+
contents: read
691+
# Required to attest build provenance, verified by the release job:
692+
id-token: write
693+
attestations: write
639694
outputs:
640695
pydantic-version: ${{ steps.check-tag.outputs.VERSION }}
641696

@@ -661,6 +716,10 @@ jobs:
661716

662717
- run: ls -lh dist/
663718

719+
- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
720+
with:
721+
subject-path: dist/*
722+
664723
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
665724
with:
666725
name: pydantic_pypi_files
@@ -943,7 +1002,8 @@ jobs:
9431002
- uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
9441003
with:
9451004
python-version: ${{ matrix.python-version }}
946-
enable-cache: true # zizmor: ignore[cache-poisoning] -- Job does not produce release artifacts and does not have sensitive permissions
1005+
# Installs `typing-extensions` from its `main` branch, so don't write to (nor read from) the shared cache:
1006+
enable-cache: false
9471007

9481008
- name: Install dependencies
9491009
run: uv sync --all-packages --group testing-extra --all-extras
@@ -999,6 +1059,7 @@ jobs:
9991059

10001060
permissions:
10011061
id-token: write
1062+
attestations: read
10021063

10031064
steps:
10041065
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -1040,6 +1101,20 @@ jobs:
10401101
merge-multiple: true
10411102
path: pydantic-core-dist
10421103

1104+
- name: Verify pydantic-core dist artifacts provenance
1105+
if: steps.check-pypi.outputs.already_published != 'true'
1106+
run: |
1107+
for f in pydantic-core-dist/*; do
1108+
gh attestation verify "$f" \
1109+
--repo "$GITHUB_REPOSITORY" \
1110+
--signer-workflow "$GITHUB_REPOSITORY/.github/workflows/ci.yml" \
1111+
--source-ref "$GITHUB_REF" \
1112+
--source-digest "$GITHUB_SHA" \
1113+
--deny-self-hosted-runners
1114+
done
1115+
env:
1116+
GH_TOKEN: ${{ github.token }}
1117+
10431118
- name: Test pydantic-core wheels integrity
10441119
if: steps.check-pypi.outputs.already_published != 'true'
10451120
run: |
@@ -1059,6 +1134,7 @@ jobs:
10591134
permissions:
10601135
id-token: write
10611136
contents: write
1137+
attestations: read
10621138

10631139
steps:
10641140
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -1077,6 +1153,19 @@ jobs:
10771153
name: pydantic_pypi_files
10781154
path: pydantic-dist
10791155

1156+
- name: Verify pydantic dist artifacts provenance
1157+
run: |
1158+
for f in pydantic-dist/*; do
1159+
gh attestation verify "$f" \
1160+
--repo "$GITHUB_REPOSITORY" \
1161+
--signer-workflow "$GITHUB_REPOSITORY/.github/workflows/ci.yml" \
1162+
--source-ref "$GITHUB_REF" \
1163+
--source-digest "$GITHUB_SHA" \
1164+
--deny-self-hosted-runners
1165+
done
1166+
env:
1167+
GH_TOKEN: ${{ github.token }}
1168+
10801169
- name: Test pydantic artifacts integrity
10811170
run: |
10821171
for whl in pydantic-dist/*.whl; do unzip -qt "$whl"; done

‎.github/workflows/dependencies-check.yml‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)