@@ -26,6 +26,7 @@ Options:
2626 -i, --identity <identity_file> Identity key file
2727 -p, --pubkey <pub_key_file> Public key file
2828 -P, --port <port> SSH port for target node SSH server (default:22)
29+ -a, --args <args> Args to exec in ssh session
2930 --skip-agent Skip automatically starting SSH agent and adding
3031 SSH Identity key into the agent before SSH login
3132 (=> You need to manage SSH agent by yourself)
@@ -56,6 +57,7 @@ write_options(){
5657 cat << EOF > ${PLUGIN_SSH_OPTIONS_FILE}
5758sshuser=${sshuser}
5859identity=${identity}
60+
5961pubkey=${pubkey}
6062port=${port}
6163EOF
@@ -112,9 +114,10 @@ run_ssh_node(){
112114 local identity=" $3 "
113115 local pubkey=" $4 "
114116 local port=" $5 "
117+ local sshargs=" $6 "
115118
116119 # Install an SSH Server if not yet installed
117- r=$( kubectl get pod sshjump 2> /dev/null | tail -1 | awk ' {print $1}' )
120+ r=$( kubectl get pod sshjump 2> /dev/null | tail -1 | awk ' {print $1}' ) #
118121 if [ " ${r} " != " sshjump" ]; then
119122 echo " Creating SSH jump host (Pod)..."
120123 kubectl run sshjump --image=corbinu/ssh-server --port=22 --restart=Never
@@ -140,71 +143,61 @@ run_ssh_node(){
140143 # Using the SSH Server as a jumphost (via port-forward proxy), ssh into the desired Node
141144 ssh -i ${identity} -p ${port} ${sshuser} @${destnode} \
142145 -o " ProxyCommand ssh root@127.0.0.1 -p 2222 -i ${identity} -o \" StrictHostKeyChecking=no\" \" nc %h %p\" " \
143- -o " StrictHostKeyChecking=no"
146+ -o " StrictHostKeyChecking=no" $sshargs
144147
145148 # Stop port-forward
146149 kill -3 ${pid_port_forward} 2> /dev/null
147150}
148151
149- plugin_main (){
150- skip_agent=" no"
151- cleanup_jump=" no"
152- cleanup_agent=" no"
153-
154- for arg in " $@ " ; do
155- option=" "
156- if [ " ${arg: 0: 1} " = " -" ]; then
157- if [ " ${arg: 1: 1} " = " -" ]; then
158- option=" ${arg: 2} "
159- prevopt=" ${arg: 2} "
160- else
161- index=1
162- while o=" ${arg: $index : 1} " ; do
163- [ -n " $o " ] || break
164- option=" $o "
165- prevopt=" $o "
166- let index+=1
167- done
168- fi
169- case " ${option} " in
170- " h" | " help" )
171- help
172- exit 0
173- ;;
174- " cleanup-jump" )
175- cleanup_jump=" yes"
176- ;;
177- " cleanup-agent" )
178- cleanup_agent=" yes"
179- ;;
180- " skip-agent" )
181- skip_agent=" yes"
182- ;;
183- esac
184- else
185- if [ " ${prevopt} " = " " ]; then
186- destnode=" ${arg} "
187- else
188- case " ${prevopt} " in
189- " u" | " user" )
190- c_sshuser=" ${arg} "
191- ;;
192- " i" | " identity" )
193- c_identity=" ${arg} "
194- ;;
195- " p" | " pubkey" )
196- c_pubkey=" ${arg} "
197- ;;
198- " P" | " port" )
199- c_port=" ${arg} "
200- ;;
201- * )
202- help >&2
203- exit 1
204- ;;
205- esac
206- fi
207- fi
152+ plugin_main () {
153+ skip_agent=no
154+ cleanup_jump=no
155+ cleanup_agent=no
156+ while [ $# -gt 0 ] ; do
157+ nSkip=1
158+ case $1 in
159+ " -h" | " --help" )
160+ help
161+ exit 0
162+ ;;
163+ " --cleanup-jump" )
164+ cleanup_jump=yes
165+ ;;
166+ " --cleanup-agent" )
167+ cleanup_agent=yes
168+ ;;
169+ " --skip-agent" )
170+ skip_agent=yes
171+ ;;
172+ " -u" | " --user" )
173+ c_sshuser=$2
174+ nSkip=2
175+ ;;
176+ " -i" | " --identity" )
177+ c_identity=$2
178+ nSkip=2
179+ ;;
180+ " -p" | " --pubkey" )
181+ c_pubkey=$2
182+ nSkip=2
183+ ;;
184+ " -P" | " --port" )
185+ c_port=$2
186+ nSkip=2
187+ ;;
188+ " -a" | " --args" )
189+ sshargs=" $2 "
190+ nSkRip=2
191+ ;;
192+ [a-z]* )
193+ destnode=$1
194+ ;;
195+ * )
196+ help >&2
197+ exit 1
198+ ;;
199+ esac
200+ shift $nSkip
208201 done
209202
210203 if [[ " $( type kubectl & > /dev/null; echo $? ) " -eq 1 ]]; then
@@ -256,14 +249,18 @@ plugin_main(){
256249 c_port=" ${port} "
257250 fi
258251
252+ if [ " ${sshargs} " != " " ]; then
253+ echo " using: args=$sshargs "
254+ fi
255+
259256 # Caching current ssh options
260257 write_options ${c_sshuser} ${c_identity} ${c_pubkey} ${c_port}
261258
262259 if [ " ${skip_agent} " = " no" ]; then
263260 check_and_start_agent ${c_identity}
264261 fi
265262 # SSH Logging into desitnation node via Jump host
266- run_ssh_node ${destnode} ${c_sshuser} ${c_identity} ${c_pubkey} ${c_port}
263+ run_ssh_node ${destnode} ${c_sshuser} ${c_identity} ${c_pubkey} ${c_port} " ${sshargs} "
267264
268265 # Cleaning up resources if needed
269266 if [ " ${cleanup_jump} " = " yes" ]; then
0 commit comments