Skip to content

Commit 079e1cc

Browse files
authored
Stop restore when a backup without Actions is being restored onto an appliance with Actions enabled (#946)
* throw error and abort when restoring a backup with Actions disabled onto an appliance with Actions enabled * set ACTIONS_ENABLED_IN_BACKUP to false if the value is not found in settings.json * use git config to grab app.actions.enabled directly * add bash function to enable and disable actions in settings.json * enable actions in settings for part of other tests that require it * use git config to set initial value for actions in settings.json * empty settings.json before using git config
1 parent 261bd7c commit 079e1cc

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

bin/ghe-restore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ fi
285285
# Get GHES release version in major.minor format
286286
RELEASE_VERSION=$(ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --get core.package-version' | cut -d '.' -f 1,2)
287287

288+
# If the backup being restored is from an appliance with Actions disabled, restoring it onto an appliance with Actions enabled will cause
289+
# mismatches in the secrets needed for Actions which ultimately results in Actions not working properly. Note: xargs is to remove whitespace
290+
ACTIONS_ENABLED_IN_BACKUP=$(git config -f $GHE_RESTORE_SNAPSHOT_PATH/settings.json --bool app.actions.enabled | xargs)
291+
if [[ $ACTIONS_ENABLED_IN_BACKUP != true ]] && ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
292+
echo "Error: Restoring a backup with Actions disabled onto an appliance with Actions enabled is not supported." >&2
293+
exit 1
294+
fi
295+
288296
# Make sure the GitHub appliance has Actions enabled if the snapshot contains Actions data.
289297
# If above is true, also check if ac is present in appliance then snapshot should also contains ac databases
290298
if [ -d "$GHE_RESTORE_SNAPSHOT_PATH/mssql" ] || [ -d "$GHE_RESTORE_SNAPSHOT_PATH/actions" ]; then

test/test-ghe-restore.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
. "$(dirname "$0")/testlib.sh"
77

88
setup_test_data "$GHE_DATA_DIR/1"
9+
setup_actions_enabled_settings_for_restore true
910

1011
# Make the current symlink
1112
ln -s 1 "$GHE_DATA_DIR/current"
@@ -700,3 +701,17 @@ end_test
700701
# verify_all_restored_data
701702
# )
702703
# end_test
704+
705+
begin_test "ghe-restore fails if Actions is disabled in the backup but enabled on the appliance"
706+
(
707+
set -e
708+
rm -rf "$GHE_REMOTE_ROOT_DIR"
709+
setup_remote_metadata
710+
setup_actions_enabled_settings_for_restore false
711+
enable_actions
712+
713+
setup_maintenance_mode "configured"
714+
715+
! ghe-restore -v -f localhost
716+
)
717+
end_test

test/testlib.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,11 @@ cleanup_moreutils_parallel() {
594594
unlink "$ROOTDIR/test/bin/parallel"
595595
fi
596596
}
597+
598+
# setup_actions_enabled_in_settings_json writes settings for the Actions app to settings.json
599+
# it accepts true or false as first argument to enable or disable actions in settings.json
600+
setup_actions_enabled_settings_for_restore() {
601+
# Empty the file, it now contains "fake ghe-export-settings data"
602+
echo > "$GHE_DATA_DIR/1/settings.json"
603+
git config -f "$GHE_DATA_DIR/1/settings.json" --bool app.actions.enabled $1
604+
}

0 commit comments

Comments
 (0)