Skip to content

Use the verify defined interface in OCIRepository #1417

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

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions internal/controller/ocirepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (r *OCIRepositoryReconciler) verifySignature(ctx context.Context, obj *ociv
return soci.VerificationResultFailed, err
}

signatureVerified := false
signatureVerified := soci.VerificationResultFailed
for k, data := range pubSecret.Data {
// search for public keys in the secret
if strings.HasSuffix(k, ".pub") {
Expand All @@ -653,19 +653,19 @@ func (r *OCIRepositoryReconciler) verifySignature(ctx context.Context, obj *ociv
return soci.VerificationResultFailed, err
}

signatures, _, err := verifier.VerifyImageSignatures(ctxTimeout, ref)
if err != nil {
result, err := verifier.Verify(ctxTimeout, ref)
if err != nil || result == soci.VerificationResultFailed {
continue
}

if signatures != nil {
signatureVerified = true
if result == soci.VerificationResultSuccess {
signatureVerified = result
break
}
}
}

if !signatureVerified {
if signatureVerified == soci.VerificationResultFailed {
return soci.VerificationResultFailed, fmt.Errorf("no matching signatures were found for '%s'", ref)
}

Expand All @@ -689,16 +689,16 @@ func (r *OCIRepositoryReconciler) verifySignature(ctx context.Context, obj *ociv
return soci.VerificationResultFailed, err
}

signatures, _, err := verifier.VerifyImageSignatures(ctxTimeout, ref)
result, err := verifier.Verify(ctxTimeout, ref)
if err != nil {
return soci.VerificationResultFailed, err
}

if len(signatures) > 0 {
return soci.VerificationResultSuccess, nil
if result == soci.VerificationResultFailed {
return soci.VerificationResultFailed, fmt.Errorf("no matching signatures were found for '%s'", ref)
}

return soci.VerificationResultFailed, fmt.Errorf("no matching signatures were found for '%s'", ref)
return soci.VerificationResultSuccess, nil

case "notation":
// get the public keys from the given secret
Expand Down
8 changes: 1 addition & 7 deletions internal/oci/cosign/cosign.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
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"
"github.com/sigstore/cosign/v2/pkg/oci"
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature"
Expand Down Expand Up @@ -146,16 +145,11 @@ func NewCosignVerifier(ctx context.Context, opts ...Options) (*CosignVerifier, e
}, nil
}

// VerifyImageSignatures verify the authenticity of the given ref OCI image.
func (v *CosignVerifier) VerifyImageSignatures(ctx context.Context, ref name.Reference) ([]oci.Signature, bool, error) {
return cosign.VerifyImageSignatures(ctx, ref, v.opts)
}

// Verify verifies the authenticity of the given ref OCI image.
// 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 := v.VerifyImageSignatures(ctx, ref)
signatures, _, err := cosign.VerifyImageSignatures(ctx, ref, v.opts)
if err != nil {
return soci.VerificationResultFailed, err
}
Expand Down