Skip to content

Commit 03af4f6

Browse files
Dentraxstefanprodan
authored andcommitted
fix: ocirepository_controller reviews
Signed-off-by: Furkan <[email protected]>
1 parent 2db2715 commit 03af4f6

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

controllers/ocirepository_controller.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -501,18 +501,15 @@ func (r *OCIRepositoryReconciler) reconcileSource(ctx context.Context, obj *sour
501501
return sreconcile.ResultSuccess, nil
502502
}
503503

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.
506506
func (r *OCIRepositoryReconciler) verifyOCISourceSignature(ctx context.Context, obj *sourcev1.OCIRepository, url string, keychain authn.Keychain) error {
507507
ctxTimeout, cancel := context.WithTimeout(ctx, obj.Spec.Timeout.Duration)
508508
defer cancel()
509509

510510
provider := obj.Spec.Verify.Provider
511511
switch provider {
512512
case "cosign":
513-
// get the public keys from the given secret
514-
secretRef := obj.Spec.Verify.SecretRef
515-
516513
defaultCosignOciOpts := []soci.Options{
517514
soci.WithAuthnKeychain(keychain),
518515
soci.WithContext(ctxTimeout),
@@ -523,7 +520,8 @@ func (r *OCIRepositoryReconciler) verifyOCISourceSignature(ctx context.Context,
523520
return err
524521
}
525522

526-
if secretRef != nil {
523+
// get the public keys from the given secret
524+
if secretRef := obj.Spec.Verify.SecretRef; secretRef != nil {
527525
certSecretName := types.NamespacedName{
528526
Namespace: obj.Namespace,
529527
Name: secretRef.Name,
@@ -560,23 +558,25 @@ func (r *OCIRepositoryReconciler) verifyOCISourceSignature(ctx context.Context,
560558
}
561559

562560
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+
}
569562

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+
}
574569

575-
if len(signatures) > 0 {
576-
return nil
577-
}
570+
signatures, _, err := verifier.VerifyImageSignatures(ref)
571+
if err != nil {
572+
return err
578573
}
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)
580580
}
581581

582582
return nil
@@ -980,8 +980,7 @@ func (r *OCIRepositoryReconciler) garbageCollect(ctx context.Context, obj *sourc
980980
// that this is a simple log. While the debug log contains complete details
981981
// about the event.
982982
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{}) {
985984
msg := fmt.Sprintf(messageFmt, args...)
986985
// Log and emit event.
987986
if eventType == corev1.EventTypeWarning {

0 commit comments

Comments
 (0)