Skip to content

Commit 90304d4

Browse files
authored
Merge pull request #243 from github/atirikt/ghe-kredz_backup
GHES Kredz backup util
2 parents b0f212e + 3b08120 commit 90304d4

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ backup-secret() {
7676

7777
backup-secret "management console password" "manage-password" "secrets.manage"
7878
backup-secret "password pepper" "password-pepper" "secrets.github.user-password-secrets"
79+
backup-secret "kredz.credz HMAC key" "kredz-credz-hmac" "secrets.kredz.credz-hmac-secret"
7980

8081
# Backup external MySQL password if running external MySQL DB.
8182
if is_service_external 'mysql'; then
@@ -102,7 +103,6 @@ if ghe-ssh "$host" -- ghe-config --true app.actions.enabled; then
102103
backup-secret "Actions SPS validation cert thumbprint" "actions-sps-validation-cert-thumbprint" "secrets.actions.SpsValidationCertThumbprint"
103104

104105
backup-secret "Actions Launch secrets encryption/decryption" "actions-launch-secrets-private-key" "secrets.launch.actions-secrets-private-key"
105-
backup-secret "Actions Launch credz HMAC key" "actions-launch-credz-hmac" "secrets.launch.credz-hmac-secret"
106106
backup-secret "Actions Launch deployer HMAC key" "actions-launch-deployer-hmac" "secrets.launch.deployer-hmac-secret"
107107
backup-secret "Actions Launch Client id" "actions-launch-client-id" "secrets.launch.client-id"
108108
backup-secret "Actions Launch Client secret" "actions-launch-client-secret" "secrets.launch.client-secret"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ restore-secret "Actions service principal cert" "actions-service-principal-cert"
7070
restore-secret "Actions SPS validation cert thumbprint" "actions-sps-validation-cert-thumbprint" "secrets.actions.SpsValidationCertThumbprint"
7171

7272
restore-secret "Actions Launch secrets encryption/decryption" "actions-launch-secrets-private-key" "secrets.launch.actions-secrets-private-key"
73-
restore-secret "Actions Launch credz HMAC key" "actions-launch-credz-hmac" "secrets.launch.credz-hmac-secret"
7473
restore-secret "Actions Launch deployer HMAC key" "actions-launch-deployer-hmac" "secrets.launch.deployer-hmac-secret"
7574
restore-secret "Actions Launch Client id" "actions-launch-client-id" "secrets.launch.client-id"
7675
restore-secret "Actions Launch Client secret" "actions-launch-client-secret" "secrets.launch.client-secret"
@@ -86,6 +85,7 @@ restore-secret "Actions Launch service private key" "actions-launch-app-app-priv
8685
restore-secret "Actions Launch token oauth key" "actions-oauth-s2s-signing-key" "secrets.launch.token-oauth-key"
8786
restore-secret "Actions Launch token oauth cert" "actions-oauth-s2s-signing-cert" "secrets.launch.token-oauth-cert"
8887

88+
8989
# Setup the database logins.
9090
ghe_verbose "* Restoring database logins and users to $host ..."
9191

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ restore-secret "external MySQL password" "external-mysql-password" "secrets.exte
4141
# Restore management console password hash if present.
4242
restore-secret "management console password" "manage-password" "secrets.manage"
4343

44+
# Restore kredz.credz HMAC key if present.
45+
restore-secret "kredz.credz HMAC key" "kredz-credz-hmac" "secrets.kredz.credz-hmac-secret"
46+
4447
# Restore SAML keys if present.
4548
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/saml-keys.tar" ]; then
4649
echo "Restoring SAML keys ..."

test/test-ghe-backup.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,31 @@ begin_test "ghe-backup upgrades transaction backup to full if LSN chain break"
470470
)
471471
end_test
472472

473+
begin_test "ghe-backup takes backup of Kredz settings"
474+
(
475+
set -e
476+
477+
required_secrets=(
478+
"secrets.kredz.credz-hmac-secret"
479+
)
480+
481+
for secret in "${required_secrets[@]}"; do
482+
ghe-ssh "$GHE_HOSTNAME" -- ghe-config "$secret" "foo"
483+
done
484+
485+
ghe-backup
486+
487+
required_files=(
488+
"kredz-credz-hmac"
489+
)
490+
491+
for file in "${required_files[@]}"; do
492+
[ "$(cat "$GHE_DATA_DIR/current/$file")" = "foo" ]
493+
done
494+
495+
)
496+
end_test
497+
473498
begin_test "ghe-backup takes backup of Actions settings"
474499
(
475500
set -e
@@ -493,7 +518,6 @@ begin_test "ghe-backup takes backup of Actions settings"
493518
"secrets.actions.SpsValidationCertThumbprint"
494519

495520
"secrets.launch.actions-secrets-private-key"
496-
"secrets.launch.credz-hmac-secret"
497521
"secrets.launch.deployer-hmac-secret"
498522
"secrets.launch.client-id"
499523
"secrets.launch.client-secret"
@@ -507,6 +531,7 @@ begin_test "ghe-backup takes backup of Actions settings"
507531
"secrets.launch.token-oauth-cert"
508532
"secrets.launch.azp-app-cert"
509533
"secrets.launch.azp-app-private-key"
534+
510535
)
511536

512537
# these 5 were removed in later versions, so we extract them as best effort
@@ -538,7 +563,6 @@ begin_test "ghe-backup takes backup of Actions settings"
538563
"actions-sps-validation-cert-thumbprint"
539564

540565
"actions-launch-secrets-private-key"
541-
"actions-launch-credz-hmac"
542566
"actions-launch-deployer-hmac"
543567
"actions-launch-client-id"
544568
"actions-launch-client-secret"
@@ -550,6 +574,7 @@ begin_test "ghe-backup takes backup of Actions settings"
550574
"actions-launch-action-runner-secret"
551575
"actions-launch-azp-app-cert"
552576
"actions-launch-app-app-private-key"
577+
553578
)
554579

555580
# Add the one optional file we included tests for

test/test-ghe-restore.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,32 @@ begin_test "ghe-restore invokes ghe-import-mssql"
309309
)
310310
end_test
311311

312+
begin_test "ghe-restore with Kredz settings"
313+
(
314+
set -e
315+
rm -rf "$GHE_REMOTE_ROOT_DIR"
316+
setup_remote_metadata
317+
enable_actions
318+
319+
required_files=(
320+
"kredz-credz-hmac"
321+
)
322+
323+
for file in "${required_files[@]}"; do
324+
echo "foo" > "$GHE_DATA_DIR/current/$file"
325+
done
326+
327+
ghe-restore -v -f localhost
328+
required_secrets=(
329+
"secrets.kredz.credz-hmac-secret"
330+
)
331+
332+
for secret in "${required_secrets[@]}"; do
333+
[ "$(ghe-ssh "$GHE_HOSTNAME" -- ghe-config "$secret")" = "foo" ]
334+
done
335+
)
336+
end_test
337+
312338
begin_test "ghe-restore with Actions settings"
313339
(
314340
set -e
@@ -335,7 +361,6 @@ begin_test "ghe-restore with Actions settings"
335361
"actions-sps-validation-cert-thumbprint"
336362

337363
"actions-launch-secrets-private-key"
338-
"actions-launch-credz-hmac"
339364
"actions-launch-deployer-hmac"
340365
"actions-launch-client-id"
341366
"actions-launch-client-secret"
@@ -347,6 +372,7 @@ begin_test "ghe-restore with Actions settings"
347372
"actions-launch-action-runner-secret"
348373
"actions-launch-azp-app-cert"
349374
"actions-launch-app-app-private-key"
375+
350376
)
351377

352378
for file in "${required_files[@]}"; do
@@ -374,7 +400,6 @@ begin_test "ghe-restore with Actions settings"
374400
"secrets.actions.SpsValidationCertThumbprint"
375401

376402
"secrets.launch.actions-secrets-private-key"
377-
"secrets.launch.credz-hmac-secret"
378403
"secrets.launch.deployer-hmac-secret"
379404
"secrets.launch.client-id"
380405
"secrets.launch.client-secret"
@@ -388,6 +413,7 @@ begin_test "ghe-restore with Actions settings"
388413
"secrets.launch.token-oauth-cert"
389414
"secrets.launch.azp-app-cert"
390415
"secrets.launch.azp-app-private-key"
416+
391417
)
392418

393419
for secret in "${required_secrets[@]}"; do

0 commit comments

Comments
 (0)