Switch PyPI publish workflow to OIDC trusted publishing#7879
Conversation
…C trusted publishing Agent-Logs-Url: https://github.com/microsoft/CCF/sessions/ae6b3f94-23af-4d89-adae-716929b33a1e Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
|
@copilot what does setting an environment on the job do? Also is there a way to set the write permission at the step level rather than the job? |
Two separate things:
For trusted publishing specifically, it also acts as an additional constraint on the PyPI side: when you register the trusted publisher on PyPI you can pin it to a workflow and an environment name (e.g. Step-level |
|
@copilot add an environment to this workflow, call it pypi - what do I need to do in repo settings? |
Agent-Logs-Url: https://github.com/microsoft/CCF/sessions/5bef9d3b-cd2a-45ab-9b30-b8275f2f5b9e Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Done in 84b59be — added Repo settings to do:
PyPI side: in the |
Agent-Logs-Url: https://github.com/microsoft/CCF/sessions/5ac86288-f25c-4ed3-8558-ec5c766a1811 Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the PyPI publish workflow to use OIDC trusted publishing (via pypa/gh-action-pypi-publish) instead of a long-lived PYPI_TOKEN, aligning CCF’s release publishing with PyPA’s recommended approach.
Changes:
- Switch upload mechanism from
twine uploadwith a repository secret topypa/gh-action-pypi-publish(pinned by commit SHA). - Add GitHub Actions environment binding (
environment: pypi) and enable OIDC (id-token: write) for token minting. - Download the release wheel into
dist/to match the publish action’s defaultpackages-dir.
Custom instructions used:
.github/copilot-instructions.md
| name: "Publish ccf package to PyPi" | ||
| runs-on: ubuntu-latest | ||
| environment: pypi | ||
| permissions: |
| - name: Fetch PyPi Package from release | ||
| run: | | ||
| cd python | ||
| mkdir -p dist | ||
| cd dist | ||
| RELEASE_WHEEL_URL=$(curl -s https://api.github.com/repos/microsoft/ccf/releases/tags/ccf-${{steps.tref.outputs.version}} | jq -r '.assets[] | select(.name|test("ccf-.*.whl")) | .browser_download_url') | ||
| wget ${RELEASE_WHEEL_URL} |
| RELEASE_WHEEL_URL=$(curl -s https://api.github.com/repos/microsoft/ccf/releases/tags/ccf-${{steps.tref.outputs.version}} | jq -r '.assets[] | select(.name|test("ccf-.*.whl")) | .browser_download_url') | ||
| wget ${RELEASE_WHEEL_URL} |
|
@copilot create a follow up PR addressing the review comments. |
|
@copilot create a new PR addressing the comments you posted after this one was merged. |
Replaces the long-lived
PYPI_TOKENupload in.github/workflows/pypi.ymlwith PyPA's official action using OIDC trusted publishing, per the linked GitHub/PyPI guidance.Changes
pip install twine+twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }}step in favour ofpypa/gh-action-pypi-publish, pinned to commit SHAcef221092ed1bacb1cc03d23a2d87d1d172e277b(v1.14.0).id-token: writeon the job so GitHub can mint the OIDC token PyPI exchanges for a short-lived API token.dist/(the action's defaultpackages-dir) instead ofpython/.pypifor additional hardening (deployment branch/tag restrictions, optional required reviewers, deployment record).secrets.PYPI_TOKENis no longer referenced and can be removed from repo secrets once trusted publishing is live.Out-of-band setup required
pypi(must match the workflow exactly). Optionally restrict "Deployment branches and tags" to the release tag pattern (e.g.ccf-*) and add required reviewers for a manual gate.ccfproject pointing atmicrosoft/CCF, workflowpypi.yml, and set the Environment name topypi. Both sides must match or token minting will fail.