File tree 4 files changed +44
-2
lines changed
spec/unit/classes/database 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 52
52
postgresql_ssl_key_path => $postgresql_ssl_key_path ,
53
53
postgresql_ssl_cert_path => $postgresql_ssl_cert_path ,
54
54
postgresql_ssl_ca_cert_path => $postgresql_ssl_ca_cert_path ,
55
+ postgres_version => $postgres_version ,
55
56
create_read_user_rule => $create_read_user_rule
56
57
}
57
58
}
Original file line number Diff line number Diff line change 2
2
define puppetdb::database::postgresql_ssl_rules (
3
3
String $database_name ,
4
4
String $database_username ,
5
+ String $postgres_version ,
5
6
String $puppetdb_server ,
6
7
) {
7
8
$identity_map_key = " ${database_name} -${database_username} -map"
8
9
10
+ $clientcert_value = Float($postgres_version ) >= 12.0 ? {
11
+ true => ' verify-full' ,
12
+ false => ' 1' ,
13
+ }
14
+
9
15
postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as ${database_username} (ipv4)" :
10
16
type => ' hostssl' ,
11
17
database => $database_name ,
12
18
user => $database_username ,
13
19
address => ' 0.0.0.0/0' ,
14
20
auth_method => ' cert' ,
15
21
order => 0,
16
- auth_option => " map=${identity_map_key} clientcert=1 "
22
+ auth_option => " map=${identity_map_key} clientcert=${clientcert_value} " ,
17
23
}
18
24
19
25
postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as ${database_username} (ipv6)" :
23
29
address => ' ::0/0' ,
24
30
auth_method => ' cert' ,
25
31
order => 0,
26
- auth_option => " map=${identity_map_key} clientcert=1 "
32
+ auth_option => " map=${identity_map_key} clientcert=${clientcert_value} " ,
27
33
}
28
34
29
35
postgresql::server::pg_ident_rule { "Map the SSL certificate of the server as a ${database_username} user" :
Original file line number Diff line number Diff line change 9
9
$postgresql_ssl_key_path = $puppetdb::params::postgresql_ssl_key_path,
10
10
$postgresql_ssl_cert_path = $puppetdb::params::postgresql_ssl_cert_path,
11
11
$postgresql_ssl_ca_cert_path = $puppetdb::params::postgresql_ssl_ca_cert_path,
12
+ $postgres_version = $puppetdb::params::postgres_version,
12
13
$create_read_user_rule = false ,
13
14
) inherits puppetdb::params {
14
15
File {
55
56
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${database_username}" :
56
57
database_name => $database_name ,
57
58
database_username => $database_username ,
59
+ postgres_version => $postgres_version ,
58
60
puppetdb_server => $puppetdb_server ,
59
61
}
60
62
61
63
if $create_read_user_rule {
62
64
puppetdb::database::postgresql_ssl_rules { "Configure postgresql ssl rules for ${read_database_username}" :
63
65
database_name => $database_name ,
64
66
database_username => $read_database_username ,
67
+ postgres_version => $postgres_version ,
65
68
puppetdb_server => $puppetdb_server ,
66
69
}
67
70
}
Original file line number Diff line number Diff line change 188
188
. with_database_username ( params [ :read_database_username ] )
189
189
end
190
190
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
191
223
end
192
224
end
You can’t perform that action at this time.
0 commit comments