Skip to content

Commit f829be7

Browse files
committed
Discover cosign v3 NewBundleFormat for verification
v2 signatures and v3 bundled signatures both function transparently. This does require additional queries to the registry. Signed-off-by: leigh capili <leigh@null.net>
1 parent fc0c8ea commit f829be7

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

internal/controller/helmchart_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignatureCosign(t *tes
34683468
Timeout: timeout,
34693469
}
34703470

3471-
err = sign.SignCmd(ro, ko, coptions.SignOptions{
3471+
err = sign.SignCmd(ctx, ro, ko, coptions.SignOptions{
34723472
Upload: true,
34733473
SkipConfirmation: true,
34743474
TlogUpload: false,

internal/controller/ocirepository_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignatureCosign(t *testing
22112211
ro := &coptions.RootOptions{
22122212
Timeout: timeout,
22132213
}
2214-
err = sign.SignCmd(ro, ko, coptions.SignOptions{
2214+
err = sign.SignCmd(ctx, ro, ko, coptions.SignOptions{
22152215
Upload: true,
22162216
SkipConfirmation: true,
22172217
TlogUpload: false,

internal/oci/cosign/cosign.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
coptions "github.com/sigstore/cosign/v3/cmd/cosign/cli/options"
2828
"github.com/sigstore/cosign/v3/cmd/cosign/cli/rekor"
2929
"github.com/sigstore/cosign/v3/pkg/cosign"
30+
"github.com/sigstore/cosign/v3/pkg/oci"
3031

3132
ociremote "github.com/sigstore/cosign/v3/pkg/oci/remote"
3233
"github.com/sigstore/sigstore/pkg/cryptoutils"
@@ -81,6 +82,7 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
8182
}
8283

8384
checkOpts := &cosign.CheckOpts{}
85+
checkOpts.NewBundleFormat = true
8486

8587
ro := coptions.RegistryOptions{}
8688
co, err := ro.ClientOpts(ctx)
@@ -147,10 +149,25 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
147149
}
148150

149151
// Verify verifies the authenticity of the given ref OCI image.
152+
// Both cosign v2 signatures and cosign v3 bundles are supported by
153+
// attempting to discover bundles before verification.
154+
// Bundles can be located either via the OCI 1.1 referrer API or an
155+
// OCI 1.0 referrer tag.
150156
// It returns a boolean indicating if the verification was successful.
151157
// It returns an error if the verification fails, nil otherwise.
152158
func (v *CosignVerifier) Verify(ctx context.Context, ref name.Reference) (soci.VerificationResult, error) {
153-
signatures, _, err := cosign.VerifyImageSignatures(ctx, ref, v.opts)
159+
var signatures []oci.Signature
160+
// copy options since we'll need to change them based on bundle discovery on the ref
161+
opts := *v.opts
162+
newBundles, _, err := cosign.GetBundles(ctx, ref, opts.RegistryClientOpts)
163+
if len(newBundles) == 0 || err != nil {
164+
opts.NewBundleFormat = false
165+
signatures, _, err = cosign.VerifyImageSignatures(ctx, ref, &opts)
166+
} else {
167+
opts.NewBundleFormat = true
168+
signatures, _, err = cosign.VerifyImageAttestations(ctx, ref, &opts)
169+
}
170+
fmt.Println(opts.NewBundleFormat, v.opts.NewBundleFormat)
154171
if err != nil {
155172
return soci.VerificationResultFailed, err
156173
}

0 commit comments

Comments
 (0)