File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -121,10 +121,20 @@ setup_git_credentials() {
121121 if [ -n " ${HELM_PLUGIN_USERNAME:- } " ] && [ -n " ${HELM_PLUGIN_PASSWORD:- } " ]; then
122122 debug " Setting up git credentials using Helm-provided username and password"
123123
124+ # Store credentials in local variables before unsetting environment variables
125+ HELM_GIT_USERNAME=" ${HELM_PLUGIN_USERNAME} "
126+ HELM_GIT_PASSWORD=" ${HELM_PLUGIN_PASSWORD} "
127+ export HELM_GIT_USERNAME
128+ export HELM_GIT_PASSWORD
129+
130+ # Unset the original environment variables to prevent them from being passed to child processes
131+ unset HELM_PLUGIN_USERNAME
132+ unset HELM_PLUGIN_PASSWORD
133+
124134 # Mark that credentials are available for git_cmd
125135 export HELM_GIT_USE_CREDENTIALS=" 1"
126136
127- trace " Git credential helper configured with username: ${HELM_PLUGIN_USERNAME } "
137+ trace " Git credential helper configured with username: ${HELM_GIT_USERNAME } "
128138 else
129139 trace " No Helm plugin credentials found, using existing git authentication"
130140 fi
@@ -135,7 +145,7 @@ setup_git_credentials() {
135145git_cmd () {
136146 if [ " ${HELM_GIT_USE_CREDENTIALS:- } " = " 1" ]; then
137147 # shellcheck disable=SC2016
138- GIT_USER=" ${HELM_PLUGIN_USERNAME } " GIT_PASSWORD=" ${HELM_PLUGIN_PASSWORD } " git -c credential.helper=' !f() { echo "username=${GIT_USER}"; echo "password=${GIT_PASSWORD}"; }; f' " $@ "
148+ GIT_USER=" ${HELM_GIT_USERNAME } " GIT_PASSWORD=" ${HELM_GIT_PASSWORD } " git -c credential.helper=' !f() { echo "username=${GIT_USER}"; echo "password=${GIT_PASSWORD}"; }; f' " $@ "
139149 else
140150 git " $@ "
141151 fi
Original file line number Diff line number Diff line change @@ -23,11 +23,17 @@ setup_file() {
2323 # Check that HELM_GIT_USE_CREDENTIALS is set to enable git_cmd wrapper
2424 [[ " $output " == * " HELM_GIT_USE_CREDENTIALS=1" * ]]
2525
26- # Check that the global GIT_USER and GIT_PASSWORD are not set (they should not be exported globally)
27- run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "GIT_USER =${GIT_USER :-unset}" && echo "GIT_PASSWORD =${GIT_PASSWORD :-unset}"'
26+ # Check that the original HELM_PLUGIN_* variables are unset for security
27+ run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "HELM_PLUGIN_USERNAME =${HELM_PLUGIN_USERNAME :-unset}" && echo "HELM_PLUGIN_PASSWORD =${HELM_PLUGIN_PASSWORD :-unset}"'
2828 [ $status = 0 ]
29- [[ " $output " == * " GIT_USER=unset" * ]]
30- [[ " $output " == * " GIT_PASSWORD=unset" * ]]
29+ [[ " $output " == * " HELM_PLUGIN_USERNAME=unset" * ]]
30+ [[ " $output " == * " HELM_PLUGIN_PASSWORD=unset" * ]]
31+
32+ # Check that the internal HELM_GIT_* variables are set
33+ run bash -c ' source "${HELM_GIT_DIRNAME}/helm-git-plugin.sh" && setup_git_credentials && echo "HELM_GIT_USERNAME=${HELM_GIT_USERNAME}" && echo "HELM_GIT_PASSWORD=${HELM_GIT_PASSWORD}"'
34+ [ $status = 0 ]
35+ [[ " $output " == * " HELM_GIT_USERNAME=testuser" * ]]
36+ [[ " $output " == * " HELM_GIT_PASSWORD=testpass" * ]]
3137}
3238
3339@test " should not setup git credentials when HELM_PLUGIN_USERNAME is missing" {
You can’t perform that action at this time.
0 commit comments