Skip to content

Commit d3f3435

Browse files
committed
use the correct value for clientcert in pg_hba.conf for Postgresql 12 and up
1 parent d8a0b5e commit d3f3435

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

manifests/database/postgresql.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
postgresql_ssl_key_path => $postgresql_ssl_key_path,
5353
postgresql_ssl_cert_path => $postgresql_ssl_cert_path,
5454
postgresql_ssl_ca_cert_path => $postgresql_ssl_ca_cert_path,
55+
postgres_version => $postgres_version,
5556
create_read_user_rule => $create_read_user_rule
5657
}
5758
}

manifests/database/postgresql_ssl_rules.pp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
define puppetdb::database::postgresql_ssl_rules (
33
String $database_name,
44
String $database_username,
5+
String $postgres_version,
56
String $puppetdb_server,
67
) {
78
$identity_map_key = "${database_name}-${database_username}-map"
89

10+
$clientcert_value = Float($postgres_version) >= 12.0 ? {
11+
true => 'verify-full',
12+
false => '1',
13+
}
14+
915
postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as ${database_username} (ipv4)":
1016
type => 'hostssl',
1117
database => $database_name,
1218
user => $database_username,
1319
address => '0.0.0.0/0',
1420
auth_method => 'cert',
1521
order => 0,
16-
auth_option => "map=${identity_map_key} clientcert=1"
22+
auth_option => "map=${identity_map_key} clientcert=${clientcert_value}",
1723
}
1824

1925
postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as ${database_username} (ipv6)":
@@ -23,7 +29,7 @@
2329
address => '::0/0',
2430
auth_method => 'cert',
2531
order => 0,
26-
auth_option => "map=${identity_map_key} clientcert=1"
32+
auth_option => "map=${identity_map_key} clientcert=${clientcert_value}",
2733
}
2834

2935
postgresql::server::pg_ident_rule { "Map the SSL certificate of the server as a ${database_username} user":

manifests/database/ssl_configuration.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
$postgresql_ssl_key_path = $puppetdb::params::postgresql_ssl_key_path,
1010
$postgresql_ssl_cert_path = $puppetdb::params::postgresql_ssl_cert_path,
1111
$postgresql_ssl_ca_cert_path = $puppetdb::params::postgresql_ssl_ca_cert_path,
12+
$postgres_version = $puppetdb::params::postgres_version,
1213
$create_read_user_rule = false,
1314
) inherits puppetdb::params {
1415
File {
@@ -55,13 +56,15 @@
5556
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${database_username}":
5657
database_name => $database_name,
5758
database_username => $database_username,
59+
postgres_version => $postgres_version,
5860
puppetdb_server => $puppetdb_server,
5961
}
6062

6163
if $create_read_user_rule {
6264
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${read_database_username}":
6365
database_name => $database_name,
6466
database_username => $read_database_username,
67+
postgres_version => $postgres_version,
6568
puppetdb_server => $puppetdb_server,
6669
}
6770
}

spec/unit/classes/database/ssl_configuration_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,37 @@
188188
.with_database_username(params[:read_database_username])
189189
end
190190
end
191+
192+
context 'when the specified Postgresql version is 12 or later' do
193+
let(:params) do
194+
{
195+
database_name: 'puppetdb',
196+
database_username: 'puppetdb',
197+
postgres_version: '12'
198+
}
199+
end
200+
201+
it 'has hba rule for puppetdb user ipv4' do
202+
is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{params[:database_name]} as #{params[:database_username]} (ipv4)")
203+
.with_type('hostssl')
204+
.with_database(params[:database_name])
205+
.with_user(params[:database_username])
206+
.with_address('0.0.0.0/0')
207+
.with_auth_method('cert')
208+
.with_order(0)
209+
.with_auth_option("map=#{identity_map} clientcert=verify-full")
210+
end
211+
212+
it 'has hba rule for puppetdb user ipv6' do
213+
is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{params[:database_name]} as #{params[:database_username]} (ipv6)")
214+
.with_type('hostssl')
215+
.with_database(params[:database_name])
216+
.with_user(params[:database_username])
217+
.with_address('::0/0')
218+
.with_auth_method('cert')
219+
.with_order(0)
220+
.with_auth_option("map=#{identity_map} clientcert=verify-full")
221+
end
222+
end
191223
end
192224
end

0 commit comments

Comments
 (0)