Skip to content

Commit 255b974

Browse files
(PE-40379) fix issue on RBAC restore (#579)
1 parent dd7f25a commit 255b974

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

REFERENCE.md

+9
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,7 @@ The following parameters are available in the `peadm::restore` plan:
24762476
* [`restore_type`](#-peadm--restore--restore_type)
24772477
* [`restore`](#-peadm--restore--restore)
24782478
* [`input_file`](#-peadm--restore--input_file)
2479+
* [`console_password`](#-peadm--restore--console_password)
24792480

24802481
##### <a name="-peadm--restore--targets"></a>`targets`
24812482

@@ -2505,6 +2506,14 @@ Data type: `Pattern[/.*\.tar\.gz$/]`
25052506

25062507
The file containing the backup to restore from
25072508

2509+
##### <a name="-peadm--restore--console_password"></a>`console_password`
2510+
2511+
Data type: `Optional[String]`
2512+
2513+
2514+
2515+
Default value: `undef`
2516+
25082517
### <a name="peadm--restore_ca"></a>`peadm::restore_ca`
25092518

25102519
The peadm::restore_ca class.

functions/migration_opts_default.pp

+1-1
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

+4-3
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

+10-2
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

+1-1
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)