release/trusted-publishing/python
Packages are published with trusted publishing
Implements release/trusted-publishing for python.
| Severity | warning |
| Tiers | 1 |
| Stacks | python |
| Scope | root |
| Kind | expr |
| Source | library v0.2.0 |
| Selected by | fleetlint-recommended@v0.2.0 |
Requirement
A tag-triggered GitHub or GitLab workflow that publishes to PyPI (pypa/gh-action-pypi-publish, twine, uv, poetry, flit, hatch, pdm) uses trusted publishing: id-token: write, no pypi-publish password and no TWINE_/UV_PUBLISH_/POETRY_PYPI_TOKEN_* or --token from secrets; on GitLab id_tokens:.
Why
A registry token in CI secrets is valid for months and publishes from anywhere once leaked; an OIDC token is minted per run, scoped to this repository and workflow, and expires in minutes.
Applies when
tagged_workflows().filter(w, ci_kind(w) in ["github", "gitlab"] && steps(w).exists(s,
s.uses.startsWith("pypa/gh-action-pypi-publish")
|| s.run.matches("\\b(twine upload|uv publish|poetry publish|flit publish|hatch publish|pdm publish)\\b"))).size() > 0Check
For each item in:
tagged_workflows().filter(w, ci_kind(w) in ["github", "gitlab"] && steps(w).exists(s,
s.uses.startsWith("pypa/gh-action-pypi-publish")
|| s.run.matches("\\b(twine upload|uv publish|poetry publish|flit publish|hatch publish|pdm publish)\\b")))ci_kind(item) == "gitlab"
? text(item).matches("(?m)^\\s*id_tokens:")
: text(item).matches("id-token:\\s*write")
&& !steps(item).exists(s, s.uses.startsWith("pypa/gh-action-pypi-publish") && "password" in s.with)
&& !grep(item, r'^\s*-?\s*(?:TWINE_PASSWORD|TWINE_API_KEY|UV_PUBLISH_TOKEN|UV_PUBLISH_PASSWORD|POETRY_PYPI_TOKEN_\w+|POETRY_HTTP_BASIC_PYPI_PASSWORD|FLIT_PASSWORD|HATCH_INDEX_AUTH|PDM_PUBLISH_PASSWORD)\s*:\s*["\x27]?\$\{\{\s*secrets\.(\w+)').exists(m, m.match.upperAscii() != "GITHUB_TOKEN")
&& !grep(item, r'--token[\s=]+["\x27]?\$\{\{\s*secrets\.(\w+)').exists(m, m.match.upperAscii() != "GITHUB_TOKEN")Fix
Register the workflow as a trusted publisher on pypi.org, publish with pypa/gh-action-pypi-publish (no password) from a job with id-token: write, and delete the token secret.
Agent instruction: Grant id-token: write on the publishing job, remove the registry token from env/with (pypa/gh-action-pypi-publish without password, npm publish with npm 11.5.1 or newer, rust-lang/crates-io-auth-action for cargo, rubygems/release-gem for gems; on GitLab add id_tokens: with the registry’s audience), and tell the user to register the trusted publisher and delete the secret.
See: https://fleetlint.org/baseline/#releases, https://fleetlint.org/baseline/#security, https://fleetlint.org/stacks/#python
Generated by fleetlint docs from catalog v0.2.0.