Skip to content

Commit 21a6395

Browse files
author
Yoichi Kawasaki
committed
Release: 0.2.0
1 parent 37aaab4 commit 21a6395

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Change Log
2+
3+
All notable changes to the "kubectl-plugin-ssh-jump" extension will be documented in this file.
4+
5+
## 0.2.0
6+
- Added -P|--port options for specifing SSH port that target node is listening (default 22)
7+
- Added -o "StrictHostKeyChecking=no" for ssh login options
8+
- Changed the way to SSH login via SSH Jump Pod from using "-J" to using "ProxyCommand"
9+
10+
11+
## 0.1.0
12+
- Initial release (alpha release)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Options:
9393
-u, --user <sshuser> SSH User name
9494
-i, --identity <identity_file> Identity key file
9595
-p, --pubkey <pub_key_file> Public key file
96+
-P, --port <port> SSH port for target node SSH server (default:22)
9697
--skip-agent Skip automatically starting SSH agent and adding
9798
SSH Identity key into the agent before SSH login
9899
(=> You need to manage SSH agent by yourself)
@@ -105,7 +106,7 @@ Options:
105106
```
106107

107108
#### Option parameters Cache
108-
`username`, `identity`, `pubkey` options are cached, therefore you can omit these options afterward. The options are stored in a file named `$HOME/.kube/kubectlssh/options`
109+
`username`, `identity`, `pubkey`, `port` options are cached, therefore you can omit these options afterward. The options are stored in a file named `$HOME/.kube/kubectlssh/options`
109110
```
110111
$ cat $HOME/.kube/kubectlssh/options
111112
sshuser=azureuser
@@ -135,6 +136,7 @@ Options:
135136
-u, --user <sshuser> SSH User name
136137
-i, --identity <identity_file> Identity key file
137138
-p, --pubkey <pub_key_file> Public key file
139+
-P, --port <port> SSH port for target node SSH server (default:22)
138140
--skip-agent Skip automatically starting SSH agent and adding
139141
SSH Identity key into the agent before SSH login
140142
(=> You need to manage SSH agent by yourself)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.2.0

kubectl-ssh-jump

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SSH_AGENT_PID_FILE="${PLUGIN_DIR}/sshagent-pid"
1313

1414
help(){
1515
echo "Usage: "
16-
echo " kubectl ssh <dest_node> [options]"
16+
echo " kubectl ssh-jump <dest_node> [options]"
1717
echo ""
1818
options
1919
}
@@ -25,6 +25,7 @@ Options:
2525
-u, --user <sshuser> SSH User name
2626
-i, --identity <identity_file> Identity key file
2727
-p, --pubkey <pub_key_file> Public key file
28+
-P, --port <port> SSH port for target node SSH server (default:22)
2829
--skip-agent Skip automatically starting SSH agent and adding
2930
SSH Identity key into the agent before SSH login
3031
(=> You need to manage SSH agent by yourself)
@@ -50,11 +51,13 @@ write_options(){
5051
local sshuser="$1"
5152
local identity="$2"
5253
local pubkey="$3"
54+
local port="$4"
5355

5456
cat << EOF > ${PLUGIN_SSH_OPTIONS_FILE}
5557
sshuser=${sshuser}
5658
identity=${identity}
5759
pubkey=${pubkey}
60+
port=${port}
5861
EOF
5962
}
6063

@@ -108,6 +111,7 @@ run_ssh_node(){
108111
local sshuser="$2"
109112
local identity="$3"
110113
local pubkey="$4"
114+
local port="$5"
111115

112116
# Install an SSH Server if not yet installed
113117
r=$(kubectl get pod sshjump 2>/dev/null | tail -1 | awk '{print $1}')
@@ -134,7 +138,10 @@ run_ssh_node(){
134138
cat ${pubkey} | kubectl exec -i sshjump -- /bin/bash -c "cat >> /root/.ssh/authorized_keys"
135139

136140
# Using the SSH Server as a jumphost (via port-forward proxy), ssh into the desired Node
137-
ssh -i ${identity} -J [email protected]:2222 ${sshuser}@${destnode}
141+
ssh -i ${identity} -p ${port} ${sshuser}@${destnode} \
142+
-o "ProxyCommand ssh [email protected] -p 2222 -i ${identity} -o \"StrictHostKeyChecking=no\" \"nc %h %p\"" \
143+
-o "StrictHostKeyChecking=no"
144+
138145
# Stop port-forward
139146
kill -3 ${pid_port_forward} 2>/dev/null
140147
}
@@ -188,6 +195,9 @@ plugin_main(){
188195
"p" | "pubkey" )
189196
c_pubkey="${arg}"
190197
;;
198+
"P" | "port" )
199+
c_port="${arg}"
200+
;;
191201
* )
192202
help >&2
193203
exit 1
@@ -238,15 +248,22 @@ plugin_main(){
238248
echo "using: pubkey=$pubkey"
239249
c_pubkey="${pubkey}"
240250
fi
251+
if [ ! -n "${c_port}" ]; then
252+
if [ ! -n "${port}" ]; then
253+
port="22" # default: 22
254+
fi
255+
echo "using: port=$port"
256+
c_port="${port}"
257+
fi
241258

242259
# Caching current ssh options
243-
write_options ${c_sshuser} ${c_identity} ${c_pubkey}
260+
write_options ${c_sshuser} ${c_identity} ${c_pubkey} ${c_port}
244261

245262
if [ "${skip_agent}" = "no" ]; then
246263
check_and_start_agent ${c_identity}
247264
fi
248265
# SSH Logging into desitnation node via Jump host
249-
run_ssh_node ${destnode} ${c_sshuser} ${c_identity} ${c_pubkey}
266+
run_ssh_node ${destnode} ${c_sshuser} ${c_identity} ${c_pubkey} ${c_port}
250267

251268
# Cleaning up resources if needed
252269
if [ "${cleanup_jump}" = "yes" ]; then

0 commit comments

Comments
 (0)