错误信息
--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,而是直接停止。
原因
来自 cosign 1.x 文档的命令
常见`COSIGN_EXPERIMENTAL=1 cosign verify image` 在 1.x 中可以运行,并且对任何身份都会验证通过。照搬到 2.x/3.x 的流水线中,就会在这里失败。
你还不知道签名者的身份
常见身份就是证书的 SAN:对于 GitHub Actions,是带 ref 的工作流 URL;对于交互式签名,是电子邮件地址。各项目会在验证说明旁边写明这个身份。
用密钥签名的制品,验证时没有带 --key
偶见如果制品是用密钥对签名的,就传入 `--key cosign.pub`;这样就不需要任何身份参数。
修复方法
- 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.
匹配多个值时使用带锚点的正则表达式
`--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.
从证书中读取身份
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