@@ -31,6 +31,7 @@ import (
31
31
authutils "github.com/fluxcd/pkg/auth/utils"
32
32
"github.com/fluxcd/pkg/git/github"
33
33
"github.com/fluxcd/pkg/runtime/logger"
34
+ "github.com/fluxcd/pkg/runtime/secrets"
34
35
"github.com/go-git/go-git/v5/plumbing/transport"
35
36
corev1 "k8s.io/api/core/v1"
36
37
"k8s.io/apimachinery/pkg/runtime"
@@ -621,10 +622,11 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
621
622
// transport.ProxyOptions object using those settings and then returns it.
622
623
func (r * GitRepositoryReconciler ) getProxyOpts (ctx context.Context , proxySecretName ,
623
624
proxySecretNamespace string ) (* transport.ProxyOptions , * url.URL , error ) {
624
- proxyData , err := r .getSecretData (ctx , proxySecretName , proxySecretNamespace )
625
+ secret , err := r .getSecret (ctx , proxySecretName , proxySecretNamespace )
625
626
if err != nil {
626
627
return nil , nil , fmt .Errorf ("failed to get proxy secret '%s/%s': %w" , proxySecretNamespace , proxySecretName , err )
627
628
}
629
+ proxyData := secret .Data
628
630
b , ok := proxyData ["address" ]
629
631
if ! ok {
630
632
return nil , nil , fmt .Errorf ("invalid proxy secret '%s/%s': key 'address' is missing" , proxySecretNamespace , proxySecretName )
@@ -659,10 +661,11 @@ func (r *GitRepositoryReconciler) getProxyOpts(ctx context.Context, proxySecretN
659
661
// URL and returns it.
660
662
func (r * GitRepositoryReconciler ) getAuthOpts (ctx context.Context , obj * sourcev1.GitRepository ,
661
663
u url.URL , proxyURL * url.URL ) (* git.AuthOptions , error ) {
664
+ var secret * corev1.Secret
662
665
var authData map [string ][]byte
663
666
if obj .Spec .SecretRef != nil {
664
667
var err error
665
- authData , err = r .getSecretData (ctx , obj .Spec .SecretRef .Name , obj .GetNamespace ())
668
+ secret , err = r .getSecret (ctx , obj .Spec .SecretRef .Name , obj .GetNamespace ())
666
669
if err != nil {
667
670
e := serror .NewGeneric (
668
671
fmt .Errorf ("failed to get secret '%s/%s': %w" , obj .GetNamespace (), obj .Spec .SecretRef .Name , err ),
@@ -671,6 +674,7 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
671
674
conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , "%s" , e )
672
675
return nil , e
673
676
}
677
+ authData = secret .Data
674
678
}
675
679
676
680
// Configure authentication strategy to access the source
@@ -719,22 +723,36 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
719
723
}
720
724
721
725
getCreds = func () (* authutils.GitCredentials , error ) {
722
- var opts []github.OptFunc
726
+ var appOpts []github.OptFunc
723
727
724
728
if len (authData ) > 0 {
725
- opts = append (opts , github .WithAppData (authData ))
729
+ appOpts = append (appOpts , github .WithAppData (authData ))
726
730
}
727
731
728
732
if proxyURL != nil {
729
- opts = append (opts , github .WithProxyURL (proxyURL ))
733
+ appOpts = append (appOpts , github .WithProxyURL (proxyURL ))
730
734
}
731
735
732
736
if r .TokenCache != nil {
733
- opts = append (opts , github .WithCache (r .TokenCache , sourcev1 .GitRepositoryKind ,
737
+ appOpts = append (appOpts , github .WithCache (r .TokenCache , sourcev1 .GitRepositoryKind ,
734
738
obj .GetName (), obj .GetNamespace (), cache .OperationReconcile ))
735
739
}
736
740
737
- username , password , err := github .GetCredentials (ctx , opts ... )
741
+ if len (opts .CAFile ) > 0 {
742
+ targetURL := fmt .Sprintf ("%s://%s" , u .Scheme , u .Host )
743
+ tlsConfig , err := secrets .TLSConfigFromSecret (ctx , secret , targetURL , secrets .WithSystemCertPool ())
744
+ if err != nil {
745
+ e := serror .NewStalling (
746
+ fmt .Errorf ("failed to configure TLS from secret '%s/%s': %w" , obj .GetNamespace (), obj .Spec .SecretRef .Name , err ),
747
+ sourcev1 .AuthenticationFailedReason ,
748
+ )
749
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , "%s" , e )
750
+ return nil , e
751
+ }
752
+ appOpts = append (appOpts , github .WithTLSConfig (tlsConfig ))
753
+ }
754
+
755
+ username , password , err := github .GetCredentials (ctx , appOpts ... )
738
756
if err != nil {
739
757
return nil , err
740
758
}
@@ -771,16 +789,16 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
771
789
return opts , nil
772
790
}
773
791
774
- func (r * GitRepositoryReconciler ) getSecretData (ctx context.Context , name , namespace string ) (map [ string ][] byte , error ) {
792
+ func (r * GitRepositoryReconciler ) getSecret (ctx context.Context , name , namespace string ) (* corev1. Secret , error ) {
775
793
key := types.NamespacedName {
776
794
Namespace : namespace ,
777
795
Name : name ,
778
796
}
779
- var secret corev1.Secret
780
- if err := r .Client .Get (ctx , key , & secret ); err != nil {
781
- return nil , err
797
+ secret := & corev1.Secret {}
798
+ if err := r .Client .Get (ctx , key , secret ); err != nil {
799
+ return nil , fmt . Errorf ( "failed to get secret '%s/%s': %w" , namespace , name , err )
782
800
}
783
- return secret . Data , nil
801
+ return secret , nil
784
802
}
785
803
786
804
// reconcileArtifact archives a new Artifact to the Storage, if the current
0 commit comments