Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Switch to Trusted Publishing for package upload to PyPI in CI

Offen
#140 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
68/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Ruhig
Tech-Stack
github-actions, python
Bereich
ci-cd, release, security

Rechercherichtung

Beginne mit .github/workflows/release.yml und untersuche den publish-Job, insbesondere den Schritt Upload to PyPI. Konfiguriere die GitHub-pypi-Umgebung und ihre PyPI-Registrierung, füge die angeforderten Job-Berechtigungen und die Umgebung hinzu und entferne das password-Argument sowie optional PYPI_API_TOKEN. Erledigt ist die Aufgabe, wenn Releases über Trusted Publishing mit Attestierungen statt mit einem gespeicherten Token veröffentlicht werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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 httptools 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 httptools'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 Release CI workflow

  • Optionally remove the PYPI_API_TOKEN project secret

Vorherrschende Sprache
Python
Sterne
1.3k
Forks
107
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus MagicStack/httptools

Alle Issues in MagicStack/httptools

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.