@@ -18,6 +18,7 @@ package controller
18
18
19
19
import (
20
20
"context"
21
+ stdtls "crypto/tls"
21
22
"errors"
22
23
"fmt"
23
24
"os"
@@ -57,6 +58,7 @@ import (
57
58
"github.com/fluxcd/source-controller/internal/index"
58
59
sreconcile "github.com/fluxcd/source-controller/internal/reconcile"
59
60
"github.com/fluxcd/source-controller/internal/reconcile/summarize"
61
+ "github.com/fluxcd/source-controller/internal/tls"
60
62
"github.com/fluxcd/source-controller/pkg/azure"
61
63
"github.com/fluxcd/source-controller/pkg/gcp"
62
64
"github.com/fluxcd/source-controller/pkg/minio"
@@ -421,14 +423,33 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, sp *patch.Seria
421
423
// the provider. If this fails, it records v1beta2.FetchFailedCondition=True on
422
424
// the object and returns early.
423
425
func (r * BucketReconciler ) reconcileSource (ctx context.Context , sp * patch.SerialPatcher , obj * bucketv1.Bucket , index * index.Digester , dir string ) (sreconcile.Result , error ) {
424
- secret , err := r .getBucketSecret (ctx , obj )
426
+ objNamespace := obj .GetNamespace ()
427
+
428
+ secret , err := r .getSecret (ctx , obj .Spec .SecretRef , objNamespace )
425
429
if err != nil {
426
430
e := serror .NewGeneric (err , sourcev1 .AuthenticationFailedReason )
427
431
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
428
432
// Return error as the world as observed may change
429
433
return sreconcile .ResultEmpty , e
430
434
}
431
435
436
+ // Fetch and validate certificate secret if specified on the object.
437
+ certSecret , err := r .getSecret (ctx , obj .Spec .CertSecretRef , objNamespace )
438
+ if err != nil {
439
+ e := serror .NewGeneric (err , sourcev1 .CertificateFailedReason )
440
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
441
+ return sreconcile .ResultEmpty , e
442
+ }
443
+ var tlsConfig * stdtls.Config
444
+ if certSecret != nil {
445
+ tlsConfig , _ , err = tls .KubeTLSClientConfigFromSecret (* certSecret , obj .Spec .Endpoint )
446
+ if err != nil {
447
+ e := serror .NewGeneric (err , sourcev1 .CertificateFailedReason )
448
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
449
+ return sreconcile .ResultEmpty , e
450
+ }
451
+ }
452
+
432
453
// Construct provider client
433
454
var provider BucketProvider
434
455
switch obj .Spec .Provider {
@@ -460,7 +481,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
460
481
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
461
482
return sreconcile .ResultEmpty , e
462
483
}
463
- if provider , err = minio .NewClient (obj , secret ); err != nil {
484
+ if provider , err = minio .NewClient (obj , secret , tlsConfig ); err != nil {
464
485
e := serror .NewGeneric (err , "ClientError" )
465
486
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Error ())
466
487
return sreconcile .ResultEmpty , e
@@ -663,15 +684,15 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *bucketv1.Buc
663
684
return nil
664
685
}
665
686
666
- // getBucketSecret attempts to fetch the Secret reference if specified on the
667
- // obj. It returns any client error.
668
- func ( r * BucketReconciler ) getBucketSecret ( ctx context. Context , obj * bucketv1. Bucket ) (* corev1.Secret , error ) {
669
- if obj . Spec . SecretRef == nil {
687
+ // getSecret attempts to fetch a Secret reference if specified. It returns any client error.
688
+ func ( r * BucketReconciler ) getSecret ( ctx context. Context , secretRef * meta. LocalObjectReference ,
689
+ namespace string ) (* corev1.Secret , error ) {
690
+ if secretRef == nil {
670
691
return nil , nil
671
692
}
672
693
secretName := types.NamespacedName {
673
- Namespace : obj . GetNamespace () ,
674
- Name : obj . Spec . SecretRef .Name ,
694
+ Namespace : namespace ,
695
+ Name : secretRef .Name ,
675
696
}
676
697
secret := & corev1.Secret {}
677
698
if err := r .Get (ctx , secretName , secret ); err != nil {
0 commit comments