MagicStack / MagicStack/uvloop

Switch to Trusted Publishing for package upload to PyPI in CI

Aberta Para iniciantes
#741 0 comentários 2 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
Cython
Estrelas
11.9k
Forks
616
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece com .github/workflows/release.yml e inspecione o job publish, especialmente sua etapa Upload to PyPI. Configure o ambiente do GitHub e o registro correspondente no PyPI, depois atualize as permissões do job e remova o argumento de senha. Está concluído quando os releases usarem Trusted Publishing com attestations em vez de um token do PyPI.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
github-actions, python
Domínio
ci-cd, release, security
Tipo de issue
Funcionalidade
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Pouca atividade
Clareza
Claramente especificada
Facilidade para iniciantes
68/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.