MagicStack / MagicStack/uvloop

Switch to Trusted Publishing for package upload to PyPI in CI

Ouverte Adaptée aux débutants
#741 0 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Cython
Étoiles
11.9k
Forks
616
Métriques de merge des PR
Aucune PR mergée en 30 j

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](https://hugovk.github.io/top-pypi-packages/)) 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](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idenvironment) to the same `publish` job

* Add `id-token: write`, `contents: write` and `packages: write` [permissions](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idpermissions) 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](https://github.com/MagicStack/uvloop/blob/master/.github/workflows/release.yml) CI workflow

* Optionally remove the `PYPI_TOKEN` project secret

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par .github/workflows/release.yml et examinez le job publish, en particulier son étape Upload to PyPI. Configurez l’environnement GitHub et l’enregistrement PyPI correspondant, puis mettez à jour les permissions du job et supprimez l’argument de mot de passe. La tâche est terminée lorsque les releases utilisent Trusted Publishing avec des attestations au lieu d’un token PyPI.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
github-actions, python
Domaine
ci-cd, release, security
Type d'issue
Fonctionnalité
Difficulté
2/5
Temps estimé
1-3 heures
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
68/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.