Skip to content

Commit cbf23b7

Browse files
(PE-40379) fix issue on RBAC restore
1 parent dd7f25a commit cbf23b7

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

functions/migration_opts_default.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ function peadm::migration_opts_default () {
77
'config' => false,
88
'orchestrator' => true,
99
'puppetdb' => true,
10-
'rbac' => false,
10+
'rbac' => true,
1111
}
1212
}

plans/migrate.pp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@
7777
})
7878

7979
run_plan('peadm::restore', {
80-
targets => $new_primary_host,
81-
restore_type => 'migration',
82-
input_file => $remote_backup_path,
80+
targets => $new_primary_host,
81+
restore_type => 'migration',
82+
input_file => $remote_backup_path,
83+
console_password => $old_primary_password,
8384
})
8485

8586
$node_types = {

plans/restore.pp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
# Path to the recovery tarball
2121
Pattern[/.*\.tar\.gz$/] $input_file,
22+
23+
# Console password for restored system
24+
Optional[String] $console_password = undef,
2225
) {
2326
peadm::assert_supported_bolt_version()
2427

@@ -194,8 +197,8 @@
194197
# Restore secrets/keys.json if it exists
195198
out::message('# Restoring ldap secret key if it exists')
196199
run_command(@("CMD"/L), $primary_target)
197-
test -f ${shellquote($recovery_directory)}/rbac/keys.json \
198-
&& cp -rp ${shellquote($recovery_directory)}/keys.json /etc/puppetlabs/console-services/conf.d/secrets/ \
200+
test -f ${shellquote($recovery_directory)}/rbac/secrets/keys.json \
201+
&& cp -rp ${shellquote($recovery_directory)}/rbac/secrets/keys.json /etc/puppetlabs/console-services/conf.d/secrets/ \
199202
|| echo secret ldap key doesnt exist
200203
| CMD
201204
# lint:ignore:140chars
@@ -296,6 +299,11 @@
296299
# TODO: consider adding a heuristic to skip when innappropriate due to size
297300
# or other factors.
298301
if getvar('recovery_opts.puppetdb') and $restore_type == 'migration' {
302+
# ensure there is a valid token on the new primary host
303+
run_task('peadm::rbac_token', $primary_target,
304+
password => $console_password,
305+
token_lifetime => '1y',
306+
)
299307
run_command(@("CMD"/L), $primary_target)
300308
/opt/puppetlabs/bin/puppet-db import \
301309
--cert=$(/opt/puppetlabs/bin/puppet config print hostcert) \

spec/plans/restore_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
expect_command("umask 0077 && cd /input && tar -xzf /input/file.tar.gz\n")
6565
expect_command("/opt/puppetlabs/bin/puppet-backup restore --scope=certs,code,config --tempdir=/input/file --force /input/file/recovery/pe_backup-*tgz\n")
6666
expect_command("systemctl stop pe-console-services pe-nginx pxp-agent pe-puppetserver pe-orchestration-services puppet pe-puppetdb\n")
67-
expect_command("test -f /input/file/rbac/keys.json && cp -rp /input/file/keys.json /etc/puppetlabs/console-services/conf.d/secrets/ || echo secret ldap key doesnt exist\n")
67+
expect_command("test -f /input/file/rbac/secrets/keys.json && cp -rp /input/file/rbac/secrets/keys.json /etc/puppetlabs/console-services/conf.d/secrets/ || echo secret ldap key doesnt exist\n")
6868
expect_command("su - pe-postgres -s /bin/bash -c \"/opt/puppetlabs/server/bin/psql --tuples-only -d 'pe-puppetdb' -c 'DROP SCHEMA IF EXISTS pglogical CASCADE;'\"\n").be_called_times(2)
6969
expect_command("su - pe-postgres -s /bin/bash -c \"/opt/puppetlabs/server/bin/psql -d 'pe-puppetdb' -c 'DROP SCHEMA public CASCADE; CREATE SCHEMA public;'\"\n")
7070
expect_command('su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/bin/psql -d \'pe-puppetdb\' -c \'ALTER USER \\"pe-puppetdb\\" WITH SUPERUSER;\'"' + "\n")

0 commit comments

Comments
 (0)