跳到主要内容
ecdsa.com
npm publish --provenance (npm 9.5+)包管理器

错误信息

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 中运行的。没有发布任何内容。

原因

修复方法

  1. 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. 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

相关错误

浏览完整的签名错误库