npm 新增仅预发布令牌,2027年1月起移除绕过2FA直发
Stage-only npm tokens for safer automation
自动化构建与发布是 CI/CD 核心链路,2027年1月的强制变更将直接阻断旧版令牌的工作流。请检查你的 GitHub Actions 或 CI 脚本,尽早迁移至 stage-only 令牌或可信发布模式。
You can now select Read and write (stage only) when creating an npm granular access token. This lets your automated workflows stage package versions for review without giving the token permission to publish new versions directly to the npm registry.
创建 npm 细粒度访问令牌时,现在可以选择“读取和写入(仅限暂存)”。这允许你的自动化工作流将软件包版本暂存以供审查,而无需授予该令牌直接向 npm 注册表发布新版本的权利。
Your workflow uses npm stage publish to submit a version. A package maintainer then reviews and approves its release with two-factor authentication (2FA). npm rejects direct npm publish attempts with that token, even if you’ve configured it to bypass 2FA for automation.
你的工作流使用 npm stage publish 提交一个版本。然后,软件包维护者通过双因素认证 (2FA) 审核并批准其发布。即使你已配置该令牌以绕过自动化所需的 2FA,npm 也会拒绝使用该令牌的直接 npm publish 尝试。
Stage-only tokens retain other package write permissions, including moving dist-tags and deprecating versions. Protect them with the same care as any other write token.
仅限暂存的令牌保留其他软件包写入权限,包括移动 dist-tags 和弃用版本。请像保护任何其他写入令牌一样小心保护它们。
Prepare your automation for the token transition
为令牌过渡做好自动化准备
This release is opt-in and doesn’t change existing tokens or their direct-publish capabilities.
此发布为可选功能,不会更改现有令牌或其直接发布能力。
As previously announced, npm is targeting January 2027 to remove direct publishing through bypass-2FA tokens. If you can’t move to trusted publishing yet, stage-only tokens offer a migration path for token-based automation.
如先前宣布,npm 计划于 2027 年 1 月移除通过 bypass-2FA 令牌进行的直接发布。如果你暂时无法迁移到可信发布,仅限暂存的令牌为基于令牌的自动化提供了迁移路径。
To get started:
开始操作:
- Create a granular access token with Read and write (stage only) permissions for the packages your workflow needs.
- Replace your workflow’s publishing token and use npm stage publish instead of npm publish.
- Have a maintainer review and approve staged versions with 2FA.
- 为你的工作流所需的软件包创建一个具有“读取和写入(仅限暂存)”权限的细粒度访问令牌。
- 替换工作流中的发布令牌,并使用 npm stage publish 代替 npm publish。
- 由维护者通过 2FA 审核并批准暂存的版本。
Staged publishing works with existing npm packages. You’ll need publish access to the package, 2FA enabled on your npm account, npm CLI 11.15.0 or later, and Node.js 22.14.0 or later.
暂存发布适用于现有的 npm 软件包。你需要拥有该软件包的发布权限、在 npm 账户上启用 2FA、npm CLI 11.15.0 或更高版本,以及 Node.js 22.14.0 或更高版本。
Learn more about staged publishing, and share questions or migration blockers in the npm community discussion category.
了解更多关于暂存发布的信息,并在 npm 社区讨论类别中分享问题或迁移阻碍。
The post Stage-only npm tokens for safer automation appeared first on The GitHub Blog.
文章《用于更安全自动化的仅限暂存的 npm 令牌》最初发布于 GitHub 博客。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力