Skip to content

Commit 84b2e45

Browse files
authored
Merge branch 'enterprise-3.8-release' into enterprise-3.8-backport-417-add-error-msg-for-snapshots
2 parents d20cf09 + c216f2f commit 84b2e45

File tree

8 files changed

+225
-28
lines changed

8 files changed

+225
-28
lines changed

bin/ghe-restore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ if $RESTORE_SETTINGS; then
380380
ghe-restore-settings "$GHE_HOSTNAME"
381381
fi
382382

383+
# Always restore column encryption keys
384+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.7.0)" ]; then
385+
log_info "Always restore encrypted column encryption keys on GHES verions 3.7.0+"
386+
fi
387+
ghe-restore-column-encryption-keys "$GHE_HOSTNAME"
388+
383389
# Make sure mysql and elasticsearch are prep'd and running before restoring.
384390
# These services will not have been started on appliances that have not been
385391
# configured yet.

script/release

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ GH_REPO = ENV['GH_REPO'] || 'backup-utils'
3131
GH_OWNER = ENV['GH_OWNER'] || 'github'
3232
GH_AUTHOR = ENV['GH_AUTHOR']
3333
DEB_PKG_NAME = 'github-backup-utils'
34-
GH_BASE_BRANCH = ENV['GH_BASE_BRANCH'] || 'master'
34+
GH_BASE_BRANCH = ENV['GH_BASE_BRANCH'] || 'master' # TODO: should we even allow a default or require all params get set explicitly?
35+
GH_STABLE_BRANCH = ""
3536

3637
CHANGELOG_TMPL = '''<%= package_name %> (<%= package_version %>) UNRELEASED; urgency=medium
3738
@@ -137,7 +138,8 @@ def beautify_changes(changes)
137138
end
138139

139140
def changelog
140-
changes = `git log --pretty=oneline origin/stable...origin/#{GH_BASE_BRANCH} --reverse --grep "Merge pull request" | sort -t\# -k2`.lines.map(&:strip)
141+
puts "building changelog by comparing origin/#{GH_STABLE_BRANCH}...origin/#{GH_BASE_BRANCH}"
142+
changes = `git log --pretty=oneline origin/#{GH_STABLE_BRANCH}...origin/#{GH_BASE_BRANCH} --reverse --grep "Merge pull request" | sort -t\# -k2`.lines.map(&:strip)
141143
raise 'Building the changelog failed' if $CHILD_STATUS != 0
142144

143145
changes
@@ -228,12 +230,12 @@ def push_release_branch(version)
228230
end
229231

230232
def update_stable_branch
231-
`git checkout --quiet stable`
233+
`git checkout --quiet #{GH_STABLE_BRANCH}`
232234
unless (out = `git merge --quiet --ff-only origin/#{GH_BASE_BRANCH}`)
233-
warn "Merging #{GH_BASE_BRANCH} into stable failed:\n\n#{out}"
235+
warn "Merging #{GH_BASE_BRANCH} into #{GH_STABLE_BRANCH} failed:\n\n#{out}"
234236
end
235-
unless (out = `git push --quiet origin stable`)
236-
warn "Failed pushing the stable branch:\n\n#{out}"
237+
unless (out = `git push --quiet origin #{GH_STABLE_BRANCH}`)
238+
warn "Failed pushing the #{GH_STABLE_BRANCH} branch:\n\n#{out}"
237239
end
238240
end
239241

@@ -333,9 +335,38 @@ def clean_up(version)
333335
`git branch --quiet -D tmp-packaging >/dev/null 2>&1`
334336
end
335337

338+
def is_base_branch_valid?(branch)
339+
if branch == "master" || branch.match(/^\d+\.\d+-main$/)
340+
return true
341+
else
342+
return false
343+
end
344+
end
345+
346+
def get_stable_branch_name(branch)
347+
## derive the proper stable branch. if the base branch is "master" the stable branch is just "stable"
348+
## if the base branch is a release branch, the stable branch will be "x.y-stable"
349+
result = ""
350+
if branch == "master"
351+
result = "stable"
352+
else
353+
result = branch.gsub(/-main$/, "-stable")
354+
end
355+
356+
result
357+
end
358+
336359
#### All the action starts ####
337360
if $PROGRAM_NAME == __FILE__
338361
begin
362+
## validate base branch. this must either be "master" or a release branch which will match the pattern "x.y-main"
363+
raise "The branch #{GH_BASE_BRANCH} is not valid for releasing backup-utils. branch name must be master or match x.y-main" if !is_base_branch_valid?(GH_BASE_BRANCH)
364+
365+
GH_STABLE_BRANCH = get_stable_branch_name(GH_BASE_BRANCH)
366+
367+
puts "base branch = " + GH_BASE_BRANCH
368+
puts "stable branch = " + GH_STABLE_BRANCH
369+
339370
args = ARGV.dup
340371
dry_run = false
341372
skip_version_bump_check = false
@@ -455,7 +486,7 @@ if $PROGRAM_NAME == __FILE__
455486
puts 'Cleaning up...'
456487
clean_up version
457488

458-
puts 'Updating stable branch...'
489+
puts "Updating #{GH_STABLE_BRANCH} branch..."
459490
update_stable_branch
460491

461492
puts 'Released!'

share/github-backup-utils/ghe-backup-mssql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export_tool_available() {
3030
}
3131

3232
ghe_ssh_mssql() {
33-
ghe-ssh $opts $ssh_config_file_opt "$GHE_MSSQL_PRIMARY_HOST" "$@"
33+
ghe-ssh "${opts[@]}" "${ssh_config_file_opt[@]}" "$GHE_MSSQL_PRIMARY_HOST" "$@"
3434
}
3535

3636
cleanup() {
37-
rm -rf $tempdir
37+
rm -rf "$tempdir"
3838
}
3939
trap 'cleanup' EXIT INT
4040

@@ -47,16 +47,16 @@ if [ -z "$GHE_MSSQL_PRIMARY_HOST" ]; then
4747
fi
4848

4949
tempdir=$(mktemp -d -t backup-utils-backup-XXXXXX)
50-
ssh_config_file_opt=
51-
opts=
50+
ssh_config_file_opt=()
51+
opts=()
5252

5353
isHA="$(ghe-ssh "$GHE_HOSTNAME" -- "ghe-config cluster.ha" || true)"
5454

5555
# get server hostnames under cluster and HA
5656
if [ "$GHE_BACKUP_STRATEGY" = "cluster" ] || [ "$isHA" = "true" ] ; then
5757
ssh_config_file="$tempdir/ssh_config"
58-
ssh_config_file_opt="-F $ssh_config_file"
59-
opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no"
58+
ssh_config_file_opt=("-F" "$ssh_config_file")
59+
opts=("-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no" "-o" "PasswordAuthentication=no")
6060
ghe-ssh-config "$GHE_HOSTNAME" "$GHE_MSSQL_PRIMARY_HOST" > "$ssh_config_file"
6161
fi
6262

@@ -69,10 +69,10 @@ add_minute() {
6969
# Expect date string in the format of yyyymmddTHHMMSS
7070
# Here parse date differently depending on GNU Linux vs BSD MacOS
7171
if date -v -1d > /dev/null 2>&1; then
72-
echo "$(date -v +$2M -ujf'%Y%m%dT%H%M%S' $1 +%Y%m%dT%H%M%S)"
72+
date -v +"$2"M -ujf'%Y%m%dT%H%M%S' "$1" +%Y%m%dT%H%M%S
7373
else
7474
dt=$1
75-
echo "$(date -u '+%Y%m%dT%H%M%S' -d "${dt:0:8} ${dt:9:2}:${dt:11:2}:${dt:13:2} $2 minutes")"
75+
date -u '+%Y%m%dT%H%M%S' -d "${dt:0:8} ${dt:9:2}:${dt:11:2}:${dt:13:2} $2 minutes"
7676
fi
7777
}
7878

@@ -337,7 +337,7 @@ if [ -n "$backup_type" ]; then
337337
fi
338338

339339
bm_start "$(basename "$0")"
340-
ghe_ssh_mssql -- "$backup_command" || failures="$failures mssql"
340+
ghe_ssh_mssql -- "$backup_command"
341341
bm_end "$(basename "$0")"
342342

343343
# Configure the backup cadence on the appliance, which is used for diagnostics

share/github-backup-utils/ghe-backup-settings

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ backup-secret "management console password" "manage-password" "secrets.manage"
7878
backup-secret "password pepper" "password-pepper" "secrets.github.user-password-secrets"
7979
backup-secret "kredz.credz HMAC key" "kredz-credz-hmac" "secrets.kredz.credz-hmac-secret"
8080
backup-secret "kredz.varz HMAC key" "kredz-varz-hmac" "secrets.kredz.varz-hmac-secret"
81-
backup-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
82-
backup-secret "encrypted column current encryption key" "encrypted-column-current-encryption-key" "secrets.github.encrypted-column-current-encryption-key"
81+
82+
# backup encryption keying material for GHES 3.7.0 onwards
83+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.7.0)" ]; then
84+
backup-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
85+
fi
86+
87+
# backup current encryption key for GHES 3.8.0 onwards
88+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.8.0)" ]; then
89+
backup-secret "encrypted column current encryption key" "encrypted-column-current-encryption-key" "secrets.github.encrypted-column-current-encryption-key"
90+
fi
8391

8492
# Backup argon secrets for multiuser from ghes version 3.8 onwards
8593
if ! [ "$(version $GHE_REMOTE_VERSION)" -lt "$(version 3.8.0)" ]; then
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-restore-column-encryption-keys <host>
3+
#/ Restore the column encryption keys from a snapshot to the given <host>.
4+
#/ This script will be run automatically by `ghe-restore
5+
set -e
6+
7+
# Bring in the backup configuration
8+
# shellcheck source=share/github-backup-utils/ghe-backup-config
9+
. "$( dirname "${BASH_SOURCE[0]}" )/ghe-backup-config"
10+
11+
# Show usage and bail with no arguments
12+
[ -z "$*" ] && print_usage
13+
14+
bm_start "$(basename $0)"
15+
16+
# Grab host arg
17+
GHE_HOSTNAME="$1"
18+
19+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
20+
ghe_remote_version_required "$GHE_HOSTNAME"
21+
22+
# The snapshot to restore should be set by the ghe-restore command but this lets
23+
# us run this script directly.
24+
: ${GHE_RESTORE_SNAPSHOT:=current}
25+
26+
# Path to snapshot dir we're restoring from
27+
: ${GHE_RESTORE_SNAPSHOT_PATH:="$GHE_DATA_DIR/current"}
28+
29+
# Restore encrypted column encryption keying material for GHES 3.7.0 onward
30+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.7.0)" ]; then
31+
log_info "Restoring encrypted column encryption keying material"
32+
restore-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
33+
fi
34+
35+
# Restore encrypted column current encryption key for GHES 3.8.0 onwards
36+
if [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 3.8.0)" ]; then
37+
log_info "Restoring encrypted column current encryption key"
38+
restore-secret "encrypted column current encryption key" "encrypted-column-current-encryption-key" "secrets.github.encrypted-column-current-encryption-key"
39+
fi
40+
41+
42+
bm_end "$(basename $0)"

share/github-backup-utils/ghe-restore-settings

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ restore-secret "kredz.credz HMAC key" "kredz-credz-hmac" "secrets.kredz.credz-hm
5353
# Restore kredz.varz HMAC key if present.
5454
restore-secret "kredz.varz HMAC key" "kredz-varz-hmac" "secrets.kredz.varz-hmac-secret"
5555

56-
# Restore encrypted column encryption keying material if present
57-
restore-secret "encrypted column encryption keying material" "encrypted-column-encryption-keying-material" "secrets.github.encrypted-column-keying-material"
58-
59-
# Restore encrypted column current encryption key if present
60-
restore-secret "encrypted column current encryption key" "encrypted-column-current-encryption-key" "secrets.github.encrypted-column-current-encryption-key"
61-
6256
# Restore SAML keys if present.
6357
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/saml-keys.tar" ]; then
6458
log_info "Restoring SAML keys ..."

test/test-ghe-backup.sh

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,18 @@ begin_test "ghe-backup takes backup of kredz-varz settings"
543543
)
544544
end_test
545545

546-
begin_test "ghe-backup takes backup of encrypted column encryption keying material"
546+
begin_test "ghe-backup does not take backup of encrypted column encryption keying material for versions below 3.7.0"
547+
(
548+
GHE_REMOTE_VERSION=2.1.10 ghe-backup -v | grep -q "encrypted column encryption keying material not set" && exit 1
549+
[ ! -f "$GHE_DATA_DIR/current/encrypted-column-keying-material" ]
550+
551+
GHE_REMOTE_VERSION=3.6.1 ghe-backup -v | grep -q "encrypted column encryption keying material not set" && exit 1
552+
[ ! -f "$GHE_DATA_DIR/current/encrypted-column-keying-material" ]
553+
554+
)
555+
end_test
556+
557+
begin_test "ghe-backup takes backup of encrypted column encryption keying material for versions 3.7.0+"
547558
(
548559
set -e
549560

@@ -555,6 +566,24 @@ begin_test "ghe-backup takes backup of encrypted column encryption keying materi
555566
ghe-ssh "$GHE_HOSTNAME" -- ghe-config "$secret" "foo"
556567
done
557568

569+
# GHES version 3.7.0
570+
GHE_REMOTE_VERSION=3.7.0
571+
export GHE_REMOTE_VERSION
572+
573+
ghe-backup
574+
575+
required_files=(
576+
"encrypted-column-encryption-keying-material"
577+
)
578+
579+
for file in "${required_files[@]}"; do
580+
[ "$(cat "$GHE_DATA_DIR/current/$file")" = "foo" ]
581+
done
582+
583+
# GHES version 3.8.0
584+
GHE_REMOTE_VERSION=3.8.0
585+
export GHE_REMOTE_VERSION
586+
558587
ghe-backup
559588

560589
required_files=(
@@ -568,7 +597,18 @@ begin_test "ghe-backup takes backup of encrypted column encryption keying materi
568597
)
569598
end_test
570599

571-
begin_test "ghe-backup takes backup of encrypted column current encryption key"
600+
begin_test "ghe-backup does not take backup of encrypted column current encryption key for versions below 3.8.0"
601+
(
602+
GHE_REMOTE_VERSION=2.1.10 ghe-backup -v | grep -q "encrypted column current encryption key not set" && exit 1
603+
[ ! -f "$GHE_DATA_DIR/current/encrypted-column-current-encryption-key" ]
604+
605+
GHE_REMOTE_VERSION=3.7.0 ghe-backup -v | grep -q "encrypted column current encryption key not set" && exit 1
606+
[ ! -f "$GHE_DATA_DIR/current/encrypted-column-current-encryption-key" ]
607+
608+
)
609+
end_test
610+
611+
begin_test "ghe-backup takes backup of encrypted column current encryption key for versions 3.8.0+"
572612
(
573613
set -e
574614

@@ -580,6 +620,24 @@ begin_test "ghe-backup takes backup of encrypted column current encryption key"
580620
ghe-ssh "$GHE_HOSTNAME" -- ghe-config "$secret" "foo"
581621
done
582622

623+
# GHES version 3.8.0
624+
GHE_REMOTE_VERSION=3.8.0
625+
export GHE_REMOTE_VERSION
626+
627+
ghe-backup
628+
629+
required_files=(
630+
"encrypted-column-current-encryption-key"
631+
)
632+
633+
for file in "${required_files[@]}"; do
634+
[ "$(cat "$GHE_DATA_DIR/current/$file")" = "foo" ]
635+
done
636+
637+
# GHES version 3.9.0
638+
GHE_REMOTE_VERSION=3.9.0
639+
export GHE_REMOTE_VERSION
640+
583641
ghe-backup
584642

585643
required_files=(

0 commit comments

Comments
 (0)