Skip to content

Commit d4a2b2b

Browse files
authored
Add trusted publishing (OIDC) (#1135)
* Add trusted publishing * Don't persist credentials in pypi.yml Ref: <https://woodruffw.github.io/zizmor/audits/#artipacked> * Don't attempt to publish from forks * Include more comments
1 parent 091b664 commit d4a2b2b

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

.github/workflows/pypi.yml

+36-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
make_sdist:
2222
name: Make SDist
2323
runs-on: ubuntu-latest
24+
permissions:
25+
# write id-token and attestations are required to attest build provenance
26+
id-token: write
27+
attestations: write
2428
steps:
2529
- uses: actions/checkout@v4
2630
with:
@@ -31,6 +35,11 @@ jobs:
3135
- name: Build SDist
3236
run: pipx run build --sdist
3337

38+
- name: Attest GitHub build provenance
39+
uses: actions/attest-build-provenance@v1
40+
with:
41+
subject-path: dist/*.tar.gz
42+
3443
- uses: actions/upload-artifact@v4
3544
with:
3645
name: sdist
@@ -52,6 +61,10 @@ jobs:
5261
build_wheels:
5362
name: Build wheels for ${{ matrix.platform }}
5463
runs-on: ${{ matrix.platform }}
64+
permissions:
65+
# write id-token and attestations are required to attest build provenance
66+
id-token: write
67+
attestations: write
5568
strategy:
5669
matrix:
5770
platform:
@@ -67,6 +80,11 @@ jobs:
6780
- name: Build wheels
6881
uses: pypa/[email protected]
6982

83+
- name: Attest GitHub build provenance
84+
uses: actions/attest-build-provenance@v1
85+
with:
86+
subject-path: ./wheelhouse/*.whl
87+
7088
- uses: actions/upload-artifact@v4
7189
with:
7290
name: wheels-${{ matrix.platform }}
@@ -75,6 +93,10 @@ jobs:
7593
build_universal_wheel:
7694
name: Build universal wheel for Pyodide
7795
runs-on: ubuntu-latest
96+
permissions:
97+
# write id-token and attestations are required to attest build provenance
98+
id-token: write
99+
attestations: write
78100
steps:
79101
- uses: actions/checkout@v4
80102
with:
@@ -93,6 +115,11 @@ jobs:
93115
run: |
94116
PYODIDE=1 python setup.py bdist_wheel --universal
95117
118+
- name: Attest GitHub build provenance
119+
uses: actions/attest-build-provenance@v1
120+
with:
121+
subject-path: dist/*.whl
122+
96123
- uses: actions/upload-artifact@v4
97124
with:
98125
name: universal_wheel
@@ -129,9 +156,16 @@ jobs:
129156

130157
upload_pypi:
131158
name: Upload to PyPI on release
159+
# Use the `release` GitHub environment to protect the Trusted Publishing (OIDC)
160+
# workflow by requiring signoff from a maintainer.
161+
environment: release
162+
permissions:
163+
# write id-token is required for trusted publishing (OIDC)
164+
id-token: write
132165
needs: [check_dist]
133166
runs-on: ubuntu-latest
134-
if: github.event_name == 'release' && github.event.action == 'published'
167+
# Don't publish from forks
168+
if: github.repository_owner == 'pymc-devs' && github.event_name == 'release' && github.event.action == 'published'
135169
steps:
136170
- uses: actions/download-artifact@v4
137171
with:
@@ -150,6 +184,4 @@ jobs:
150184
path: dist
151185

152186
- uses: pypa/[email protected]
153-
with:
154-
user: __token__
155-
password: ${{ secrets.pypi_password }}
187+
# Implicitly attests that the packages were uploaded in the context of this workflow.

0 commit comments

Comments
 (0)