MagicStack / MagicStack/httptools

Switch to Trusted Publishing for package upload to PyPI in CI

Abierto
#140 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
1.3k
Forks
107
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza con .github/workflows/release.yml e inspecciona el job publish, especialmente el paso Upload to PyPI. Configura el entorno pypi de GitHub y su registro en PyPI, añade los permisos y el entorno solicitados para el job, y elimina el argumento password y, opcionalmente, PYPI_API_TOKEN. La tarea estará terminada cuando las releases se publiquen mediante Trusted Publishing con atestaciones en lugar de un token almacenado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
github-actions, python
Área
ci-cd, release, security
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
68/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.