beforeservice.pp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # Class: postgresql::config::beforeservice
  2. #
  3. # Parameters:
  4. #
  5. # [*ip_mask_deny_postgres_user*] - ip mask for denying remote access for postgres user; defaults to '0.0.0.0/0',
  6. # meaning that all TCP access for postgres user is denied.
  7. # [*ip_mask_allow_all_users*] - ip mask for allowing remote access for other users (besides postgres);
  8. # defaults to '127.0.0.1/32', meaning only allow connections from localhost
  9. # [*listen_addresses*] - what IP address(es) to listen on; comma-separated list of addresses; defaults to
  10. # 'localhost', '*' = all
  11. # [*ipv4acls*] - list of strings for access control for connection method, users, databases, IPv4
  12. # addresses; see postgresql documentation about pg_hba.conf for information
  13. # [*ipv6acls*] - list of strings for access control for connection method, users, databases, IPv6
  14. # addresses; see postgresql documentation about pg_hba.conf for information
  15. # [*pg_hba_conf_path*] - path to pg_hba.conf file
  16. # [*postgresql_conf_path*] - path to postgresql.conf file
  17. # [*manage_redhat_firewall*] - boolean indicating whether or not the module should open a port in the firewall on
  18. # redhat-based systems; this parameter is likely to change in future versions. Possible
  19. # changes include support for non-RedHat systems and finer-grained control over the
  20. # firewall rule (currently, it simply opens up the postgres port to all TCP connections).
  21. #
  22. # Actions:
  23. #
  24. # Requires:
  25. #
  26. # Usage:
  27. # This class is not intended to be used directly; it is
  28. # managed by postgresl::config. It contains resources
  29. # that should be handled *before* the postgres service
  30. # has been started up.
  31. #
  32. # class { 'postgresql::config::before_service':
  33. # ip_mask_allow_all_users => '0.0.0.0/0',
  34. # }
  35. #
  36. class postgresql::config::beforeservice(
  37. $pg_hba_conf_path,
  38. $postgresql_conf_path,
  39. $ip_mask_deny_postgres_user = $postgresql::params::ip_mask_deny_postgres_user,
  40. $ip_mask_allow_all_users = $postgresql::params::ip_mask_allow_all_users,
  41. $listen_addresses = $postgresql::params::listen_addresses,
  42. $ipv4acls = $postgresql::params::ipv4acls,
  43. $ipv6acls = $postgresql::params::ipv6acls,
  44. $manage_redhat_firewall = $postgresql::params::manage_redhat_firewall
  45. ) inherits postgresql::params {
  46. File {
  47. owner => $postgresql::params::user,
  48. group => $postgresql::params::group,
  49. }
  50. # We use a templated version of pg_hba.conf. Our main needs are to
  51. # make sure that md5 authentication can be made available for
  52. # remote hosts.
  53. file { 'pg_hba.conf':
  54. ensure => file,
  55. path => $pg_hba_conf_path,
  56. content => template('postgresql/pg_hba.conf.erb'),
  57. notify => Exec['reload_postgresql'],
  58. }
  59. # We must set a "listen_addresses" line in the postgresql.conf if we
  60. # want to allow any connections from remote hosts.
  61. file_line { 'postgresql.conf#listen_addresses':
  62. path => $postgresql_conf_path,
  63. match => '^listen_addresses\s*=.*$',
  64. line => "listen_addresses = '${listen_addresses}'",
  65. notify => Service['postgresqld'],
  66. }
  67. # Here we are adding an 'include' line so that users have the option of
  68. # managing their own settings in a second conf file.
  69. file_line { 'postgresql.conf#include':
  70. path => $postgresql_conf_path,
  71. line => 'include \'postgresql_puppet_extras.conf\'',
  72. notify => Service['postgresqld'],
  73. }
  74. # Since we're adding an "include" for this extras config file, we need
  75. # to make sure it exists.
  76. exec { "touch `dirname ${postgresql_conf_path}`/postgresql_puppet_extras.conf" :
  77. path => '/usr/bin:/bin',
  78. unless => "[ -f `dirname ${postgresql_conf_path}`/postgresql_puppet_extras.conf ]"
  79. }
  80. # TODO: is this a reasonable place for this firewall stuff?
  81. # TODO: figure out a way to make this not platform-specific; debian and ubuntu have
  82. # an out-of-the-box firewall configuration that seems trickier to manage
  83. # TODO: get rid of hard-coded port
  84. if ($manage_redhat_firewall and $firewall_supported) {
  85. exec { 'postgresql-persist-firewall':
  86. command => $persist_firewall_command,
  87. refreshonly => true,
  88. }
  89. Firewall {
  90. notify => Exec['postgresql-persist-firewall']
  91. }
  92. firewall { '5432 accept - postgres':
  93. port => '5432',
  94. proto => 'tcp',
  95. action => 'accept',
  96. }
  97. }
  98. }