-
Notifications
You must be signed in to change notification settings - Fork 222
Discover cosign v3 NewBundleFormat for verification #1961
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,13 @@ import ( | |
|
|
||
| "github.com/google/go-containerregistry/pkg/name" | ||
| "github.com/google/go-containerregistry/pkg/v1/remote" | ||
| "github.com/sigstore/cosign/v2/cmd/cosign/cli/fulcio" | ||
| coptions "github.com/sigstore/cosign/v2/cmd/cosign/cli/options" | ||
| "github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor" | ||
| "github.com/sigstore/cosign/v2/pkg/cosign" | ||
| ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote" | ||
| "github.com/sigstore/cosign/v3/cmd/cosign/cli/fulcio" | ||
| coptions "github.com/sigstore/cosign/v3/cmd/cosign/cli/options" | ||
| "github.com/sigstore/cosign/v3/cmd/cosign/cli/rekor" | ||
| "github.com/sigstore/cosign/v3/pkg/cosign" | ||
| "github.com/sigstore/cosign/v3/pkg/oci" | ||
|
|
||
| ociremote "github.com/sigstore/cosign/v3/pkg/oci/remote" | ||
| "github.com/sigstore/sigstore/pkg/cryptoutils" | ||
| "github.com/sigstore/sigstore/pkg/signature" | ||
|
|
||
|
|
@@ -80,6 +82,7 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e | |
| } | ||
|
|
||
| checkOpts := &cosign.CheckOpts{} | ||
| checkOpts.NewBundleFormat = true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line seems unneeded since we're assigning the value of this field for each case inside |
||
|
|
||
| ro := coptions.RegistryOptions{} | ||
| co, err := ro.ClientOpts(ctx) | ||
|
|
@@ -146,10 +149,25 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e | |
| } | ||
|
|
||
| // Verify verifies the authenticity of the given ref OCI image. | ||
| // Both cosign v2 signatures and cosign v3 bundles are supported by | ||
| // attempting to discover bundles before verification. | ||
| // Bundles can be located either via the OCI 1.1 referrer API or an | ||
| // OCI 1.0 referrer tag. | ||
| // It returns a boolean indicating if the verification was successful. | ||
| // It returns an error if the verification fails, nil otherwise. | ||
| func (v *CosignVerifier) Verify(ctx context.Context, ref name.Reference) (soci.VerificationResult, error) { | ||
| signatures, _, err := cosign.VerifyImageSignatures(ctx, ref, v.opts) | ||
| var signatures []oci.Signature | ||
| // copy options since we'll need to change them based on bundle discovery on the ref | ||
| opts := *v.opts | ||
| newBundles, _, err := cosign.GetBundles(ctx, ref, opts.RegistryClientOpts) | ||
| if len(newBundles) == 0 || err != nil { | ||
| opts.NewBundleFormat = false | ||
| signatures, _, err = cosign.VerifyImageSignatures(ctx, ref, &opts) | ||
| } else { | ||
| opts.NewBundleFormat = true | ||
| signatures, _, err = cosign.VerifyImageAttestations(ctx, ref, &opts) | ||
| } | ||
| fmt.Println(opts.NewBundleFormat, v.opts.NewBundleFormat) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops |
||
| if err != nil { | ||
| return soci.VerificationResultFailed, err | ||
| } | ||
|
|
||
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.
nit