Skip to content

Conversation

@haydentherapper
Copy link
Contributor

@haydentherapper haydentherapper commented Aug 1, 2025

Summary

This is the first PR to leverage sigstore-go's signing API, which is gated on whether or not a signing config is provided. While we could continue to reuse Cosign's signing APIs by passing in the signing config URLs to KeyOpts, we would not have support for Rekor v2 signing, which has only been implemented in sigstore-go. When a SigningConfig is provided, it will also force usage of the new bundle format.

You can see how much simpler sign/attest-blob will be once we start refactoring the CLI code.

There are two follow ups for this PR: Adding support for SigningConfig for attest (and eventually sign) and adding support for self-managed keys, which just requires a few Keypair implementations that wrap SignerVerifier.

This PR is split into two commits. The first refactors the authentication layer so it can be reused without Cosign's fulcio.Signer (which we can eventually move out to a utilities library), and the second adds support for SigningConfig.

Release Note

  • Added support for SigningConfig for sign-blob and attest-blob
  • Added support for Rekor v2 signing and verification

Documentation

@codecov
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 18.86228% with 271 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.62%. Comparing base (2ef6022) to head (4901485).
⚠️ Report is 463 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cosign/bundle/sign.go 0.00% 82 Missing ⚠️
internal/auth/auth.go 40.21% 52 Missing and 3 partials ⚠️
cmd/cosign/cli/attest/attest_blob.go 18.75% 38 Missing and 1 partial ⚠️
cmd/cosign/cli/sign/sign_blob.go 0.00% 37 Missing and 1 partial ⚠️
cmd/cosign/cli/attest_blob.go 0.00% 15 Missing ⚠️
cmd/cosign/cli/signblob.go 0.00% 15 Missing ⚠️
pkg/cosign/tuf.go 0.00% 10 Missing ⚠️
cmd/cosign/cli/options/attest_blob.go 0.00% 7 Missing ⚠️
cmd/cosign/cli/options/signblob.go 0.00% 7 Missing ⚠️
cmd/cosign/cli/fulcio/fulcio.go 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4319      +/-   ##
==========================================
- Coverage   40.10%   34.62%   -5.49%     
==========================================
  Files         155      216      +61     
  Lines       10044    14878    +4834     
==========================================
+ Hits         4028     5151    +1123     
- Misses       5530     9063    +3533     
- Partials      486      664     +178     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haydentherapper haydentherapper force-pushed the sign-sigstore-go branch 6 times, most recently from b9a85d7 to 8cf6ff7 Compare August 1, 2025 18:49
@haydentherapper haydentherapper changed the title Add support for SigningConfig for sign-blob/attest-blob Add support for SigningConfig for sign-blob/attest-blob, support Rekor v2 Aug 1, 2025
@haydentherapper haydentherapper force-pushed the sign-sigstore-go branch 3 times, most recently from 50797d8 to 50a3b14 Compare August 1, 2025 22:08
@haydentherapper
Copy link
Contributor Author

Verified working against our staging Rekor v2 instance:

curl -LO https://raw.githubusercontent.com/sigstore/root-signing-staging/refs/heads/main/metadata/root_history/1.root.json
cosign initialize --mirror="https://tuf-repo-cdn.sigstage.dev" --root=1.root.json

cosign sign-blob --use-signing-config --bundle sigstore.json README.md

cosign verify-blob --new-bundle-format --bundle sigstore.json --certificate-identity $EMAIL --certificate-oidc-issuer https://accounts.google.com --use-signed-timestamps README.md

And for attestations...

cosign attest-blob --use-signing-config --statement intoto.txt --bundle sigstore.att.json

cosign verify-blob-attestation --new-bundle-format --bundle sigstore.att.json --certificate-identity $EMAIL --certificate-oidc-issuer https://accounts.google.com --use-signed-timestamps --digestAlg sha256 --digest="b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"

@haydentherapper haydentherapper marked this pull request as ready for review August 1, 2025 22:54
@haydentherapper haydentherapper requested review from a team as code owners August 1, 2025 22:54
@haydentherapper
Copy link
Contributor Author

Proof it's using Rekor v2:

cat sigstore.json | jq -r ".verificationMaterial.tlogEntries[0]".inclusionProof.checkpoint.envelope

log2025-alpha1.rekor.sigstage.dev
19056
bfZQI4+dbAj12+FU+t1/DwP+/M5lrQGODznnOG2OYsM=

— log2025-alpha1.rekor.sigstage.dev 8w1amS0/tukAkFuM+b+hDou8IeUyeyfAnUphXTQ/ntwKodJlMfaQGJ7blOD0OdUam7+NiWaHhW3+wQ96q2pOAZw1fgg=

}

if c.SigningConfig != nil {
// TODO: Only ephemeral keys are currently supported
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline but will still note here, I think it's important to get this added quickly as it's a bigger use case in cosign than in sigstore-go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created issues to track this, will get this implemented right after.

opts.TrustedRoot = trustedMaterial
}

if idToken != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could fetching the idToken be moved here, instead of duplicating in sign_blob.go and attest_blob.go? This is already where the rest of the SelectService logic seems to be happening.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored identity token retrieval into its own method that's now called from sign_blob and attest_blob. When we move this out into a shared library and work towards v3, I'll want to refactor this a bit more - for example, providing an identity token via flag that's either the token itself or a path isn't the cleanest UX.

This will allow these functions to be reused by other parts of the
codebase, and eventually we can move these into an external package for
use by other libraries.

Signed-off-by: Hayden B <[email protected]>
Copy link
Member

@steiza steiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, one small comment on flags.

What about OCI support for signing config / Rekor v2? When would it make sense to also add this functionality to attest and sign?

Comment on lines +166 to +168
// TODO(#4327): Only ephemeral keys are currently supported
// Need to add support for self-managed keys (e.g. PKCS11, KMS, on disk)
// and determine if we want to store certificates for those as well.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime, should we check for key flags like --key, --sk, or --slot and return an error to the user? Otherwise I'm worried we're silently ignoring those options if you're using signing config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, returning an error if any self-managed key is provided with a signing config.

@haydentherapper
Copy link
Contributor Author

What about OCI support for signing config / Rekor v2? When would it make sense to also add this functionality to attest and sign?

Tracking this in #4324. My plan would be to merge this PR and your PR, then I'll circle back to add support for sign and attest when using the new bundle format.

@haydentherapper haydentherapper requested a review from cmurphy August 6, 2025 20:57
@haydentherapper haydentherapper requested a review from steiza August 6, 2025 20:57
Copy link
Member

@steiza steiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - nice work!

@haydentherapper haydentherapper merged commit f011b93 into sigstore:main Aug 7, 2025
29 checks passed
@haydentherapper haydentherapper deleted the sign-sigstore-go branch August 7, 2025 16:21
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 16, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cosign](https://github.com/sigstore/cosign) | minor | `2.5.3` -> `2.6.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>sigstore/cosign (cosign)</summary>

### [`v2.6.0`](https://github.com/sigstore/cosign/blob/HEAD/CHANGELOG.md#v260)

[Compare Source](sigstore/cosign@v2.5.3...v2.6.0)

v2.6.0 introduces a number of new features, including:

- Signing an in-toto statement rather than Cosign constructing one from a predicate, along with verifying a statement's subject using a digest and digest algorithm rather than providing a file reference ([#&#8203;4306](sigstore/cosign#4306))
- Uploading a signature and its verification material (a ["bundle"](https://github.com/sigstore/protobuf-specs/blob/main/protos/sigstore_bundle.proto)) as an OCI Image 1.1 referring artifact, completing [#&#8203;3927](sigstore/cosign#3927) ([#&#8203;4316](sigstore/cosign#4316))
- Providing service URLs for signing and attesting using a [SigningConfig](https://github.com/sigstore/protobuf-specs/blob/4df5baadcdb582a70c2bc032e042c0a218eb3841/protos/sigstore_trustroot.proto#L185). Note that this is required when using a [Rekor v2](https://github.com/sigstore/rekor-tiles) instance ([#&#8203;4319](sigstore/cosign#4319))

Example generation and verification of a signed in-toto statement:

```
cosign attest-blob --new-bundle-format=true --bundle="digest-key-test.sigstore.json" --key="cosign.key" --statement="../sigstore-go/examples/sigstore-go-signing/intoto.txt"
cosign verify-blob-attestation --bundle="digest-key-test.sigstore.json" --key=cosign.pub --type=unused --digest="b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9" --digestAlg="sha256"
```

Example container signing and verification using the new bundle format and referring artifacts:

```
cosign sign --new-bundle-format=true ghcr.io/user/alpine@sha256:a19367999603840546b8612572e338ec076c6d1f2fec61760a9e11410f546733
cosign verify --new-bundle-format=true ghcr.io/user/alpine@sha256:a19367999603840546b8612572e338ec076c6d1f2fec61760a9e11410f546733
```

Example usage of a signing config provided by the public good instance's TUF repository:

```
cosign sign-blob --use-signing-config --bundle sigstore.json README.md
cosign verify-blob --new-bundle-format --bundle sigstore.json --certificate-identity $EMAIL --certificate-oidc-issuer $ISSUER --use-signed-timestamps README.md
```

v2.6.0 leverages sigstore-go's signing and verification APIs gated behind these new flags. In an upcoming major release, we will be
updating Cosign to default to producing and consuming bundles to align with all other Sigstore SDKs.

#### Features

- Add to `attest-blob` the ability to supply a complete in-toto statement, and add to `verify-blob-attestation` the ability to verify with just a digest ([#&#8203;4306](sigstore/cosign#4306))
- Have cosign sign support bundle format ([#&#8203;4316](sigstore/cosign#4316))
- Add support for SigningConfig for sign-blob/attest-blob, support Rekor v2 ([#&#8203;4319](sigstore/cosign#4319))
- Add support for SigningConfig in sign/attest ([#&#8203;4371](sigstore/cosign#4371))
- Support self-managed keys when signing with sigstore-go ([#&#8203;4368](sigstore/cosign#4368))
- Don't require timestamps when verifying with a key ([#&#8203;4337](sigstore/cosign#4337))
- Don't load content from TUF if trusted root path is specified ([#&#8203;4347](sigstore/cosign#4347))
- Add a terminal spinner while signing with sigstore-go ([#&#8203;4402](sigstore/cosign#4402))
- Require exclusively a SigningConfig or service URLs when signing ([#&#8203;4403](sigstore/cosign#4403))
- Remove SHA256 assumption in sign-blob/verify-blob ([#&#8203;4050](sigstore/cosign#4050))
- Bump sigstore-go, support alternative hash algorithms with keys ([#&#8203;4386](sigstore/cosign#4386))

#### Breaking API Changes

- `sign.SignerFromKeyOpts` no longer generates a key. Instead, it returns whether or not the client needs to generate a key, and if so, clients
  should call `sign.KeylessSigner`. This allows clients to more easily manage key generation.

#### Bug Fixes

- Verify subject with bundle only when checking claims ([#&#8203;4320](sigstore/cosign#4320))
- Fixes to cosign sign / verify for the new bundle format ([#&#8203;4346](sigstore/cosign#4346))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xMTMuNSIsInVwZGF0ZWRJblZlciI6IjQxLjExMy41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants