-
Notifications
You must be signed in to change notification settings - Fork 676
Support self-managed keys when signing with sigstore-go #4368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4368 +/- ##
==========================================
- Coverage 40.10% 34.75% -5.36%
==========================================
Files 155 217 +62
Lines 10044 15329 +5285
==========================================
+ Hits 4028 5327 +1299
- Misses 5530 9311 +3781
- Partials 486 691 +205 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6fa7574 to
072fbea
Compare
072fbea to
020fda7
Compare
|
Verified this works with Rekor v2: |
0b84033 to
927fffa
Compare
927fffa to
6c5159e
Compare
steiza
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM - I don't understand the IssueCertificateForExistingKey part though.
cmd/cosign/cli/attest/attest_blob.go
Outdated
| // Set to false so sigstore-go fetches the Fulcio certificate, | ||
| // otherwise SignerFromKeyOpts would through the old signing path | ||
| issueCertForKey := c.IssueCertificateForExistingKey | ||
| c.IssueCertificateForExistingKey = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this code block. What flag to I pass to cosign attest-blob to specify this behavior? Where does this get used by sigstore-go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we have too much duplication everywhere, I had missed adding --issue-certificate to attest-blob and attest - I just added this.
For context, --issue-certificate was added as part of https://blog.sigstore.dev/adopting-sigstore-incrementally-1b56a69b8c15/, to request a Fulcio certificate even if a key is provided.
This flag isn't used by sigstore-go, it's used by SignerFromKeyOpts, which does a few things - it load a key from KMS/PIV/disk, it generates a key, and if IssueCertificateForExistingKey is set or an ephemeral key was generated, it requests a certificate from Fulcio. This is the root cause of the issue, the method does too much.
sigstore-go will be handling certificate requests, so I need to set IssueCertificateForExistingKey to false to prevent SignerFromKeyOpts from trying to generate a cert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhh, okay, now I see. Still, mutating the configuration like this makes me a bit nervous (I've been bitten before in the cosign code base doing similar things!)
The "problem" is that SignerFromKeyOpts does two things:
- Constructs the
SignerVerifier - Calls
keylessSignerin some cases
There aren't that many places we call SignerFromKeyOpts. Instead of mutating the config like this, would it make sense to have keylessSigner become a public method and call it when needed from the cmd/cosign/cli files? I'm not 100% sure if that's better or not, but I think it would allow us to avoid mutating the configuration like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'm happy to try this out.
FYI @ret2libc, this would also solve the e2e test failure you were running into.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored this and then searched for method usage across GitHub and found it's being used in some libraries. So one of two options:
- Call this out in the CHANGELOG - we provide no guarantees for API breakages, and because the method signature has changed, it'll force clients to make an update
- Check if
SigningConfigis set inSignerFromKeyOpts- This is kinda gross
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think a CHANGELOG entry is just fine.
f6a043d to
6d27d43
Compare
steiza
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
This creates a wrapper around the Keypair interface when a SignerVerifier is provided for signing with KMS or any other provided keys. This also retains support for --issue-certificate to request a certificate for a managed key. Fixes sigstore#4327 Signed-off-by: Hayden <[email protected]>
This is for uniformity with sign/sign-blob. Signed-off-by: Hayden <[email protected]>
Now, we can generate a SignerVerifier from a provided key without mandating that we also request a Fulcio certificate when "issue-certificate" is provided. Signed-off-by: Hayden <[email protected]>
6d27d43 to
d2bac6a
Compare
Signed-off-by: Hayden <[email protected]>
d2bac6a to
0c22436
Compare
|
Re-verified all commands work with after the rebase. Signing with a non-ecdsa-p256 key doesn't work with Rekor v2, but that's a bug in sigstore-go I'm fixing now, no need to block this PR. |
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 ([#​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 [#​3927](sigstore/cosign#3927) ([#​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 ([#​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 ([#​4306](sigstore/cosign#4306)) - Have cosign sign support bundle format ([#​4316](sigstore/cosign#4316)) - Add support for SigningConfig for sign-blob/attest-blob, support Rekor v2 ([#​4319](sigstore/cosign#4319)) - Add support for SigningConfig in sign/attest ([#​4371](sigstore/cosign#4371)) - Support self-managed keys when signing with sigstore-go ([#​4368](sigstore/cosign#4368)) - Don't require timestamps when verifying with a key ([#​4337](sigstore/cosign#4337)) - Don't load content from TUF if trusted root path is specified ([#​4347](sigstore/cosign#4347)) - Add a terminal spinner while signing with sigstore-go ([#​4402](sigstore/cosign#4402)) - Require exclusively a SigningConfig or service URLs when signing ([#​4403](sigstore/cosign#4403)) - Remove SHA256 assumption in sign-blob/verify-blob ([#​4050](sigstore/cosign#4050)) - Bump sigstore-go, support alternative hash algorithms with keys ([#​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 ([#​4320](sigstore/cosign#4320)) - Fixes to cosign sign / verify for the new bundle format ([#​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=-->
This creates a wrapper around the Keypair interface when a SignerVerifier is provided for signing with KMS or any other provided keys. This also retains support for --issue-certificate to request a certificate for a managed key.
Fixes #4327
Summary
Release Note
Documentation