@@ -26,6 +26,7 @@ Options:
26
26
-i, --identity <identity_file> Identity key file
27
27
-p, --pubkey <pub_key_file> Public key file
28
28
-P, --port <port> SSH port for target node SSH server (default:22)
29
+ -a, --args <args> Args to exec in ssh session
29
30
--skip-agent Skip automatically starting SSH agent and adding
30
31
SSH Identity key into the agent before SSH login
31
32
(=> You need to manage SSH agent by yourself)
@@ -56,6 +57,7 @@ write_options(){
56
57
cat << EOF > ${PLUGIN_SSH_OPTIONS_FILE}
57
58
sshuser=${sshuser}
58
59
identity=${identity}
60
+
59
61
pubkey=${pubkey}
60
62
port=${port}
61
63
EOF
@@ -112,9 +114,10 @@ run_ssh_node(){
112
114
local identity=" $3 "
113
115
local pubkey=" $4 "
114
116
local port=" $5 "
117
+ local sshargs=" $6 "
115
118
116
119
# 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}' ) #
118
121
if [ " ${r} " != " sshjump" ]; then
119
122
echo " Creating SSH jump host (Pod)..."
120
123
kubectl run sshjump --image=corbinu/ssh-server --port=22 --restart=Never
@@ -140,71 +143,61 @@ run_ssh_node(){
140
143
# Using the SSH Server as a jumphost (via port-forward proxy), ssh into the desired Node
141
144
ssh -i ${identity} -p ${port} ${sshuser} @${destnode} \
142
145
-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
144
147
145
148
# Stop port-forward
146
149
kill -3 ${pid_port_forward} 2> /dev/null
147
150
}
148
151
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
208
201
done
209
202
210
203
if [[ " $( type kubectl & > /dev/null; echo $? ) " -eq 1 ]]; then
@@ -256,14 +249,18 @@ plugin_main(){
256
249
c_port=" ${port} "
257
250
fi
258
251
252
+ if [ " ${sshargs} " != " " ]; then
253
+ echo " using: args=$sshargs "
254
+ fi
255
+
259
256
# Caching current ssh options
260
257
write_options ${c_sshuser} ${c_identity} ${c_pubkey} ${c_port}
261
258
262
259
if [ " ${skip_agent} " = " no" ]; then
263
260
check_and_start_agent ${c_identity}
264
261
fi
265
262
# 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} "
267
264
268
265
# Cleaning up resources if needed
269
266
if [ " ${cleanup_jump} " = " yes" ]; then
0 commit comments