错误信息
Automatic provenance generation not supported for provider: null
也可能输出为
- Provenance generation in GitHub Actions requires "write" access to the "id-token" permission
- Provenance generation in GitLab CI requires "SIGSTORE_ID_TOKEN" with "sigstore" audience to be present in "id_tokens".
在没有 `permissions: id-token: write` 的 GitHub Actions 中,消息是“Provenance generation in GitHub Actions requires "write" access to the "id-token" permission”(两者均用 npm 11.19.1 复现);在没有 `id_tokens` 条目的 GitLab 中,消息会提到 `SIGSTORE_ID_TOKEN`(文本取自 libnpmpublish 的源代码)。这些都是 `EUSAGE` 错误。提供方名称来自 npm 的 CI 检测(`ci-info`)。
npm publish --provenance (npm 9.5+) — libnpmpublish, code EUSAGE
含义
`npm publish --provenance` 会创建一份经过签名的 SLSA 来源证明声明,说明是哪个 CI 工作流构建了这个包。npm 只能在提供 OIDC 身份的受支持 CI 系统中做到这一点(GitHub 托管运行器上的 GitHub Actions、共享运行器上的 GitLab CI);Sigstore 会把这个身份写入签名证书。`provider: null` 表示 npm 根本没有检测到 CI——命令是在开发者的机器上或不受支持的 CI 中运行的。没有发布任何内容。
原因
从笔记本电脑发布
常见为维护者手动发布的包设置了 `--provenance`(或 `.npmrc` 中的 `provenance=true`,或 `publishConfig.provenance`)。来源证明的用途是证明构建发生在 CI 中,因此无法在本地生成。
没有权限签发 OIDC 令牌的 CI 作业
常见GitHub Actions 只有在设置了 `id-token: write` 时才提供该令牌;GitLab 只有在存在受众为 `sigstore` 的 `id_tokens` 条目时才提供。
npm 无法为其生成来源证明的 CI 系统
偶见Jenkins、CircleCI、自托管运行器等能被检测到(消息中会出现提供方名称),但不支持自动生成来源证明。
修复方法
- 1.
从 GitHub Actions 工作流发布
授予 `id-token: write`,在 GitHub 托管运行器上运行,并使用 `--provenance` 发布。npm 的可信发布(OIDC)可以完全取代 npm 令牌。
yaml name: release on: { release: { types: [published] } } permissions: contents: read id-token: write # lets npm obtain the OIDC token Sigstore needs jobs: publish: runs-on: ubuntu-latest # GitHub-hosted runner steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: { node-version: 24, registry-url: "https://registry.npmjs.org" } - run: npm ci - run: npm publish --provenance --access public env: { NODE_AUTH_TOKEN: "${{ secrets.NPM_TOKEN }}" } - 2.
或者从 GitLab CI 发布
在 `id_tokens` 下申请受众为 `sigstore` 的 ID 令牌;npm 会从 `SIGSTORE_ID_TOKEN` 中读取它。
yaml publish: image: node:24 id_tokens: SIGSTORE_ID_TOKEN: aud: sigstore script: - npm publish --provenance --access public