@@ -501,18 +501,15 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
501
501
return sreconcile .ResultSuccess , nil
502
502
}
503
503
504
- // verifyOCISourceSignature verifies the authenticity of the given image reference url. First, it tries using a key,
505
- // provided the secret exists and a public key exists in the secret . Then, if it does not exist , it pushes for a keyless approach for verification.
504
+ // verifyOCISourceSignature verifies the authenticity of the given image reference url. First, it tries using a key
505
+ // if a secret with a valid public key is provided. If not, it falls back to a keyless approach for verification.
506
506
func (r * OCIRepositoryReconciler ) verifyOCISourceSignature (ctx context.Context , obj * sourcev1.OCIRepository , url string , keychain authn.Keychain ) error {
507
507
ctxTimeout , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
508
508
defer cancel ()
509
509
510
510
provider := obj .Spec .Verify .Provider
511
511
switch provider {
512
512
case "cosign" :
513
- // get the public keys from the given secret
514
- secretRef := obj .Spec .Verify .SecretRef
515
-
516
513
defaultCosignOciOpts := []soci.Options {
517
514
soci .WithAuthnKeychain (keychain ),
518
515
soci .WithContext (ctxTimeout ),
@@ -523,7 +520,8 @@ func (r *OCIRepositoryReconciler) verifyOCISourceSignature(ctx context.Context,
523
520
return err
524
521
}
525
522
526
- if secretRef != nil {
523
+ // get the public keys from the given secret
524
+ if secretRef := obj .Spec .Verify .SecretRef ; secretRef != nil {
527
525
certSecretName := types.NamespacedName {
528
526
Namespace : obj .Namespace ,
529
527
Name : secretRef .Name ,
@@ -560,23 +558,25 @@ func (r *OCIRepositoryReconciler) verifyOCISourceSignature(ctx context.Context,
560
558
}
561
559
562
560
return nil
563
- } else {
564
- ctrl .LoggerFrom (ctx ).Info ("no secret reference is provided, trying to verify the image using keyless approach" )
565
- verifier , err := soci .New (defaultCosignOciOpts ... )
566
- if err != nil {
567
- return err
568
- }
561
+ }
569
562
570
- signatures , _ , err := verifier .VerifyImageSignatures (ref )
571
- if err != nil {
572
- return err
573
- }
563
+ // if no secret is provided, try keyless verification
564
+ ctrl .LoggerFrom (ctx ).Info ("no secret reference is provided, trying to verify the image using keyless approach" )
565
+ verifier , err := soci .New (defaultCosignOciOpts ... )
566
+ if err != nil {
567
+ return err
568
+ }
574
569
575
- if len ( signatures ) > 0 {
576
- return nil
577
- }
570
+ signatures , _ , err := verifier . VerifyImageSignatures ( ref )
571
+ if err != nil {
572
+ return err
578
573
}
579
- return nil
574
+
575
+ if len (signatures ) > 0 {
576
+ return nil
577
+ }
578
+
579
+ return fmt .Errorf ("no matching signatures were found for '%s'" , url )
580
580
}
581
581
582
582
return nil
@@ -980,8 +980,7 @@ func (r *OCIRepositoryReconciler) garbageCollect(ctx context.Context, obj *sourc
980
980
// that this is a simple log. While the debug log contains complete details
981
981
// about the event.
982
982
func (r * OCIRepositoryReconciler ) eventLogf (ctx context.Context ,
983
- obj runtime.Object , eventType , reason , messageFmt string , args ... interface {},
984
- ) {
983
+ obj runtime.Object , eventType string , reason string , messageFmt string , args ... interface {}) {
985
984
msg := fmt .Sprintf (messageFmt , args ... )
986
985
// Log and emit event.
987
986
if eventType == corev1 .EventTypeWarning {
0 commit comments