|
1 | 1 | # Class for creating the PuppetDB postgresql database. See README.md for more |
2 | 2 | # information. |
3 | 3 | class puppetdb::database::postgresql( |
4 | | - $listen_addresses = $puppetdb::params::database_host, |
5 | | - $database_name = $puppetdb::params::database_name, |
6 | | - $database_username = $puppetdb::params::database_username, |
7 | | - $database_password = $puppetdb::params::database_password, |
8 | | - $database_port = $puppetdb::params::database_port, |
9 | | - $manage_database = $puppetdb::params::manage_database, |
10 | | - $manage_server = $puppetdb::params::manage_dbserver, |
11 | | - $manage_package_repo = $puppetdb::params::manage_pg_repo, |
12 | | - $postgres_version = $puppetdb::params::postgres_version, |
| 4 | + $listen_addresses = $puppetdb::params::database_host, |
| 5 | + $database_name = $puppetdb::params::database_name, |
| 6 | + $database_username = $puppetdb::params::database_username, |
| 7 | + $database_password = $puppetdb::params::database_password, |
| 8 | + $database_port = $puppetdb::params::database_port, |
| 9 | + $manage_database = $puppetdb::params::manage_database, |
| 10 | + $manage_server = $puppetdb::params::manage_dbserver, |
| 11 | + $manage_package_repo = $puppetdb::params::manage_pg_repo, |
| 12 | + $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 |
13 | 17 | ) inherits puppetdb::params { |
14 | 18 |
|
15 | 19 | if $manage_server { |
|
24 | 28 | port => scanf($database_port, '%i')[0], |
25 | 29 | } |
26 | 30 |
|
| 31 | + # configure PostgreSQL communication with Puppet Agent SSL certificates if |
| 32 | + # postgresql_ssl_on is set to true |
| 33 | + if $postgresql_ssl_on { |
| 34 | + file {'postgres private key': |
| 35 | + ensure => present, |
| 36 | + path => "${postgresql::params::datadir}/server.key", |
| 37 | + source => $postgresql_ssl_key_path, |
| 38 | + owner => 'postgres', |
| 39 | + mode => '0600', |
| 40 | + require => Package['postgresql-server'], |
| 41 | + } |
| 42 | + |
| 43 | + file {'postgres public key': |
| 44 | + ensure => present, |
| 45 | + path => "${postgresql::params::datadir}/server.crt", |
| 46 | + source => $postgresql_ssl_cert_path, |
| 47 | + owner => 'postgres', |
| 48 | + mode => '0600', |
| 49 | + require => Package['postgresql-server'], |
| 50 | + } |
| 51 | + |
| 52 | + postgresql::server::config_entry {'ssl': |
| 53 | + ensure => present, |
| 54 | + value => 'on', |
| 55 | + require => [File['postgres private key'], File['postgres public key']] |
| 56 | + } |
| 57 | + |
| 58 | + postgresql::server::config_entry {'ssl_cert_file': |
| 59 | + ensure => present, |
| 60 | + value => "${postgresql::params::datadir}/server.crt", |
| 61 | + require => [File['postgres private key'], File['postgres public key']] |
| 62 | + } |
| 63 | + |
| 64 | + postgresql::server::config_entry {'ssl_key_file': |
| 65 | + ensure => present, |
| 66 | + value => "${postgresql::params::datadir}/server.key", |
| 67 | + require => [File['postgres private key'], File['postgres public key']] |
| 68 | + } |
| 69 | + |
| 70 | + postgresql::server::config_entry {'ssl_ca_file': |
| 71 | + ensure => present, |
| 72 | + value => $postgresql_ssl_ca_cert_path, |
| 73 | + require => [File['postgres private key'], File['postgres public key']] |
| 74 | + } |
| 75 | + |
| 76 | + $identity_map_key = "${database_name}-${database_username}-map" |
| 77 | + |
| 78 | + postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as \ |
| 79 | +${database_username} (ipv4)": |
| 80 | + type => 'hostssl', |
| 81 | + database => $database_name, |
| 82 | + user => $database_username, |
| 83 | + address => '0.0.0.0/0', |
| 84 | + auth_method => 'cert', |
| 85 | + order => 0, |
| 86 | + auth_option => "map=${identity_map_key} clientcert=1" |
| 87 | + } |
| 88 | + |
| 89 | + postgresql::server::pg_hba_rule { "Allow certificate mapped connections to ${database_name} as \ |
| 90 | +${database_username} (ipv6)": |
| 91 | + type => 'hostssl', |
| 92 | + database => $database_name, |
| 93 | + user => $database_username, |
| 94 | + address => '::0/0', |
| 95 | + auth_method => 'cert', |
| 96 | + order => 0, |
| 97 | + auth_option => "map=${identity_map_key} clientcert=1" |
| 98 | + } |
| 99 | + |
| 100 | + postgresql::server::pg_ident_rule {"Map the SSL certificate of the server as a ${database_username} user": |
| 101 | + map_name => "${identity_map_key}", |
| 102 | + system_username => $fqdn, |
| 103 | + database_username => $database_username, |
| 104 | + } |
| 105 | + } |
| 106 | + |
27 | 107 | # Only install pg_trgm extension, if database it is actually managed by the module |
28 | 108 | if $manage_database { |
29 | 109 |
|
|
0 commit comments