Skip to content

Commit 6064af2

Browse files
authored
Merge pull request #815 from github/hao/default-port-to-122
Always default port to 122
2 parents d792b23 + 7d1db1a commit 6064af2

File tree

6 files changed

+20
-44
lines changed

6 files changed

+20
-44
lines changed

bin/ghe-host-check

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,8 @@ options="
5252
port=$(ssh_port_part "$host")
5353
hostname=$(ssh_host_part "$host")
5454

55-
set +e
55+
# ghe-negotiate-version verifies if the target is a Github Enterprise Server instance
5656
output=$(echo "ghe-negotiate-version backup-utils $BACKUP_UTILS_VERSION" | ghe-ssh -o BatchMode=no $options $host -- /bin/sh 2>&1)
57-
rc=$?
58-
set -e
59-
60-
if [ $rc -ne 0 ]; then
61-
case $rc in
62-
255)
63-
if echo "$output" | grep -i "port 22: Network is unreachable\|port 22: connection refused\|port 22: no route to host\|ssh_exchange_identification: Connection closed by remote host\|Connection timed out during banner exchange\|port 22: Connection timed out" >/dev/null; then
64-
exec "$(basename $0)" "$hostname:122"
65-
fi
66-
67-
echo "$output" 1>&2
68-
echo "Error: ssh connection with '$host' failed" 1>&2
69-
echo "Note that your SSH key needs to be setup on $host as described in:" 1>&2
70-
echo "* https://enterprise.github.com/help/articles/adding-an-ssh-key-for-shell-access" 1>&2
71-
;;
72-
101)
73-
echo "Error: couldn't read GitHub Enterprise Server fingerprint on '$host' or this isn't a GitHub appliance." 1>&2
74-
;;
75-
1)
76-
if [ "${port:-22}" -eq 22 ] && echo "$output" | grep "use port 122" >/dev/null; then
77-
exec "$(basename $0)" "$hostname:122"
78-
else
79-
echo "$output" 1>&2
80-
fi
81-
;;
82-
83-
esac
84-
exit $rc
85-
fi
8657

8758
CLUSTER=false
8859
if ghe-ssh "$host" -- \

share/github-backup-utils/ghe-backup-config

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ ssh_host_part() {
334334
# This is used primarily to break hostspecs with non-standard ports down for
335335
# rsync commands.
336336
ssh_port_part() {
337-
[ "${1##*:}" = "$1" ] && echo 22 || echo "${1##*:}"
337+
if [ "${1##*:}" != "$1" ] && [ "${1##*:}" -ne "122" ]; then
338+
echo "Error: SSH port has to be 122 connecting to Github Enterprise Server, current value is ${1##*:} for $1." 1>&2
339+
exit 1
340+
fi
341+
342+
echo 122
338343
}
339344

340345
# Usage: ghe_remote_logger <message>...

test/test-ghe-backup-config.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ end_test
8989
begin_test "ghe-backup-config ssh_port_part"
9090
(
9191
set -e
92-
[ "$(ssh_port_part 'github.example.com')" = "22" ]
93-
[ "$(ssh_port_part 'github.example.com:22')" = "22" ]
94-
[ "$(ssh_port_part 'github.example.com:5000')" = "5000" ]
95-
[ "$(ssh_port_part '[email protected]:5000')" = "5000" ]
92+
[ "$(ssh_port_part 'github.example.com')" = "122" ]
93+
[ ! "$(ssh_port_part 'github.example.com:22' 2>/dev/null)" ]
94+
[ ! "$(ssh_port_part 'github.example.com:5000' 2>/dev/null)" ]
95+
[ "$(ssh_port_part '[email protected]:122')" = "122" ]
9696
)
9797
end_test
9898

test/test-ghe-restore-external-database.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ begin_test "ghe-restore allows restore of external DB snapshot to external DB in
6060
fi
6161

6262
# verify connect to right host
63-
check_restore_output_for "Connect 127.0.0.1:22 OK"
63+
check_restore_output_for "Connect 127.0.0.1:122 OK"
6464

6565
# verify stale servers were cleared
6666
check_restore_output_for "Cleaning up stale nodes ..."
@@ -156,7 +156,7 @@ begin_test "ghe-restore allows restore of external DB snapshot to non-external D
156156
check_restore_output_for "Skipping MySQL restore."
157157

158158
# verify connect to right host
159-
check_restore_output_for "Connect 127.0.0.1:22 OK"
159+
check_restore_output_for "Connect 127.0.0.1:122 OK"
160160

161161
# verify stale servers were cleared
162162
check_restore_output_for "Cleaning up stale nodes ..."
@@ -182,7 +182,7 @@ begin_test "ghe-restore allows restore of non external DB snapshot to external D
182182
check_restore_output_for "Skipping MySQL restore."
183183

184184
# verify connect to right host
185-
check_restore_output_for "Connect 127.0.0.1:22 OK"
185+
check_restore_output_for "Connect 127.0.0.1:122 OK"
186186

187187
# verify stale servers were cleared
188188
check_restore_output_for "Cleaning up stale nodes ..."

test/test-ghe-restore.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ begin_test "ghe-restore into configured vm"
5656
cat "$TRASHDIR/restore-out"
5757

5858
# verify connect to right host
59-
grep -q "Connect 127.0.0.1:22 OK" "$TRASHDIR/restore-out"
59+
grep -q "Connect 127.0.0.1:122 OK" "$TRASHDIR/restore-out"
6060

6161
# verify stale servers were cleared
6262
grep -q "Cleaning up stale nodes ..." "$TRASHDIR/restore-out"
@@ -141,7 +141,7 @@ begin_test "ghe-restore -c into unconfigured vm"
141141
fi
142142

143143
# verify connect to right host
144-
grep -q "Connect 127.0.0.1:22 OK" "$TRASHDIR/restore-out"
144+
grep -q "Connect 127.0.0.1:122 OK" "$TRASHDIR/restore-out"
145145

146146
# verify attempt to clear stale servers was not made
147147
grep -q "Cleaning up stale nodes ..." "$TRASHDIR/restore-out" && {
@@ -175,7 +175,7 @@ begin_test "ghe-restore into unconfigured vm"
175175
! grep -q "ghe-config-apply OK" "$TRASHDIR/restore-out"
176176

177177
# verify connect to right host
178-
grep -q "Connect 127.0.0.1:22 OK" "$TRASHDIR/restore-out"
178+
grep -q "Connect 127.0.0.1:122 OK" "$TRASHDIR/restore-out"
179179

180180
# verify attempt to clear stale servers was not made
181181
grep -q "Cleaning up stale nodes ..." "$TRASHDIR/restore-out" && {
@@ -215,7 +215,7 @@ begin_test "ghe-restore with host arg and config value"
215215
rm "$GHE_BACKUP_CONFIG_TEMP"
216216

217217
# verify host arg overrides configured restore host
218-
echo "$output" | grep -q 'Connect localhost:22 OK'
218+
echo "$output" | grep -q 'Connect localhost:122 OK'
219219

220220
# Verify all the data we've restored is as expected
221221
verify_all_restored_data
@@ -239,7 +239,7 @@ begin_test "ghe-restore with host arg"
239239
output="$(ghe-restore -f localhost)" || false
240240

241241
# verify host arg overrides configured restore host
242-
echo "$output" | grep -q 'Connect localhost:22 OK'
242+
echo "$output" | grep -q 'Connect localhost:122 OK'
243243

244244
# Verify all the data we've restored is as expected
245245
verify_all_restored_data

test/test-ghe-ssh-config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ begin_test "ghe-ssh-config returns config for multiple nodes"
2020
# Confirm multiplexing enabled
2121
echo "$output" | grep -q "ControlMaster=auto"
2222
# Confirm ControlPath returns correct hash for admin@host1:122
23-
echo "$output" | grep -q ".ghe-sshmux-84f6bdcf"
23+
echo "$output" | grep -q ".ghe-sshmux-7cb77002"
2424
)
2525
end_test
2626

0 commit comments

Comments
 (0)