Skip to content

Commit 83db9ed

Browse files
committed
(PE-36580) Add r10k_known_hosts to install plan
Starting with PE 2023.3, updates to r10k libraries from PE-35980 changes in libgit2 now verify host keys. Because of this code manager now needs to be configured with known hosts public key information for the r10k remote host. Without this, PE will install but code manager will fail to deploy. This patch will fail the plan early if installing PE 2023.3+, with r10k_private_key (so using ssh protocol) and no r10k_known_hosts array.
1 parent 97ec11b commit 83db9ed

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

REFERENCE.md

+27
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
### Data types
3939

40+
* [`Peadm::Known_hosts`](#Peadm--Known_hosts)
4041
* [`Peadm::Ldap_config`](#Peadm--Ldap_config)
4142
* [`Peadm::Pe_version`](#Peadm--Pe_version)
4243
* [`Peadm::Pem`](#Peadm--Pem)
@@ -776,6 +777,23 @@ Data type: `TargetSpec`
776777

777778
## Data types
778779

780+
### <a name="Peadm--Known_hosts"></a>`Peadm::Known_hosts`
781+
782+
The Peadm::Known_hosts data type.
783+
784+
Alias of
785+
786+
```puppet
787+
Array[Struct[
788+
'title' => Optional[String[1]],
789+
'ensure' => Optional[Enum['present','absent']],
790+
'name' => String[1],
791+
'type' => String[1],
792+
'key' => String[1],
793+
'host_aliases' => Optional[Variant[String[1],Array[String[1]]]],
794+
]]
795+
```
796+
779797
### <a name="Peadm--Ldap_config"></a>`Peadm::Ldap_config`
780798

781799
The Peadm::Ldap_config data type.
@@ -1548,6 +1566,7 @@ The following parameters are available in the `peadm::install` plan:
15481566
* [`r10k_remote`](#-peadm--install--r10k_remote)
15491567
* [`r10k_private_key_file`](#-peadm--install--r10k_private_key_file)
15501568
* [`r10k_private_key_content`](#-peadm--install--r10k_private_key_content)
1569+
* [`r10k_known_hosts`](#-peadm--install--r10k_known_hosts)
15511570
* [`deploy_environment`](#-peadm--install--deploy_environment)
15521571
* [`license_key_file`](#-peadm--install--license_key_file)
15531572
* [`license_key_content`](#-peadm--install--license_key_content)
@@ -1714,6 +1733,14 @@ Data type: `Optional[Peadm::Pem]`
17141733

17151734

17161735

1736+
Default value: `undef`
1737+
1738+
##### <a name="-peadm--install--r10k_known_hosts"></a>`r10k_known_hosts`
1739+
1740+
Data type: `Optional[Peadm::Known_hosts]`
1741+
1742+
1743+
17171744
Default value: `undef`
17181745

17191746
##### <a name="-peadm--install--deploy_environment"></a>`deploy_environment`

plans/install.pp

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
Optional[String] $r10k_remote = undef,
5454
Optional[String] $r10k_private_key_file = undef,
5555
Optional[Peadm::Pem] $r10k_private_key_content = undef,
56+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
5657
Optional[String] $deploy_environment = undef,
5758

5859
# License Key
@@ -94,6 +95,7 @@
9495
r10k_remote => $r10k_remote,
9596
r10k_private_key_file => $r10k_private_key_file,
9697
r10k_private_key_content => $r10k_private_key_content,
98+
r10k_known_hosts => $r10k_known_hosts,
9799

98100
# License Key
99101
license_key_file => $license_key_file,

plans/subplans/install.pp

+23-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
# over to the primary at /etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa
1212
# If the file does not exist the value will simply be supplied to the primary
1313
#
14+
# @param r10k_known_hosts
15+
# Puppet Enterprise 2023.3+ requires host key verification for the
16+
# r10k_remote host. When setting \$r10k_private_key, you must also provide
17+
# \$r10k_known_hosts information in the form of an array of hashes with
18+
# 'name', 'type' and 'key' information for hostname, key-type and public key.
19+
#
1420
# @param license_key_file
1521
# The license key to use with Puppet Enterprise. If this is a local file it
1622
# will be copied over to the MoM at /etc/puppetlabs/license.key
@@ -50,6 +56,7 @@
5056
Optional[String] $r10k_remote = undef,
5157
Optional[String] $r10k_private_key_file = undef,
5258
Optional[Peadm::Pem] $r10k_private_key_content = undef,
59+
Optional[Peadm::Known_hosts] $r10k_known_hosts = undef,
5360

5461
# License key
5562
Optional[String] $license_key_file = undef,
@@ -125,7 +132,21 @@
125132
# either be undef or else the key content to write.
126133
$r10k_private_key = peadm::file_or_content('r10k_private_key', $r10k_private_key_file, $r10k_private_key_content)
127134

128-
# Same for license key
135+
# Determine whether r10k_known_hosts is required and has been provided.
136+
$is_pe_2023_3_or_greater = (versioncmp($version, '2023.3.0') >= 0)
137+
if (($is_pe_2023_3_or_greater) and
138+
($r10k_private_key =~ NotUndef) and
139+
($r10k_known_hosts =~ Undef)) {
140+
fail_plan("In Puppet Enterprise 2023.3+ r10k 4.0 requires host key verification for the r10k_remote host. When setting \$r10k_private_key, you must also provide \$r10k_known_hosts information in the form of an array of hashes with 'name', 'type' and 'key' information for hostname, key-type and public key. Puppet Enterprise version: ${version}, r10k_known_hosts: ${r10k_known_hosts}")
141+
}
142+
$r10k_known_hosts_config = $r10k_known_hosts ? {
143+
undef => {},
144+
default => {
145+
'puppet_enterprise::profile::master::r10k_known_hosts' => $r10k_known_hosts,
146+
},
147+
}
148+
149+
# Process user input for license key (same process as for r10k private key above).
129150
$license_key = peadm::file_or_content('license_key', $license_key_file, $license_key_content)
130151

131152
$precheck_results = run_task('peadm::precheck', $all_targets)
@@ -170,7 +191,7 @@
170191
undef => undef,
171192
default => '/etc/puppetlabs/puppetserver/ssh/id-control_repo.rsa',
172193
},
173-
} + $puppetdb_database_temp_config + $pe_conf_data)
194+
} + $r10k_known_hosts_config + $puppetdb_database_temp_config + $pe_conf_data)
174195

175196
$primary_postgresql_pe_conf = peadm::generate_pe_conf({
176197
'console_admin_password' => 'not used',

spec/plans/subplans/install_spec.rb

+50-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Include the BoltSpec library functions
55
include BoltSpec::Plans
66

7-
it 'minimum variables to run' do
7+
before(:each) do
88
allow_any_task
99
allow_any_plan
1010
allow_any_command
@@ -35,7 +35,9 @@
3535
# rubocop:enable AnyInstance
3636
## </🤮>
3737
##########
38+
end
3839

40+
it 'minimum variables to run' do
3941
params = {
4042
'primary_host' => 'primary',
4143
'console_password' => 'puppetlabs',
@@ -44,4 +46,51 @@
4446

4547
expect(run_plan('peadm::subplans::install', params)).to be_ok
4648
end
49+
50+
it 'installs 2023.2 without r10k_known_hosts' do
51+
params = {
52+
'primary_host' => 'primary',
53+
'console_password' => 'puppetlabs',
54+
'version' => '2023.2.0',
55+
'r10k_remote' => '[email protected]:puppetlabs/nothing',
56+
'r10k_private_key_content' => '-----BEGINfoo',
57+
}
58+
59+
expect(run_plan('peadm::subplans::install', params)).to be_ok
60+
end
61+
62+
it 'fails if 2023.3+ and r10k_private_key set but r10k_known_hosts not set' do
63+
params = {
64+
'primary_host' => 'primary',
65+
'console_password' => 'puppetlabs',
66+
'version' => '2023.3.0',
67+
'r10k_remote' => '[email protected]:puppetlabs/nothing',
68+
'r10k_private_key_content' => '-----BEGINfoo',
69+
'permit_unsafe_versions' => true,
70+
}
71+
72+
result = run_plan('peadm::subplans::install', params)
73+
expect(result).to_not be_ok
74+
expect(result.value.message).to match(/Puppet Enterprise 2023\.3\+ .*requires host key verification/)
75+
end
76+
77+
it 'installs 2023.3+ with r10k_private_key and r10k_known_hosts' do
78+
params = {
79+
'primary_host' => 'primary',
80+
'console_password' => 'puppetlabs',
81+
'version' => '2023.3.0',
82+
'r10k_remote' => '[email protected]:puppetlabs/nothing',
83+
'r10k_private_key_content' => '-----BEGINfoo',
84+
'r10k_known_hosts' => [
85+
{
86+
'name' => 'test',
87+
'type' => 'key-type',
88+
'key' => 'abcdef',
89+
}
90+
],
91+
'permit_unsafe_versions' => true,
92+
}
93+
94+
expect(run_plan('peadm::subplans::install', params)).to be_ok
95+
end
4796
end

types/known_hosts.pp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type Peadm::Known_hosts = Array[
2+
Struct[
3+
'title' => Optional[String[1]],
4+
'ensure' => Optional[Enum['present','absent']],
5+
'name' => String[1],
6+
'type' => String[1],
7+
'key' => String[1],
8+
'host_aliases' => Optional[Variant[String[1],Array[String[1]]]],
9+
]
10+
]

0 commit comments

Comments
 (0)