@@ -18,6 +18,7 @@ package controllers
1818
1919import (
2020 "context"
21+ "crypto/tls"
2122 "errors"
2223 "fmt"
2324 "net/url"
@@ -368,6 +369,7 @@ func (r *HelmChartReconciler) reconcileSource(ctx context.Context, obj *sourcev1
368369
369370func (r * HelmChartReconciler ) buildFromHelmRepository (ctx context.Context , obj * sourcev1.HelmChart ,
370371 repo * sourcev1.HelmRepository , b * chart.Build ) (sreconcile.Result , error ) {
372+ var tlsConfig * tls.Config
371373
372374 // Construct the Getter options from the HelmRepository data
373375 clientOpts := []helmgetter.Option {
@@ -386,34 +388,33 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
386388 return sreconcile .ResultEmpty , e
387389 }
388390
389- // Create temporary working directory for credentials
390- authDir , err := util . TempDirForObj ( "" , obj )
391+ // Build client options from secret
392+ opts , err := getter . ClientOptionsFromSecret ( * secret )
391393 if err != nil {
392394 e := & serror.Event {
393- Err : fmt .Errorf ("failed to create temporary working directory : %w" , err ),
394- Reason : sourcev1 .StorageOperationFailedReason ,
395+ Err : fmt .Errorf ("failed to configure Helm client with secret data : %w" , err ),
396+ Reason : sourcev1 .AuthenticationFailedReason ,
395397 }
396- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 .StorageOperationFailedReason , e .Err .Error ())
398+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 .AuthenticationFailedReason , e .Err .Error ())
399+ // Requeue as content of secret might change
397400 return sreconcile .ResultEmpty , e
398401 }
399- defer os . RemoveAll ( authDir )
402+ clientOpts = append ( clientOpts , opts ... )
400403
401- // Build client options from secret
402- opts , err := getter .ClientOptionsFromSecret (authDir , * secret )
404+ tlsConfig , err = getter .TLSClientConfigFromSecret (* secret , repo .Spec .URL )
403405 if err != nil {
404406 e := & serror.Event {
405- Err : fmt .Errorf ("failed to configure Helm client with secret data: %w" , err ),
407+ Err : fmt .Errorf ("failed to create tls client config with secret data: %w" , err ),
406408 Reason : sourcev1 .AuthenticationFailedReason ,
407409 }
408410 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 .AuthenticationFailedReason , e .Err .Error ())
409411 // Requeue as content of secret might change
410412 return sreconcile .ResultEmpty , e
411413 }
412- clientOpts = append (clientOpts , opts ... )
413414 }
414415
415416 // Initialize the chart repository
416- chartRepo , err := repository .NewChartRepository (repo .Spec .URL , r .Storage .LocalPath (* repo .GetArtifact ()), r .Getters , clientOpts )
417+ chartRepo , err := repository .NewChartRepository (repo .Spec .URL , r .Storage .LocalPath (* repo .GetArtifact ()), r .Getters , tlsConfig , clientOpts )
417418 if err != nil {
418419 // Any error requires a change in generation,
419420 // which we should be informed about by the watcher
@@ -523,15 +524,8 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj
523524 }
524525
525526 // Setup dependency manager
526- authDir := filepath .Join (tmpDir , "creds" )
527- if err = os .Mkdir (authDir , 0700 ); err != nil {
528- return sreconcile .ResultEmpty , & serror.Event {
529- Err : fmt .Errorf ("failed to create temporary directory for dependency credentials: %w" , err ),
530- Reason : meta .FailedReason ,
531- }
532- }
533527 dm := chart .NewDependencyManager (
534- chart .WithRepositoryCallback (r .namespacedChartRepositoryCallback (ctx , authDir , obj .GetNamespace ())),
528+ chart .WithRepositoryCallback (r .namespacedChartRepositoryCallback (ctx , obj .GetNamespace ())),
535529 )
536530 defer dm .Clear ()
537531
@@ -747,11 +741,11 @@ func (r *HelmChartReconciler) garbageCollect(ctx context.Context, obj *sourcev1.
747741}
748742
749743// namespacedChartRepositoryCallback returns a chart.GetChartRepositoryCallback scoped to the given namespace.
750- // Credentials for retrieved v1beta1.HelmRepository objects are stored in the given directory.
751744// The returned callback returns a repository.ChartRepository configured with the retrieved v1beta1.HelmRepository,
752745// or a shim with defaults if no object could be found.
753- func (r * HelmChartReconciler ) namespacedChartRepositoryCallback (ctx context.Context , dir , namespace string ) chart.GetChartRepositoryCallback {
746+ func (r * HelmChartReconciler ) namespacedChartRepositoryCallback (ctx context.Context , namespace string ) chart.GetChartRepositoryCallback {
754747 return func (url string ) (* repository.ChartRepository , error ) {
748+ var tlsConfig * tls.Config
755749 repo , err := r .resolveDependencyRepository (ctx , url , namespace )
756750 if err != nil {
757751 // Return Kubernetes client errors, but ignore others
@@ -774,13 +768,19 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
774768 if err != nil {
775769 return nil , err
776770 }
777- opts , err := getter .ClientOptionsFromSecret (dir , * secret )
771+ opts , err := getter .ClientOptionsFromSecret (* secret )
778772 if err != nil {
779773 return nil , err
780774 }
781775 clientOpts = append (clientOpts , opts ... )
776+
777+ tlsConfig , err = getter .TLSClientConfigFromSecret (* secret , repo .Spec .URL )
778+ if err != nil {
779+ return nil , fmt .Errorf ("failed to create tls client config for HelmRepository '%s': %w" , repo .Name , err )
780+ }
782781 }
783- chartRepo , err := repository .NewChartRepository (repo .Spec .URL , "" , r .Getters , clientOpts )
782+
783+ chartRepo , err := repository .NewChartRepository (repo .Spec .URL , "" , r .Getters , tlsConfig , clientOpts )
784784 if err != nil {
785785 return nil , err
786786 }
0 commit comments