@@ -24,11 +24,11 @@ import (
24
24
"net/http"
25
25
"os"
26
26
"os/exec"
27
- "path"
28
27
"path/filepath"
29
28
"strings"
30
29
"time"
31
30
31
+ securejoin "github.com/cyphar/filepath-securejoin"
32
32
"github.com/go-logr/logr"
33
33
corev1 "k8s.io/api/core/v1"
34
34
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -306,8 +306,16 @@ func (r *KustomizationReconciler) reconcile(
306
306
), err
307
307
}
308
308
309
- dirPath := path .Join (tmpDir , kustomization .Spec .Path )
310
309
// check build path exists
310
+ dirPath , err := securejoin .SecureJoin (tmpDir , kustomization .Spec .Path )
311
+ if err != nil {
312
+ return kustomizev1 .KustomizationNotReady (
313
+ kustomization ,
314
+ source .GetArtifact ().Revision ,
315
+ kustomizev1 .ArtifactFailedReason ,
316
+ err .Error (),
317
+ ), err
318
+ }
311
319
if _ , err := os .Stat (dirPath ); err != nil {
312
320
err = fmt .Errorf ("kustomization path not found: %w" , err )
313
321
return kustomizev1 .KustomizationNotReady (
@@ -606,12 +614,15 @@ func (r *KustomizationReconciler) writeKubeConfig(kustomization kustomizev1.Kust
606
614
return "" , err
607
615
}
608
616
609
- kubeConfigPath := path .Join (dirPath , secretName .Name )
610
- if err := ioutil .WriteFile (kubeConfigPath , kubeConfig , os .ModePerm ); err != nil {
617
+ f , err := ioutil .TempFile (dirPath , "kubeconfig" )
618
+ defer f .Close ()
619
+ if err != nil {
611
620
return "" , fmt .Errorf ("unable to write KubeConfig secret '%s' to storage: %w" , secretName .String (), err )
612
621
}
613
-
614
- return secretName .Name , nil
622
+ if _ , err := f .Write (kubeConfig ); err != nil {
623
+ return "" , fmt .Errorf ("unable to write KubeConfig secret '%s' to storage: %w" , secretName .String (), err )
624
+ }
625
+ return f .Name (), nil
615
626
}
616
627
617
628
func (r * KustomizationReconciler ) getKubeConfig (kustomization kustomizev1.Kustomization ) ([]byte , error ) {
0 commit comments