ci(release): publish to PyPI with trusted publishing - #77
Merged
Conversation
The stored PyPI API token has been deleted, but the publish step still passed
`password: ${{ secrets.PYPI_API_TOKEN }}`. A missing secret resolves to an empty
string rather than failing, so the next release would have reached the upload
with no credential at all, and no OIDC token either, because the workflow did not
request `id-token: write`.
It would have failed late: with the steps reordered, the version bump is pushed
to main before the upload runs, so main would carry a version that never reached
PyPI, and no tag or release would exist for it.
Request `id-token: write` and drop the password input. The action then falls back
to trusted publishing, exchanging a short-lived OIDC token for an upload token
against the publisher configured on PyPI for this repository, this workflow and
the build_and_publish environment. Nothing durable is stored, so there is no
token left to expire, leak or rotate.
Every remaining secret reference now resolves: RELEASE_DEPLOY_KEY, NAME_GITHUB,
MAIL_GITHUB and ANACONDA_API_TOKEN all exist in that environment.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This would have broken the next release
The stored PyPI API token is now deleted, but the publish step still passed:
A missing secret resolves to an empty string rather than failing the expression. So the next release would have reached the upload with no credential — and no OIDC token either, because
permissions:did not requestid-token: write.It would have failed late. With the steps reordered in #74, the version bump is pushed to main before the upload, so the result would be main carrying a version that never reached PyPI, with no tag or release for it.
The fix
Request
id-token: writeand drop thepasswordinput.pypa/gh-action-pypi-publishthen falls back to trusted publishing, exchanging a short-lived OIDC token for an upload token against the publisher configured on PyPI.Nothing durable is stored, so there is no token left to expire, leak, or rotate — which is the point of having deleted it.
Secret references after this change
RELEASE_DEPLOY_KEYbuild_and_publishenv ✅NAME_GITHUB,MAIL_GITHUBbuild_and_publishenv ✅ANACONDA_API_TOKENbuild_and_publishenv ✅ (renewed, expires 2030-01-10)PYPI_API_TOKENRepo-level secrets are now empty; everything the workflow needs is environment-scoped, and the job declares that environment.
Before the next release
The PyPI publisher must match exactly: owner
klamt-lab, repositorystraindesign, workflowpython-publish.yml, environmentbuild_and_publish. If the environment field was left blank on PyPI it matches any environment, which also works — but a different value would not.🤖 Generated with Claude Code