MagicStack / MagicStack/httptools
Switch to Trusted Publishing for package upload to PyPI in CI
还没有人认领这个 Issue。
- 主要语言
- 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) 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:
- https://futuresearch.ai/blog/litellm-pypi-supply-chain-attack/
- 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
publishjob -
Add
id-token: write,contents: writeandpackages: writepermissions to the samepublishjob- specifying any permission restricts the token, and creating a GitHub release requires
contents: writeand potentiallypackages: write
- specifying any permission restricts the token, and creating a GitHub release requires
-
Remove
passwordargument in theUpload to PyPIstep of thepublishjob of the Release CI workflow -
Optionally remove the
PYPI_API_TOKENproject secret
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 .github/workflows/release.yml 开始,检查 publish job,尤其是 Upload to PyPI 步骤。配置 GitHub pypi 环境及其 PyPI 注册,添加所请求的 job 权限和环境,并移除 password 参数以及可选的 PYPI_API_TOKEN。完成的标准是:通过 Trusted Publishing 并使用 attestations 发布 releases,而不是使用存储的 token。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- github-actions, python
- 领域
- ci-cd, release, security
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100