config.pp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # PRIVATE CLASS: do not call directly
  2. class postgresql::server::config {
  3. $ip_mask_deny_postgres_user = $postgresql::server::ip_mask_deny_postgres_user
  4. $ip_mask_allow_all_users = $postgresql::server::ip_mask_allow_all_users
  5. $listen_addresses = $postgresql::server::listen_addresses
  6. $port = $postgresql::server::port
  7. $ipv4acls = $postgresql::server::ipv4acls
  8. $ipv6acls = $postgresql::server::ipv6acls
  9. $pg_hba_conf_path = $postgresql::server::pg_hba_conf_path
  10. $pg_ident_conf_path = $postgresql::server::pg_ident_conf_path
  11. $postgresql_conf_path = $postgresql::server::postgresql_conf_path
  12. $pg_hba_conf_defaults = $postgresql::server::pg_hba_conf_defaults
  13. $user = $postgresql::server::user
  14. $group = $postgresql::server::group
  15. $version = $postgresql::server::version
  16. $manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf
  17. $manage_pg_ident_conf = $postgresql::server::manage_pg_hba_conf
  18. if ($manage_pg_hba_conf == true) {
  19. # Prepare the main pg_hba file
  20. concat { $pg_hba_conf_path:
  21. owner => $user,
  22. group => $group,
  23. mode => '0640',
  24. warn => true,
  25. notify => Class['postgresql::server::reload'],
  26. }
  27. if $pg_hba_conf_defaults {
  28. Postgresql::Server::Pg_hba_rule {
  29. database => 'all',
  30. user => 'all',
  31. }
  32. # Lets setup the base rules
  33. $local_auth_option = $version ? {
  34. '8.1' => 'sameuser',
  35. default => undef,
  36. }
  37. postgresql::server::pg_hba_rule { 'local access as postgres user':
  38. type => 'local',
  39. user => $user,
  40. auth_method => 'ident',
  41. auth_option => $local_auth_option,
  42. order => '001',
  43. }
  44. postgresql::server::pg_hba_rule { 'local access to database with same name':
  45. type => 'local',
  46. auth_method => 'ident',
  47. auth_option => $local_auth_option,
  48. order => '002',
  49. }
  50. postgresql::server::pg_hba_rule { 'allow localhost TCP access to postgresql user':
  51. type => 'host',
  52. user => $user,
  53. address => '127.0.0.1/32',
  54. auth_method => 'md5',
  55. order => '003',
  56. }
  57. postgresql::server::pg_hba_rule { 'deny access to postgresql user':
  58. type => 'host',
  59. user => $user,
  60. address => $ip_mask_deny_postgres_user,
  61. auth_method => 'reject',
  62. order => '004',
  63. }
  64. # ipv4acls are passed as an array of rule strings, here we transform
  65. # them into a resources hash, and pass the result to create_resources
  66. $ipv4acl_resources = postgresql_acls_to_resources_hash($ipv4acls,
  67. 'ipv4acls', 10)
  68. create_resources('postgresql::server::pg_hba_rule', $ipv4acl_resources)
  69. postgresql::server::pg_hba_rule { 'allow access to all users':
  70. type => 'host',
  71. address => $ip_mask_allow_all_users,
  72. auth_method => 'md5',
  73. order => '100',
  74. }
  75. postgresql::server::pg_hba_rule { 'allow access to ipv6 localhost':
  76. type => 'host',
  77. address => '::1/128',
  78. auth_method => 'md5',
  79. order => '101',
  80. }
  81. # ipv6acls are passed as an array of rule strings, here we transform
  82. # them into a resources hash, and pass the result to create_resources
  83. $ipv6acl_resources = postgresql_acls_to_resources_hash($ipv6acls,
  84. 'ipv6acls', 102)
  85. create_resources('postgresql::server::pg_hba_rule', $ipv6acl_resources)
  86. }
  87. }
  88. # We must set a "listen_addresses" line in the postgresql.conf if we
  89. # want to allow any connections from remote hosts.
  90. postgresql::server::config_entry { 'listen_addresses':
  91. value => $listen_addresses,
  92. }
  93. postgresql::server::config_entry { 'port':
  94. value => $port,
  95. }
  96. # RedHat-based systems hardcode some PG* variables in the init script, and need to be overriden
  97. # in /etc/sysconfig/pgsql/postgresql. Create a blank file so we can manage it with augeas later.
  98. if ($::osfamily == 'RedHat') and ($::operatingsystemrelease !~ /^7/) and ($::operatingsystem != 'Fedora') {
  99. file { '/etc/sysconfig/pgsql/postgresql':
  100. ensure => present,
  101. replace => false,
  102. }
  103. }
  104. if ($manage_pg_ident_conf == true) {
  105. concat { $pg_ident_conf_path:
  106. owner => $user,
  107. group => $group,
  108. force => true, # do not crash if there is no pg_ident_rules
  109. mode => '0640',
  110. warn => true,
  111. notify => Class['postgresql::server::reload'],
  112. }
  113. }
  114. }