Skip to content

Commit 30f71f8

Browse files
authoredSep 15, 2023
Merge pull request #382 from puppetlabs/PE-36789
(PE-36789) R10k Known hosts upgrade path
2 parents 2b90756 + 6bdd32c commit 30f71f8

File tree

8 files changed

+294
-18
lines changed

8 files changed

+294
-18
lines changed
 

‎REFERENCE.md

+107
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [`peadm::assert_supported_pe_version`](#peadm--assert_supported_pe_version): Assert that the PE version given is supported by PEAdm
2121
* [`peadm::bolt_version`](#peadm--bolt_version)
2222
* [`peadm::certname`](#peadm--certname): Return the certname of the given target-like input
23+
* [`peadm::check_version_and_known_hosts`](#peadm--check_version_and_known_hosts): Checks PE verison and warns about setting r10k_known_hosts
2324
* [`peadm::convert_hash`](#peadm--convert_hash): converts two arrays into hash
2425
* [`peadm::convert_status`](#peadm--convert_status): Transforms a value in a human readable status with or without colors
2526
* [`peadm::determine_status`](#peadm--determine_status): Produces a summarized hash of the given status data
@@ -28,11 +29,13 @@
2829
* [`peadm::file_or_content`](#peadm--file_or_content)
2930
* [`peadm::flatten_compact`](#peadm--flatten_compact)
3031
* [`peadm::generate_pe_conf`](#peadm--generate_pe_conf): Generate a pe.conf file in JSON format
32+
* [`peadm::get_pe_conf`](#peadm--get_pe_conf)
3133
* [`peadm::get_targets`](#peadm--get_targets): Accept undef or a SingleTargetSpec, and return an Array[Target, 1, 0]. This differs from get_target() in that: - It returns an Array[Target
3234
* [`peadm::node_manager_yaml_location`](#peadm--node_manager_yaml_location)
3335
* [`peadm::oid`](#peadm--oid)
3436
* [`peadm::plan_step`](#peadm--plan_step)
3537
* [`peadm::recovery_opts_default`](#peadm--recovery_opts_default)
38+
* [`peadm::update_pe_conf`](#peadm--update_pe_conf): Update the pe.conf file on a target with the provided hash
3639
* [`peadm::wait_until_service_ready`](#peadm--wait_until_service_ready): A convenience function to help remember port numbers for services and handle running the wait_until_service_ready task
3740

3841
### Data types
@@ -261,6 +264,56 @@ Variant[Target,
261264

262265

263266

267+
### <a name="peadm--check_version_and_known_hosts"></a>`peadm::check_version_and_known_hosts`
268+
269+
Type: Puppet Language
270+
271+
Checks if the current PE version is less than 2023.3.0 and the target version is greater than or equal to 2023.3.0
272+
If both conditions are true and the r10k_known_hosts parameter is not defined, a warning message is displayed.
273+
274+
#### `peadm::check_version_and_known_hosts(String $current_version, String $target_version, Optional[Peadm::Known_hosts] $r10k_known_hosts = undef)`
275+
276+
Checks if the current PE version is less than 2023.3.0 and the target version is greater than or equal to 2023.3.0
277+
If both conditions are true and the r10k_known_hosts parameter is not defined, a warning message is displayed.
278+
279+
Returns: `Any`
280+
281+
##### `$current_version`
282+
283+
Data type: `String`
284+
285+
The current PE version
286+
287+
##### `$target_version`
288+
289+
Data type: `String`
290+
291+
The target PE version
292+
293+
##### `$r10k_known_hosts`
294+
295+
Data type: `Optional[Peadm::Known_hosts]`
296+
297+
The r10k_known_hosts parameter
298+
299+
##### `current_version`
300+
301+
Data type: `String`
302+
303+
304+
305+
##### `target_version`
306+
307+
Data type: `String`
308+
309+
310+
311+
##### `r10k_known_hosts`
312+
313+
Data type: `Optional[Peadm::Known_hosts]`
314+
315+
316+
264317
### <a name="peadm--convert_hash"></a>`peadm::convert_hash`
265318

266319
Type: Puppet Language
@@ -653,6 +706,24 @@ Data type: `Hash`
653706
A hash of settings to set in the config file. Any keys that are set to
654707
undef will not be included in the config file.
655708

709+
### <a name="peadm--get_pe_conf"></a>`peadm::get_pe_conf`
710+
711+
Type: Puppet Language
712+
713+
The peadm::get_pe_conf function.
714+
715+
#### `peadm::get_pe_conf(Target $target)`
716+
717+
The peadm::get_pe_conf function.
718+
719+
Returns: `Any`
720+
721+
##### `target`
722+
723+
Data type: `Target`
724+
725+
726+
656727
### <a name="peadm--get_targets"></a>`peadm::get_targets`
657728

658729
Type: Puppet Language
@@ -749,6 +820,30 @@ The peadm::recovery_opts_default function.
749820

750821
Returns: `Any`
751822

823+
### <a name="peadm--update_pe_conf"></a>`peadm::update_pe_conf`
824+
825+
Type: Puppet Language
826+
827+
Update the pe.conf file on a target with the provided hash
828+
829+
#### `peadm::update_pe_conf(Target $target, Hash $updated_pe_conf_hash)`
830+
831+
The peadm::update_pe_conf function.
832+
833+
Returns: `Any`
834+
835+
##### `target`
836+
837+
Data type: `Target`
838+
839+
The target to update the pe.conf file on
840+
841+
##### `updated_pe_conf_hash`
842+
843+
Data type: `Hash`
844+
845+
The hash to update the pe.conf file with
846+
752847
### <a name="peadm--wait_until_service_ready"></a>`peadm::wait_until_service_ready`
753848

754849
Type: Puppet Language
@@ -1932,6 +2027,7 @@ The following parameters are available in the `peadm::upgrade` plan:
19322027
* [`internal_compiler_b_pool_address`](#-peadm--upgrade--internal_compiler_b_pool_address)
19332028
* [`pe_installer_source`](#-peadm--upgrade--pe_installer_source)
19342029
* [`final_agent_state`](#-peadm--upgrade--final_agent_state)
2030+
* [`r10k_known_hosts`](#-peadm--upgrade--r10k_known_hosts)
19352031
* [`primary_host`](#-peadm--upgrade--primary_host)
19362032
* [`replica_host`](#-peadm--upgrade--replica_host)
19372033
* [`compiler_hosts`](#-peadm--upgrade--compiler_hosts)
@@ -1993,6 +2089,17 @@ after PE is upgraded successfully.
19932089

19942090
Default value: `'running'`
19952091

2092+
##### <a name="-peadm--upgrade--r10k_known_hosts"></a>`r10k_known_hosts`
2093+
2094+
Data type: `Optional[Peadm::Known_hosts]`
2095+
2096+
Puppet Enterprise 2023.3+ requires host key verification for the
2097+
r10k_remote host when using ssh. you must provide \$r10k_known_hosts
2098+
information in the form of an array of hashes with 'name', 'type' and 'key'
2099+
information for hostname, key-type and public key.
2100+
2101+
Default value: `undef`
2102+
19962103
##### <a name="-peadm--upgrade--primary_host"></a>`primary_host`
19972104

19982105
Data type: `Peadm::SingleTargetSpec`

‎documentation/upgrade.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Puppet Enterprise deployments provisioned using the peadm module can also be upg
44

55
## Usage
66

7-
The `peadm::upgrade` plan requires as input the version of PE to upgrade to, and the names of each PE infrastructure host. Primary, replica, compilers, etc.
7+
The `peadm::upgrade` plan requires as input the version of PE to upgrade to, and the names of each PE infrastructure host. Primary, replica, compilers, etc.
88

9-
The following is an example parameters file for upgrading an Extra Large architecture deployment of PE 2021.0.1 to PE 2021.7.4.
9+
Please note that when upgrading from before 2023.3 to 2023.3 or above and you are using code manager, it is nessesary to provide known hosts for r10k. r10k_known_hosts is an optional parameter and is only required one time when upgrading to 2023.3 or beyond. But if you currently use the SSH protocol to allow r10k to access your remote Git repository, your Code manager or r10k code management tool cannot function until you define the r10k_known_hosts parameter. Subsequent upgrades will already have this and it won't be required again. Please refer to the Puppet Enterprise 2023.3 Upgrade cautions for more details.
10+
11+
The following is an example parameters file for upgrading an Extra Large architecture deployment of PE 2023.2.0 to PE 2023.3.0.
1012

1113
```json
1214
{
13-
"version": "2021.7.4",
15+
"version": "2023.3.0",
1416
"primary_host": "pe-master-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
1517
"primary_postgresql_host": "pe-psql-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
1618
"replica_host": "pe-master-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
@@ -20,6 +22,10 @@ The following is an example parameters file for upgrading an Extra Large archite
2022
"pe-compiler-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
2123
"pe-compiler-09a40c-2.us-west1-c.c.reidmv-peadm.internal",
2224
"pe-compiler-09a40c-3.us-west1-a.c.reidmv-peadm.internal"
25+
],
26+
"r10k_known_hosts": [
27+
{"name": "remotehostname", "type": "ssh-rsa", "key": "hash"},
28+
{"name": "remotehostname2", "type": "ssh-rsa", "key": "hash"}
2329
]
2430
}
2531
```
@@ -115,20 +121,20 @@ Note: it is assumed that the Puppet primary is in cluster A when the upgrade sta
115121
1. Shut down the `pe-puppetdb` service on the compilers in cluster B
116122
2. If different from the primary (replica), run the `install-puppet-enterprise` script for the new PE version on the PuppetDB PostgreSQL node for cluster B
117123
3. If different from the primary (replica), Run `puppet agent -t` on the PuppetDB PostgreSQL node for cluster B
118-
5. Run `puppet agent -t` on the primary to ensure orchestration services are configured and restarted before the next steps
119-
6. Perform the replica upgrade using `puppet infra upgrade replica` for the primary (replica)
120-
7. Perform the compiler upgrade using `puppet infra upgrade compiler` for the compilers in cluster B
124+
4. Run `puppet agent -t` on the primary to ensure orchestration services are configured and restarted before the next steps
125+
5. Perform the replica upgrade using `puppet infra upgrade replica` for the primary (replica)
126+
6. Perform the compiler upgrade using `puppet infra upgrade compiler` for the compilers in cluster B
121127

122128
**If Upgrading from 2019.5**
123129

124130
The following steps apply _only_ if upgrading from 2019.5 or older
125131

126132
1. Run `puppet infra run convert_legacy_compiler` for all compilers
127133
2. Modify the peadm node groups "PE Compiler Group A" and "PE Compiler Group B" as follows:
128-
* Re-parent the groups. They should be children of "PE Compiler"
129-
* Remove configuration data (Hiera data). Leave the classes and class parameters
130-
* Add the rule `trusted.extensions.pp_auth_role = pe_compiler`
131-
* Remove the rule `trusted.extensions."1.3.6.1.4.1.34380.1.1.9812" = puppet/compiler`
134+
* Re-parent the groups. They should be children of "PE Compiler"
135+
* Remove configuration data (Hiera data). Leave the classes and class parameters
136+
* Add the rule `trusted.extensions.pp_auth_role = pe_compiler`
137+
* Remove the rule `trusted.extensions."1.3.6.1.4.1.34380.1.1.9812" = puppet/compiler`
132138

133139
**Phase 4: resume puppet service**
134140

‎examples/upgrade.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "2023.3.0",
3+
"primary_host": "pe-master-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
4+
"primary_postgresql_host": "pe-psql-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
5+
"replica_host": "pe-master-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
6+
"replica_postgresql_host": "pe-psql-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
7+
"compiler_hosts": [
8+
"pe-compiler-09a40c-0.us-west1-a.c.reidmv-peadm.internal",
9+
"pe-compiler-09a40c-1.us-west1-b.c.reidmv-peadm.internal",
10+
"pe-compiler-09a40c-2.us-west1-c.c.reidmv-peadm.internal",
11+
"pe-compiler-09a40c-3.us-west1-a.c.reidmv-peadm.internal"
12+
],
13+
"r10k_known_hosts": [
14+
{"name": "remotehostname", "type": "ssh-rsa", "key": "hash"},
15+
{"name": "remotehostname2", "type": "ssh-rsa", "key": "hash"}
16+
]
17+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# @summary Checks PE verison and warns about setting r10k_known_hosts
2+
# Checks if the current PE version is less than 2023.3.0 and the target version is greater than or equal to 2023.3.0
3+
# If both conditions are true and the r10k_known_hosts parameter is not defined, a warning message is displayed.
4+
# @param $current_version [String] The current PE version
5+
# @param $target_version [String] The target PE version
6+
# @param $r10k_known_hosts [Optional[Peadm::Known_hosts]] The r10k_known_hosts parameter
7+
function peadm::check_version_and_known_hosts(
8+
String $current_version,
9+
String $target_version,
10+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
11+
) {
12+
$version = '2023.3.0'
13+
$current_check = SemVer($current_version) < SemVer($version)
14+
$target_check = SemVer($target_version) >= SemVer($version)
15+
16+
# lint:ignore:140chars
17+
if ($current_check and $target_check and $r10k_known_hosts == undef) {
18+
out::message( @(HEREDOC/n)
19+
\nWARNING: Starting in PE 2023.3, SSH host key verification is required for Code Manager and r10k.\n
20+
To enable host key verification, you must define the puppet_enterprise::profile::master::r10k_known_hosts parameter with an array of hashes containing "name", "type", and "key" to specify your hostname, key type, and public key for your remote host(s).\n
21+
If you currently use SSH protocol to allow r10k to access your remote Git repository, your Code Manager or r10k code management tool cannot function until you define the r10k_known_hosts parameter.\n
22+
Please refer to the Puppet Enterprise 2023.3 Upgrade cautions for more details.\n
23+
HEREDOC
24+
)# lint:endignore
25+
}
26+
}

‎functions/get_pe_conf.pp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function peadm::get_pe_conf(Target $target) {
2+
$current_pe_conf_content = run_task('peadm::read_file', $target, path => '/etc/puppetlabs/enterprise/conf.d/pe.conf').first['content']
3+
4+
# Parse the current pe.conf content and return the hash
5+
return $current_pe_conf_content ? {
6+
undef => {},
7+
default => stdlib::parsehocon($current_pe_conf_content),
8+
}
9+
}

‎functions/update_pe_conf.pp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# @summary Update the pe.conf file on a target with the provided hash
2+
# @param target [Bolt::Target] The target to update the pe.conf file on
3+
# @param updated_pe_conf_hash [Hash] The hash to update the pe.conf file with
4+
function peadm::update_pe_conf(Target $target, Hash $updated_pe_conf_hash) {
5+
# Convert the updated hash back to a pretty JSON string
6+
$updated_pe_conf_content = stdlib::to_json_pretty($updated_pe_conf_hash)
7+
8+
# Write the updated content back to pe.conf on the target
9+
write_file($updated_pe_conf_content, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
10+
}

‎plans/upgrade.pp

+25-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
# @param final_agent_state
2020
# Configures the state the puppet agent should be in on infrastructure nodes
2121
# after PE is upgraded successfully.
22-
#
22+
# @param r10k_known_hosts
23+
# Puppet Enterprise 2023.3+ requires host key verification for the
24+
# r10k_remote host when using ssh. you must provide \$r10k_known_hosts
25+
# information in the form of an array of hashes with 'name', 'type' and 'key'
26+
# information for hostname, key-type and public key.
27+
#
2328
plan peadm::upgrade (
2429
# Standard
2530
Peadm::SingleTargetSpec $primary_host,
@@ -33,11 +38,12 @@
3338
Optional[Peadm::SingleTargetSpec] $replica_postgresql_host = undef,
3439

3540
# Common Configuration
36-
Optional[Peadm::Pe_version] $version = undef,
37-
Optional[String] $pe_installer_source = undef,
38-
Optional[String] $compiler_pool_address = undef,
39-
Optional[String] $internal_compiler_a_pool_address = undef,
40-
Optional[String] $internal_compiler_b_pool_address = undef,
41+
Optional[Peadm::Pe_version] $version = undef,
42+
Optional[String] $pe_installer_source = undef,
43+
Optional[String] $compiler_pool_address = undef,
44+
Optional[String] $internal_compiler_a_pool_address = undef,
45+
Optional[String] $internal_compiler_b_pool_address = undef,
46+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
4147

4248
# Other
4349
Optional[String] $token_file = undef,
@@ -210,6 +216,17 @@
210216

211217
write_file($pe_conf, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
212218
}
219+
220+
if $r10k_known_hosts != undef {
221+
$current_pe_conf = peadm::get_pe_conf($primary_target[0])
222+
223+
# Append the r10k_known_hosts entry
224+
$updated_pe_conf = $current_pe_conf + {
225+
'puppet_enterprise::profile::master::r10k_known_hosts' => $r10k_known_hosts,
226+
}
227+
228+
peadm::update_pe_conf($primary_target[0], $updated_pe_conf)
229+
}
213230
}
214231

215232
peadm::plan_step('upgrade-primary') || {
@@ -391,5 +408,7 @@
391408
)
392409
}
393410

411+
peadm::check_version_and_known_hosts($current_pe_version, $_version, $r10k_known_hosts)
412+
394413
return("Upgrade of Puppet Enterprise ${arch['architecture']} completed.")
395414
}

‎spec/plans/upgrade_spec.rb

+84-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def allow_standard_non_returning_calls
2323
it 'minimum variables to run' do
2424
allow_standard_non_returning_calls
2525

26-
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
26+
expect_task('peadm::read_file')
27+
.with_params('path' => '/opt/puppetlabs/server/pe_build')
28+
.always_return({ 'content' => '2021.7.3' })
29+
2730
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary)
2831

2932
expect(run_plan('peadm::upgrade',
@@ -34,7 +37,10 @@ def allow_standard_non_returning_calls
3437
it 'runs with a primary, compilers, but no replica' do
3538
allow_standard_non_returning_calls
3639

37-
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
40+
expect_task('peadm::read_file')
41+
.with_params('path' => '/opt/puppetlabs/server/pe_build')
42+
.always_return({ 'content' => '2021.7.3' })
43+
3844
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary,
3945
'compiler' => trusted_compiler)
4046

@@ -55,4 +61,80 @@ def allow_standard_non_returning_calls
5561
expect(result.value.kind).to eq('unexpected-transport')
5662
expect(result.value.msg).to match(%r{The "pcp" transport is not available for use with the Primary})
5763
end
64+
65+
context 'r10k_known_hosts' do
66+
let(:installed_version) { '2021.7.3' }
67+
let(:r10k_known_hosts) do
68+
[
69+
{
70+
'name' => 'primary.rspec',
71+
'type' => 'rsa',
72+
'key' => 'pubkey',
73+
},
74+
]
75+
end
76+
# NOTE: dupliating this error message is unfortunate, but
77+
# expect_out_message() doesn't take a regex.
78+
let(:r10k_warning) do
79+
<<~EOS
80+
\nWARNING: Starting in PE 2023.3, SSH host key verification is required for Code Manager and r10k.\n
81+
To enable host key verification, you must define the puppet_enterprise::profile::master::r10k_known_hosts parameter with an array of hashes containing "name", "type", and "key" to specify your hostname, key type, and public key for your remote host(s).\n
82+
If you currently use SSH protocol to allow r10k to access your remote Git repository, your Code Manager or r10k code management tool cannot function until you define the r10k_known_hosts parameter.\n
83+
Please refer to the Puppet Enterprise 2023.3 Upgrade cautions for more details.\n
84+
EOS
85+
end
86+
87+
before(:each) do
88+
allow_standard_non_returning_calls
89+
90+
expect_task('peadm::read_file')
91+
.with_params('path' => '/opt/puppetlabs/server/pe_build')
92+
.always_return({ 'content' => installed_version })
93+
94+
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary)
95+
end
96+
97+
it 'updates pe.conf if r10k_known_hosts is set' do
98+
expect_task('peadm::read_file')
99+
.with_params('path' => '/etc/puppetlabs/enterprise/conf.d/pe.conf')
100+
.always_return({ 'content' => <<~PECONF })
101+
# spec pe.conf
102+
"puppet_enterprise::puppet_master_host": "%{::trusted.certname}"
103+
PECONF
104+
# TODO: this doesn't verify what we are writing; we would need to mock
105+
# write_file for that. Being more specific about exactly what file we are
106+
# uploading runs afoul of the fact that write_file creates a source tempfile,
107+
# and we can't expect_upload() because we don't have the tempfile name.
108+
allow_any_upload
109+
110+
expect(run_plan('peadm::upgrade',
111+
'primary_host' => 'primary',
112+
'version' => '2023.3.0',
113+
'r10k_known_hosts' => r10k_known_hosts,
114+
'permit_unsafe_versions' => true)).to be_ok
115+
end
116+
117+
it 'warns if upgrading to 2023.3+ from 2023.0- without r10k_known_hosts set' do
118+
# This is fairly horrible, but expect_out_message doesn't take a regex.
119+
expect_out_message.with_params(r10k_warning)
120+
121+
expect(run_plan('peadm::upgrade',
122+
'primary_host' => 'primary',
123+
'version' => '2023.3.0',
124+
'permit_unsafe_versions' => true)).to be_ok
125+
end
126+
127+
context 'upgrading from 2023.3+' do
128+
let(:installed_version) { '2023.3.0' }
129+
130+
it 'does not warn if r10k_known_hosts is not set' do
131+
expect_out_message.with_params(r10k_warning).not_be_called
132+
133+
expect(run_plan('peadm::upgrade',
134+
'primary_host' => 'primary',
135+
'version' => '2023.4.0',
136+
'permit_unsafe_versions' => true)).to be_ok
137+
end
138+
end
139+
end
58140
end

0 commit comments

Comments
 (0)
Please sign in to comment.