]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add ssl certificate for postgresql connection
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 27 Jun 2018 11:10:32 +0000 (13:10 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 27 Jun 2018 11:12:14 +0000 (13:12 +0200)
modules/role/manifests/backup/postgresql.pp
modules/role/templates/backup/postgresql.conf.erb

index aef177b776a64b1bf30ee75639e015ba72f611ba..ee62a0022ed2fb3efdacd480f8d734780904ed18 100644 (file)
@@ -121,16 +121,38 @@ class role::backup::postgresql inherits role::backup {
     } else {
       $pg_backup_host = $host["vars"]["real_hostname"][0]
     }
+
+    $pg_path = "$mountpoint/$pg_backup_host/postgresql"
+    $pg_backup_path = "$mountpoint/$pg_backup_host/postgresql_backup"
+    $pg_host = "$pg_backup_host"
+    $pg_port = $pg_infos["dbport"]
+
     if has_key($host["vars"], "postgresql_backup_port") {
       $pg_listen_port = $host["vars"]["postgresql_backup_port"][0]
+      file { "$pg_path/certs":
+        ensure => directory,
+        mode   => "0700",
+        owner  => $pg_user,
+        group  => $pg_group,
+      } ->
+      ssl::self_signed_certificate { $backup_host_cn:
+        common_name  => $backup_host_cn,
+        country      => "FR",
+        days         => "3650",
+        organization => "Immae",
+        owner        => $pg_user,
+        group        => $pg_group,
+        directory    => "$pg_path/certs",
+        before       => File["$pg_path/postgresql.conf"],
+      }
+      $ssl_key  = "$pg_path/certs/$backup_host_cn.key"
+      $ssl_cert = "$pg_path/certs/$backup_host_cn.crt"
     } else {
       $pg_listen_port = undef
+      $ssl_key = undef
+      $ssl_cert = undef
     }
 
-    $pg_path = "$mountpoint/$pg_backup_host/postgresql"
-    $pg_backup_path = "$mountpoint/$pg_backup_host/postgresql_backup"
-    $pg_host = "$pg_backup_host"
-    $pg_port = $pg_infos["dbport"]
 
     unless empty($host) {
       $host["ipHostNumber"].each |$ip| {
index c4d223e8bace6bef6c362b1af2ea439e4350a26c..8741507bef335eff402d36e7a834a4f48eb253dd 100644 (file)
@@ -2,6 +2,8 @@
 listen_addresses= '*'
 port = <%= @pg_listen_port %>
 ssl = on
+ssl_key_file = '<%= @ssl_key %>'
+ssl_cert_file = '<%= @ssl_cert %>'
 <%- else -%>
 listen_addresses= ''
 <%- end %>