MagicStack / MagicStack/httptools

Switch to Trusted Publishing for package upload to PyPI in CI

オープン
#140 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
1.3k
フォーク
107
PR マージ指標
30日以内にマージされた PR はありません

説明

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](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 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](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 [Release](https://github.com/MagicStack/httptools/blob/master/.github/workflows/release.yml) CI workflow

* Optionally remove the `PYPI_API_TOKEN` project secret

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

.github/workflows/release.yml から始めて publish ジョブを確認し、特に Upload to PyPI ステップを確認します。GitHub の pypi 環境とその PyPI への登録を設定し、要求されたジョブの権限と環境を追加して、password 引数と、任意で PYPI_API_TOKEN を削除します。保存されたトークンではなく、attestations 付きの Trusted Publishing を通じてリリースが公開されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
github-actions, python
領域
ci-cd, release, security
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
68/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。