@@ -24,11 +24,11 @@ import (
2424 "net/http"
2525 "os"
2626 "os/exec"
27- "path"
2827 "path/filepath"
2928 "strings"
3029 "time"
3130
31+ securejoin "github.com/cyphar/filepath-securejoin"
3232 "github.com/go-logr/logr"
3333 corev1 "k8s.io/api/core/v1"
3434 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -306,8 +306,16 @@ func (r *KustomizationReconciler) reconcile(
306306 ), err
307307 }
308308
309- dirPath := path .Join (tmpDir , kustomization .Spec .Path )
310309 // 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+ }
311319 if _ , err := os .Stat (dirPath ); err != nil {
312320 err = fmt .Errorf ("kustomization path not found: %w" , err )
313321 return kustomizev1 .KustomizationNotReady (
@@ -606,12 +614,15 @@ func (r *KustomizationReconciler) writeKubeConfig(kustomization kustomizev1.Kust
606614 return "" , err
607615 }
608616
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 {
611620 return "" , fmt .Errorf ("unable to write KubeConfig secret '%s' to storage: %w" , secretName .String (), err )
612621 }
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
615626}
616627
617628func (r * KustomizationReconciler ) getKubeConfig (kustomization kustomizev1.Kustomization ) ([]byte , error ) {
0 commit comments