MagicStack / MagicStack/uvloop

Switch to Trusted Publishing for package upload to PyPI in CI

Open Beginner friendly
#741 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Cython
Stars
11.9k
Forks
616
PR merge metrics
No merged PRs in 30d

Description

Trusted publishing (with attestations) is currently suggested as good practice to ensure confidence that what users download from PyPI is the same artifact that was generated in GitHub CI, meaning that what I see in GitHub is the same as what is installed - handy for auditing. It also avoids the presence of PyPI tokens as 'secrets' in the CI, which can be exfiltrated by bad actors.

Following the recent litellm supply chain attack this week, I would like to express my support for this*. The uvloop package is one of 16 packages in the top 500 PyPI packages (by downloads) which use the pypa/gh-action-pypi-publish action but have not yet upgraded it to use Trusted Publishing: this is 'low hanging fruit' in terms of making Python a more secure programming environment.

Instead of using the stored secret token, GitHub vouches for the upload, and PyPI checks the uploading CI workflow filename against a pre-declared filename you set ahead of time (in uvloop's case the filename is release.yml). It also requires creating an 'environment' for the repo on GitHub (suggested name "pypi") which you also register the package with on PyPI.

* Post-mortems of the litellm attack:

  1. https://futuresearch.ai/blog/litellm-pypi-supply-chain-attack/
  2. https://snyk.io/articles/poisoned-security-scanner-backdooring-litellm/
Implementation (click to expand)
  • Configure (or use an existing) GitHub environment, and register with PyPI

  • Add the environment definition to the same publish job

  • Add id-token: write, contents: write and packages: write permissions to the same publish job

    • specifying any permission restricts the token, and creating a GitHub release requires contents: write and potentially packages: write
  • Remove password argument in the Upload to PyPI step of the publish job of the Build & Publish CI workflow

  • Optionally remove the PYPI_TOKEN project secret

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with .github/workflows/release.yml and inspect the publish job, especially its Upload to PyPI step. Configure the GitHub environment and corresponding PyPI registration, then update the job permissions and remove the password argument. Done means releases use Trusted Publishing with attestations instead of a PyPI token.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, python
Domain
ci-cd, release, security
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.