Skip to content

Commit d7a0dea

Browse files
committed
Write KubeConfig to tmp file in working dir
Instead of using the name of the secret, as this can cause unexpected collisions in edge case scenarios. Signed-off-by: Hidde Beydals <[email protected]>
1 parent 69a7e75 commit d7a0dea

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

controllers/kustomization_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,15 @@ func (r *KustomizationReconciler) writeKubeConfig(kustomization kustomizev1.Kust
614614
return "", err
615615
}
616616

617-
kubeConfigPath, err := securejoin.SecureJoin(dirPath, secretName.Name)
617+
f, err := ioutil.TempFile(dirPath, "kubeconfig")
618+
defer f.Close()
618619
if err != nil {
619-
return "", err
620+
return "", fmt.Errorf("unable to write KubeConfig secret '%s' to storage: %w", secretName.String(), err)
620621
}
621-
if err := ioutil.WriteFile(kubeConfigPath, kubeConfig, os.ModePerm); err != nil {
622+
if _, err := f.Write(kubeConfig); err != nil {
622623
return "", fmt.Errorf("unable to write KubeConfig secret '%s' to storage: %w", secretName.String(), err)
623624
}
624-
625-
return kubeConfigPath, nil
625+
return f.Name(), nil
626626
}
627627

628628
func (r *KustomizationReconciler) getKubeConfig(kustomization kustomizev1.Kustomization) ([]byte, error) {

0 commit comments

Comments
 (0)