From Stored Tokens to Trusted Publishing: A Shift Worth Watching
For most of the history of public registries, publishing from CI meant creating an API token with upload rights and pasting it into your repository's secrets. That token was long-lived, often over-scoped and, if it leaked, gave an attacker the power to publish as you. The clear trend of the last few years is to remove that secret entirely.
What is changing
Trusted publishing uses OpenID Connect (OIDC). Your CI provider issues a short-lived, signed identity token for a specific workflow run. The registry has been told in advance which repository and workflow are allowed to publish a given package. It checks the token, and if the claims match, it issues a temporary upload credential that expires within minutes. Nothing long-lived is stored anywhere.
The observable developments, in rough order:
- PyPI launched Trusted Publishing in 2023, starting with GitHub Actions and later adding other CI providers such as GitLab CI/CD. The Python Packaging User Guide and PyPI's own documentation describe the setup.
- npm added provenance statements in 2023, which use the same OIDC identity to produce a signed, publicly verifiable record of where a package was built. npm has since extended its documentation toward OIDC-based publishing from CI as well; check npm Docs for the current state.
- Other registries, including RubyGems.org and crates.io, have adopted or announced similar trusted publishing mechanisms.
Why it is happening now
Several pressures arrived together. Stolen and leaked tokens have been a recurring root cause in package compromises. Registries began requiring two-factor authentication for maintainers, which protected interactive logins but not automation tokens. And the Sigstore project made signing and transparency logs practical without every maintainer managing keys. Trusted publishing fits naturally with all three: it is easy to adopt, removes a secret and produces an auditable link between a release and a build.
What it looks like in practice
A minimal PyPI publishing job using the PyPA's official action:
jobs:
publish:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with: { name: dist, path: dist }
- uses: pypa/gh-action-pypi-publish@release/v1
There is no password or token input. The id-token: write permission is what lets the job request an OIDC token.
What it means for maintainers
- Delete old tokens. Once trusted publishing works, revoke the stored API token; otherwise you have added a path, not replaced one.
- Protect the workflow. The workflow file is now the credential. Require review for changes to it, and use a protected deployment environment for the publish job.
- Separate build and publish. Build in one job and publish in another with minimal permissions, so a compromised build step does not get upload rights.
- Expect more of it. The direction across registries is toward tokenless, attested publishing being the norm for popular packages.
Our step-by-step PyPI trusted publishing setup and the trusted publishing workflow tutorial cover configuration in detail.