Skip to content

Commit 4758df1

Browse files
(PDB-4764) Agent SSL certificates are used for communication with the postgresql
1 parent 11dc0df commit 4758df1

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

lib/puppet/type/puppetdb_conn_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
end
2424

2525
newparam(:use_ssl) do
26-
desc 'Whether the connection will be attemped using https'
26+
desc 'Whether the connection will be attempted using https'
2727
defaultto true
2828
end
2929

manifests/database/postgresql.pp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$manage_server = $puppetdb::params::manage_dbserver,
1111
$manage_package_repo = $puppetdb::params::manage_pg_repo,
1212
$postgres_version = $puppetdb::params::postgres_version,
13+
$postgresql_ssl_on = $puppetdb::params::postgresql_ssl_on
1314
) inherits puppetdb::params {
1415

1516
if $manage_server {
@@ -24,6 +25,30 @@
2425
port => scanf($database_port, '%i')[0],
2526
}
2627

28+
# configure PostgreSQL communication with Puppet Agent SSL certificates if
29+
# postgresql_ssl_on is set to true
30+
if $postgresql_ssl_on {
31+
postgresql::server::config_entry {'ssl':
32+
ensure => present,
33+
value => 'on',
34+
}
35+
36+
postgresql::server::config_entry {'ssl_key_file':
37+
ensure => present,
38+
value => $postgresql_ssl_key_path,
39+
}
40+
41+
postgresql::server::config_entry {'ssl_cert_file':
42+
ensure => present,
43+
value => $postgresql_ssl_cert_path,
44+
}
45+
46+
postgresql::server::config_entry {'ssl_ca_file':
47+
ensure => present,
48+
value => $postgresql_ssl_ca_cert_path,
49+
}
50+
}
51+
2752
# Only install pg_trgm extension, if database it is actually managed by the module
2853
if $manage_database {
2954

manifests/init.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
$ssl_cert = $puppetdb::params::ssl_cert,
2020
$ssl_ca_cert = $puppetdb::params::ssl_ca_cert,
2121
$ssl_protocols = $puppetdb::params::ssl_protocols,
22+
$postgresql_ssl_on = $puppetdb::params::postgresql_ssl_on,
23+
$postgresql_ssl_folder = $puppetdb::params::postgresql_ssl_folder,
24+
$postgresql_ssl_cert_path = $puppetdb::params::postgresql_ssl_cert_path,
25+
$postgresql_ssl_key_path = $puppetdb::params::postgresql_ssl_key_path,
26+
$postgresql_ssl_ca_cert_path = $puppetdb::params::postgresql_ssl_ca_cert_path,
2227
$cipher_suites = $puppetdb::params::cipher_suites,
2328
$migrate = $puppetdb::params::migrate,
2429
$manage_dbserver = $puppetdb::params::manage_dbserver,

manifests/params.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@
180180
$cleanup_timer_interval = "*-*-* ${fqdn_rand(24)}:${fqdn_rand(60)}:00"
181181
$dlo_max_age = 90
182182

183+
# certificats used for PostgreSQL SSL configuration. Puppet certificates are used
184+
$postgresql_ssl_on = true
185+
$postgresql_ssl_folder = "${puppet_confdir}/ssl"
186+
$postgresql_ssl_cert_path = "${postgresql_ssl_folder}/certs/${trusted['certname']}.pem"
187+
$postgresql_ssl_key_path = "${postgresql_ssl_folder}/private_keys/${trusted['certname']}.pem"
188+
$postgresql_ssl_ca_cert_path = "${postgresql_ssl_folder}/certs/ca.pem"
189+
190+
# certificats used for Jetty configuration
183191
$ssl_set_cert_paths = false
184192
$ssl_cert_path = "${ssl_dir}/public.pem"
185193
$ssl_key_path = "${ssl_dir}/private.pem"

manifests/server/database.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
$puppetdb_group = $puppetdb::params::puppetdb_group,
2626
$database_max_pool_size = $puppetdb::params::database_max_pool_size,
2727
$migrate = $puppetdb::params::migrate,
28+
$postgresql_ssl_on = $puppetdb::params::postgresql_ssl_on
2829
) inherits puppetdb::params {
2930

3031
if str2bool($database_validate) {
@@ -87,6 +88,14 @@
8788

8889
$subname = "//${database_host}:${database_port}/${database_name}${database_suffix}"
8990

91+
if $postgresql_ssl_on {
92+
$subname += @("EOT")
93+
?ssl=true&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory&
94+
sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&
95+
sslkey=${ssl_key_path}&sslcert=${ssl_cert_path}
96+
|-EOT
97+
}
98+
9099
##Only setup for postgres
91100
ini_setting {'puppetdb_psdatabase_username':
92101
setting => 'username',

manifests/server/read_database.pp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
$puppetdb_user = $puppetdb::params::puppetdb_user,
1818
$puppetdb_group = $puppetdb::params::puppetdb_group,
1919
$database_max_pool_size = $puppetdb::params::read_database_max_pool_size,
20+
$postgresql_ssl_on = $puppetdb::params::postgresql_ssl_on
2021
) inherits puppetdb::params {
2122

2223
# Only add the read database configuration if database host is defined.
@@ -75,6 +76,14 @@
7576

7677
$subname = "//${database_host}:${database_port}/${database_name}${database_suffix}"
7778

79+
if $postgresql_ssl_on {
80+
$subname += @("EOT")
81+
?ssl=true&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory&
82+
sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&
83+
sslkey=${ssl_key_path}&sslcert=${ssl_cert_path}
84+
|-EOT
85+
}
86+
7887
ini_setting { 'puppetdb_read_database_username':
7988
setting => 'username',
8089
value => $database_username,

0 commit comments

Comments
 (0)