How to publish to PyPI using GitHub Actions securely
Brett Cannon · 2026年7月7日
AI 摘要 AI 生成,可能有误
The article outlines three relatively painless steps for securely publishing to PyPI with GitHub Actions: using the zizmor tool to fix insecure workflow defaults (broad token permissions, persisted credentials, and unpinned actions) both locally and in CI, and adopting Trusted Publishing with a GitHub environment that requires reviewer approval before any publishing workflow runs. The author stresses that the post is not meant to shame maintainers into using GitHub Actions or Trusted Publishing, and recommends keeping build and publish workflows separate. Together, these measures guard against accidental or malicious workflow triggers while letting GitHub's security team handle the PyPI communication concerns.
There have been several security incidents lately that involved compromising GitHub Actions workflows. This has led some to say "GitHub Actions is the weakest link" in publishing and to GitHub publishing a GitHub Actions security roadmap update. But saying it's an issue and acknowledging the fact is one thing, but you still need to do the mitigation work today so you are not going to be the next headline. So this post is going to outline 3 things to do so you can publish to PyPI securely when using GitHub Actions.
But before I go any farther, I want to make 2 things very clear. One is this post is in no way meant to shame anyone into using GitHub Actions. For instance, I have heard people trying to shame maintainers into using GitHub Actions to use Trusted Publishing, and I think that's wrong. Now, if you choose to use a platform that supports Trusted Publishing, then you should definitely use it. But Trusted Publishing is not a reason to change your publishing workflow if the one you have is already secure. In other words, use whatever works best for you to publish securely to PyPI, and if that's GitHub Actions then this blog post is for you.
Two, the title of this post explicitly says "publishing" and not "building and publishing". Doing builds securely is a separate concern that I am not covering. The one piece of advice I will give, though, is one the Python security developer in residence gave me: you should have building and publishing be separate workflows.
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
AI 摘要The article argues that reproducible builds would strengthen Python's secure supply chain by allowing third parties to verify that distributions match their source code and detect tampering, citing SolarWinds as an example. What's missing includes recording the source code location in distribution metadata and support for software bills of materials (SBOMs) in sdists, which—unlike wheels—lack a place to store such data, though build backends could theoretically record build environments automatically without extra effort from distribution producers. The author also proposes that trusted verifiers could report successful reproductions to PyPI so users could see when a distribution was independently verified, framed as a perk rather than a requirement.
AI 摘要The author announces his self-nomination for the inaugural 2026 Python Packaging Council (PPC), with support from his employer Microsoft but no employer pressure. He cites his qualifications, including over 23 years as a Python core developer, service on the first five Python Steering Councils, co-maintaining the packaging project, and authoring seven packaging PEPs such as PEP 518 and PEP 751. His goals for the PPC include drawing on his steering council experience to establish the new body, improving the developer experience for both package producers and consumers, and strengthening the secure supply chain through reproducible builds and software bills of materials (SBOMs).
AI 摘要The article explains why the author wrote PEP 832, addressing the problem that tools like VS Code (or any editor or AI agent) cannot easily determine which workflow tool a Python project uses or where its virtual environments are located. It outlines key difficulties—such as discovering environments on first project open, handling environments stored outside the project or shared across projects via tools like conda—and proposes solutions including detecting .venv directories, a .python-envs file listing environment paths, and a [workflow] table in pyproject.toml paired with a workflow server protocol (WSP) for JSON-RPC communication between tools. The author's motivation is to make project setup as easy as possible for users of all experience levels by hiding environment management, while creating a general, editor-agnostic standard rather than the VS Code-specific bespoke integrations that exist today.
AI 摘要The article explains that a Python project hack involving malicious PyPI uploads could have been detected if the project used trusted publishing with digital attestations, since pylock.toml lock files record publisher details (e.g., the GitHub repo and workflow) for each file. Trusted publishing lets CD systems upload releases without exposing API keys, while attestations verify a file's origin, allowing users to compare the lock file's recorded publisher against PyPI's data to spot discrepancies. The author recommends that maintainers enable trusted publishing and attestations, and that users verify attestations in lock files via code or manual review of diffs to catch suspicious changes or deletions.
AI 摘要Recent WASI work in CPython has focused on easing maintenance and development, including a WASI dev container, updated devguide instructions, and a CLI app. PEP 816, which defines WASI compatibility handling starting with Python 3.15, was accepted; it locks in supported WASI and WASI SDK versions once a Python version reaches its first beta, giving the community a stable target for building packages. Next steps include implementing a subcommand to bundle WASI builds for distribution, writing a PEP for a wheel platform tag, adding a subcommand to build dependencies, and enabling socket support once WASI 0.3 and threading support are released.