Skip to content

Commit 290c3ba

Browse files
committed
use the correct value for clientcert in pg_hba.conf for Postgresql 12 and up
1 parent 66737ab commit 290c3ba

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

manifests/database/postgresql.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@
116116
postgresql_ssl_key_path => $postgresql_ssl_key_path,
117117
postgresql_ssl_cert_path => $postgresql_ssl_cert_path,
118118
postgresql_ssl_ca_cert_path => $postgresql_ssl_ca_cert_path,
119-
create_read_user_rule => $create_read_user_rule,
119+
postgres_version => $postgres_version,
120+
create_read_user_rule => $create_read_user_rule
120121
}
121122
}
122123

manifests/database/postgresql_ssl_rules.pp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
define puppetdb::database::postgresql_ssl_rules (
55
String $database_name,
66
String $database_username,
7+
String $postgres_version,
78
String $puppetdb_server,
89
) {
910
$identity_map_key = "${database_name}-${database_username}-map"
1011

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

2127
postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as ${database_username} (ipv6)":
@@ -25,7 +31,7 @@
2531
address => '::0/0',
2632
auth_method => 'cert',
2733
order => 0,
28-
auth_option => "map=${identity_map_key} clientcert=1",
34+
auth_option => "map=${identity_map_key} clientcert=${clientcert_value}",
2935
}
3036

3137
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
@@ -10,6 +10,7 @@
1010
$postgresql_ssl_key_path = $puppetdb::params::postgresql_ssl_key_path,
1111
$postgresql_ssl_cert_path = $puppetdb::params::postgresql_ssl_cert_path,
1212
$postgresql_ssl_ca_cert_path = $puppetdb::params::postgresql_ssl_ca_cert_path,
13+
$postgres_version = $puppetdb::params::postgres_version,
1314
$create_read_user_rule = false,
1415
) inherits puppetdb::params {
1516
File {
@@ -56,13 +57,15 @@
5657
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${database_username}":
5758
database_name => $database_name,
5859
database_username => $database_username,
60+
postgres_version => $postgres_version,
5961
puppetdb_server => $puppetdb_server,
6062
}
6163

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

spec/unit/classes/database/ssl_configuration_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,37 @@
110110
end
111111
end
112112
end
113+
114+
context 'when the specified Postgresql version is 12 or later' do
115+
let(:params) do
116+
{
117+
database_name: 'puppetdb',
118+
database_username: 'puppetdb',
119+
postgres_version: '12'
120+
}
121+
end
122+
123+
it 'has hba rule for puppetdb user ipv4' do
124+
is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{params[:database_name]} as #{params[:database_username]} (ipv4)")
125+
.with_type('hostssl')
126+
.with_database(params[:database_name])
127+
.with_user(params[:database_username])
128+
.with_address('0.0.0.0/0')
129+
.with_auth_method('cert')
130+
.with_order(0)
131+
.with_auth_option("map=#{identity_map} clientcert=verify-full")
132+
end
133+
134+
it 'has hba rule for puppetdb user ipv6' do
135+
is_expected.to contain_postgresql__server__pg_hba_rule("Allow certificate mapped connections to #{params[:database_name]} as #{params[:database_username]} (ipv6)")
136+
.with_type('hostssl')
137+
.with_database(params[:database_name])
138+
.with_user(params[:database_username])
139+
.with_address('::0/0')
140+
.with_auth_method('cert')
141+
.with_order(0)
142+
.with_auth_option("map=#{identity_map} clientcert=verify-full")
143+
end
144+
end
113145
end
114146
end

0 commit comments

Comments
 (0)