@@ -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,35 @@ 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
+ tlsConfig , err := secrets .TLSConfigFromSecret (ctx , secret , u .Host , secrets .WithSystemCertPool ())
743
+ if err != nil {
744
+ e := serror .NewStalling (
745
+ fmt .Errorf ("failed to configure TLS from secret '%s/%s': %w" , obj .GetNamespace (), obj .Spec .SecretRef .Name , err ),
746
+ sourcev1 .AuthenticationFailedReason ,
747
+ )
748
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , "%s" , e )
749
+ return nil , e
750
+ }
751
+ appOpts = append (appOpts , github .WithTLSConfig (tlsConfig ))
752
+ }
753
+
754
+ username , password , err := github .GetCredentials (ctx , appOpts ... )
738
755
if err != nil {
739
756
return nil , err
740
757
}
@@ -771,16 +788,16 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
771
788
return opts , nil
772
789
}
773
790
774
- func (r * GitRepositoryReconciler ) getSecretData (ctx context.Context , name , namespace string ) (map [ string ][] byte , error ) {
791
+ func (r * GitRepositoryReconciler ) getSecret (ctx context.Context , name , namespace string ) (* corev1. Secret , error ) {
775
792
key := types.NamespacedName {
776
793
Namespace : namespace ,
777
794
Name : name ,
778
795
}
779
- var secret corev1.Secret
780
- if err := r .Client .Get (ctx , key , & secret ); err != nil {
781
- return nil , err
796
+ secret := & corev1.Secret {}
797
+ if err := r .Client .Get (ctx , key , secret ); err != nil {
798
+ return nil , fmt . Errorf ( "failed to get secret '%s/%s': %w" , namespace , name , err )
782
799
}
783
- return secret . Data , nil
800
+ return secret , nil
784
801
}
785
802
786
803
// reconcileArtifact archives a new Artifact to the Storage, if the current
0 commit comments