Skip to content

Commit 051149b

Browse files
authored
Merge pull request #420 from github/lildude/prevent-restore-to-older
Prevent restoring snapshots to older releases
2 parents b4babf0 + d0a7464 commit 051149b

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

bin/ghe-host-check

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ if [ -z "$version" ]; then
9191
exit 2
9292
fi
9393

94+
# Block restoring snapshots to older releases of GitHub Enterprise
95+
if [ -n "$GHE_RESTORE_SNAPSHOT_PATH" ]; then
96+
snapshot_version=$(cat $GHE_RESTORE_SNAPSHOT_PATH/version)
97+
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
98+
read -r snapshot_version_major snapshot_version_minor _ <<<$(ghe_parse_version $snapshot_version)
99+
if [ "$(version $GHE_REMOTE_VERSION)" -lt "$(version $snapshot_version_major.$snapshot_version_minor.0)" ]; then
100+
echo "Error: Snapshot can not be restored to an older release of GitHub Enterprise." >&2
101+
exit 1
102+
fi
103+
fi
104+
94105
if [ -z "$GHE_ALLOW_REPLICA_BACKUP" ]; then
95106
if [ "$(ghe-ssh $host -- cat $GHE_REMOTE_ROOT_DIR/etc/github/repl-state 2>/dev/null || true)" = "replica" ]; then
96107
echo "Error: high availability replica detected." 1>&2

test/test-ghe-host-check.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,16 @@ begin_test "ghe-host-check detects high availability replica"
7878
GHE_ALLOW_REPLICA_BACKUP=yes ghe-host-check
7979
)
8080
end_test
81+
82+
begin_test "ghe-host-check blocks restore to old release"
83+
(
84+
set -e
85+
86+
mkdir -p "$GHE_DATA_DIR/current/"
87+
echo "$GHE_TEST_REMOTE_VERSION" > "$GHE_DATA_DIR/current/version"
88+
89+
# shellcheck disable=SC2046 # Word splitting is required to populate the variables
90+
read -r bu_version_major bu_version_minor bu_version_patch <<<$(ghe_parse_version $GHE_TEST_REMOTE_VERSION)
91+
! GHE_TEST_REMOTE_VERSION=$bu_version_major.$((bu_version_minor-1)).$bu_version_patch ghe-restore -v
92+
)
93+
end_test

test/test-ghe-restore.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ begin_test "ghe-restore fails when restore 2.9/2.10 snapshot without audit log m
341341
set -e
342342

343343
# noop if not testing against 2.11
344-
if [ "$GHE_VERSION_MAJOR" -ne 2 ] && [ "$GHE_VERSION_MINOR" -ne 11 ]; then
344+
if [ "$(version $GHE_REMOTE_VERSION)" -ne "$(version 2.11.0)" ]; then
345345
skip_test
346346
fi
347347

@@ -368,7 +368,7 @@ begin_test "ghe-restore force restore of 2.9/2.10 snapshot without audit log mig
368368
set -e
369369

370370
# noop if not testing against 2.11
371-
if [ "$GHE_VERSION_MAJOR" -ne 2 ] && [ "$GHE_VERSION_MINOR" -ne 11 ]; then
371+
if [ "$(version $GHE_REMOTE_VERSION)" -ne "$(version 2.11.0)" ]; then
372372
skip_test
373373
fi
374374

0 commit comments

Comments
 (0)