跳到主要内容
ecdsa.com
Sigstore cosign 2.x/3.x其他工具

错误信息

--certificate-identity or --certificate-identity-regexp is required for verification in keyless mode

也可能输出为

  • Error: --certificate-identity or --certificate-identity-regexp is required for verification in keyless mode

cosign 还要求提供 `--certificate-oidc-issuer`(或 `--certificate-oidc-issuer-regexp`);身份参数会先被检查。cosign 1.x 在没有这些参数时也接受无密钥验证。

Sigstore cosign 2.x/3.x — verify / verify-blob / verify-attestation without --key

含义

不带 `--key` 时,cosign 验证的是“无密钥”签名:Fulcio 签发的短期证书把签名绑定到一个 OIDC 身份(CI 工作流、电子邮件地址)。有效的无密钥签名只能证明“某个人”以“某种”身份签了名——因此 cosign 2.0 及更高版本要求你说明接受谁的签名。在你指定期望的身份和颁发者之前,命令不会读取 bundle,而是直接停止。

原因

修复方法

  1. 1.

    固定工作流身份和颁发者

    对于 GitHub Actions,颁发者是 `https://token.actions.githubusercontent.com`,身份是某个 ref 上的工作流文件。

    bash
    # Artifacts signed in GitHub Actions: identity = workflow file at a ref, issuer = GitHub's OIDC issuer
    cosign verify-blob \
      --bundle app.sigstore.json \
      --certificate-identity "https://github.com/acme/app/.github/workflows/release.yml@refs/tags/v1.4.2" \
      --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
      app.tar.gz
  2. 2.

    匹配多个值时使用带锚点的正则表达式

    `--certificate-identity-regexp` 可以让你接受同一工作流的所有标签。务必给它加上锚点,否则复刻仓库中的工作流也可能匹配。

    bash
    # Any release tag of that workflow - anchor the expression
    cosign verify ghcr.io/acme/app:1.4.2 \
      --certificate-identity-regexp '^https://github\.com/acme/app/\.github/workflows/release\.yml@refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$' \
      --certificate-oidc-issuer https://token.actions.githubusercontent.com
  3. 3.

    从证书中读取身份

    bundle 中证书的主题备用名称就是要固定的值——前提是你已经确认这个身份正是你信任的那个。

    bash
    # Read the identity recorded in the signing certificate of a bundle
    jq -r '.verificationMaterial.certificate.rawBytes' app.sigstore.json | base64 -d \
      | openssl x509 -inform DER -noout -ext subjectAltName

相关错误

浏览完整的签名错误库