Skip to content

Commit fd2cccb

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

6 files changed

Lines changed: 64 additions & 3 deletions

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
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,
14+
$postgresql_ssl_key_path = $puppetdb::params::postgresql_ssl_key_path,
15+
$postgresql_ssl_cert_path = $puppetdb::params::postgresql_ssl_cert_path,
16+
$postgresql_ssl_ca_cert_path = $puppetdb::params::postgresql_ssl_ca_cert_path
1317
) inherits puppetdb::params {
1418

1519
if $manage_server {
@@ -24,6 +28,30 @@
2428
port => scanf($database_port, '%i')[0],
2529
}
2630

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

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: 11 additions & 1 deletion
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) {
@@ -85,7 +86,16 @@
8586
$database_suffix = ''
8687
}
8788

88-
$subname = "//${database_host}:${database_port}/${database_name}${database_suffix}"
89+
$subname_default = "//${database_host}:${database_port}/${database_name}${database_suffix}"
90+
91+
if $postgresql_ssl_on {
92+
$subname = "${subname_default}?\
93+
ssl=true&sslfactory=org.postgresql.ssl.LibPQFactory&\
94+
sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&\
95+
sslkey=${ssl_key_path}&sslcert=${ssl_cert_path}"
96+
} else {
97+
$subname = $subname_default
98+
}
8999

90100
##Only setup for postgres
91101
ini_setting {'puppetdb_psdatabase_username':

manifests/server/read_database.pp

Lines changed: 11 additions & 1 deletion
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.
@@ -73,7 +74,16 @@
7374
$database_suffix = ''
7475
}
7576

76-
$subname = "//${database_host}:${database_port}/${database_name}${database_suffix}"
77+
$subname_default = "//${database_host}:${database_port}/${database_name}${database_suffix}"
78+
79+
if $postgresql_ssl_on {
80+
$subname = "${subname_default}?\
81+
ssl=true&sslfactory=org.postgresql.ssl.LibPQFactory&\
82+
sslmode=verify-full&sslrootcert=${ssl_ca_cert_path}&\
83+
sslkey=${ssl_key_path}&sslcert=${ssl_cert_path}"
84+
} else {
85+
$subname = $subname_default
86+
}
7787

7888
ini_setting { 'puppetdb_read_database_username':
7989
setting => 'username',

0 commit comments

Comments
 (0)