1 class role::cryptoportfolio::postgresql inherits role::cryptoportfolio {
2 $password_seed = lookup("base_installation::puppet_pass_seed")
4 $pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
5 $pg_replication_password = generate_password(24, $password_seed, "postgres_cryptoportfolio_replication")
7 file { "/var/lib/postgres/data/certs":
10 owner => $::profile::postgresql::pg_user,
11 group => $::profile::postgresql::pg_user,
12 require => File["/var/lib/postgres"],
15 file { "/var/lib/postgres/data/certs/cert.pem":
16 source => "file:///etc/letsencrypt/live/$web_host/cert.pem",
19 owner => $::profile::postgresql::pg_user,
20 group => $::profile::postgresql::pg_user,
21 require => [Letsencrypt::Certonly[$web_host], File["/var/lib/postgres/data/certs"]]
24 file { "/var/lib/postgres/data/certs/privkey.pem":
25 source => "file:///etc/letsencrypt/live/$web_host/privkey.pem",
28 owner => $::profile::postgresql::pg_user,
29 group => $::profile::postgresql::pg_user,
30 require => [Letsencrypt::Certonly[$web_host], File["/var/lib/postgres/data/certs"]]
33 postgresql::server::config_entry { "wal_level":
37 postgresql::server::config_entry { "ssl":
39 require => Letsencrypt::Certonly[$web_host],
42 postgresql::server::config_entry { "ssl_cert_file":
43 value => "/var/lib/postgres/data/certs/cert.pem",
44 require => Letsencrypt::Certonly[$web_host],
47 postgresql::server::config_entry { "ssl_key_file":
48 value => "/var/lib/postgres/data/certs/privkey.pem",
49 require => Letsencrypt::Certonly[$web_host],
52 postgresql::server::db { $pg_db:
54 password => postgresql_password($pg_user, $pg_password),
57 postgresql_psql { "CREATE PUBLICATION ${pg_db}_publication FOR ALL TABLES":
59 unless => "SELECT 1 FROM pg_catalog.pg_publication WHERE pubname = '${pg_db}_publication'",
62 postgresql::server::role { $pg_user_replication:
65 password_hash => postgresql_password($pg_user_replication, $pg_replication_password),
68 postgresql::server::database_grant { $pg_user_replication:
70 privilege => "CONNECT",
71 role => $pg_user_replication,
74 postgresql::server::grant { "all tables in schema:public:$pg_user_replication":
76 role => $pg_user_replication,
77 privilege => "SELECT",
78 object_type => "ALL TABLES IN SCHEMA",
79 object_name => "public",
82 postgresql::server::grant { "all sequences in schema:public:$pg_user_replication":
84 role => $pg_user_replication,
85 privilege => "SELECT",
86 object_type => "ALL SEQUENCES IN SCHEMA",
87 object_name => "public",
90 postgresql::server::pg_hba_rule { 'allow localhost TCP access to cryptoportfolio user':
94 address => '127.0.0.1/32',
98 postgresql::server::pg_hba_rule { 'allow localhost ip6 TCP access to cryptoportfolio user':
102 address => '::1/128',
103 auth_method => 'md5',
107 postgresql::server::pg_hba_rule { 'allow TCP access to replication user from immae.eu for replication':
109 database => 'replication',
110 user => $pg_user_replication,
111 address => 'immae.eu',
112 auth_method => 'md5',
116 postgresql::server::pg_hba_rule { 'allow TCP access to replication user from immae.eu':
119 user => $pg_user_replication,
120 address => 'immae.eu',
121 auth_method => 'md5',