Puppet Class: postfix

Inherits:
postfix::params
Defined in:
manifests/init.pp

Overview

multidomain mailserver www.rosehosting.com/blog/mailserver-with-virtual-users-and-domains-using-postfix-and-dovecot-on-a-centos-6-vps/

concat main.cf

00 - base 01 - transport 50 - vmail 51 - virtual aliases 52 - virtual_mailbox_maps 53 - virtual domains 54 - SASL 55 - smtpd restrictions 60 - content filter 61 - sender_canonical_maps 62 - header_checks

concat master.cf

00 - header 01 - smtp default 02 - other defaults

Parameters:

  • smtpdbanner (Any) (defaults to: "${::hostname} ESMTP")
  • mydestination (Any) (defaults to: [ $::fqdn, 'localhost' ])
  • mydomain (Any) (defaults to: $::domain)
  • myhostname (Any) (defaults to: $::hostname)
  • mynetworks (Any) (defaults to: [ '127.0.0.1' ])
  • myorigin (Any) (defaults to: $::domain)
  • inetinterfaces (Any) (defaults to: '127.0.0.1')
  • mail_spool_directory (Any) (defaults to: '/var/mail')
  • append_dot_mydomain (Any) (defaults to: undef)
  • biff (Any) (defaults to: false)
  • ipv6 (Any) (defaults to: false)
  • opportunistictls (Any) (defaults to: false)
  • recipient_delimiter (Any) (defaults to: undef)
  • relayhost (Any) (defaults to: undef)
  • relayhost_mx_lookup (Any) (defaults to: false)
  • generatecert (Any) (defaults to: false)
  • subjectselfsigned (Any) (defaults to: undef)
  • tlscert (Any) (defaults to: undef)
  • tlspk (Any) (defaults to: undef)
  • install_mailclient (Any) (defaults to: true)
  • default_process_limit (Any) (defaults to: '100')
  • smtpd_client_connection_count_limit (Any) (defaults to: '10')
  • smtpd_client_connection_rate_limit (Any) (defaults to: '30')
  • in_flow_delay (Any) (defaults to: '1s')
  • setgid_group (Any) (defaults to: $postfix::params::setgid_group_default)
  • readme_directory (Any) (defaults to: $postfix::params::readme_directory_default)
  • smtp_fallback_relay (Any) (defaults to: undef)
  • postfix_username_uid (Any) (defaults to: $postfix_username_uid_default)
  • postfix_username_gid (Any) (defaults to: $postfix_username_gid_default)
  • add_default_smtpd_instance (Any) (defaults to: true)
  • manage_mastercf (Any) (defaults to: $postfix::params::manage_mastercf_default)
  • resolve_null_domain (Any) (defaults to: true)
  • debug_peer_level (Any) (defaults to: '2')
  • debug_peer_list (Any) (defaults to: undef)
  • smtpd_verbose (Any) (defaults to: false)
  • syslog_name (Any) (defaults to: undef)
  • daemon_directory (Any) (defaults to: $postfix::params::daemon_directory_default)
  • unknown_local_recipient_reject_code (Any) (defaults to: '550')
  • postfix_username (Any) (defaults to: 'postfix')
  • home_mailbox (Any) (defaults to: 'Maildir/')
  • alias_maps (Any) (defaults to: '/etc/aliases')
  • data_directory (Any) (defaults to: '/var/lib/postfix')
  • service_ensure (Any) (defaults to: 'running')
  • service_enable (Any) (defaults to: true)
  • smtp_generic_maps (Any) (defaults to: "${postfix::params::baseconf}/generic_maps")
  • smtpd_reject_footer (Any) (defaults to: undef)
  • message_size_limit (Any) (defaults to: undef)
  • compatibility_level (Any) (defaults to: $postfix::params::compatibility_level_default)
  • mynetworks_style (Any) (defaults to: 'subnet')
  • smtpd_helo_required (Any) (defaults to: false)
  • disable_vrfy_command (Any) (defaults to: false)
  • smtp_sasl_auth_enable (Any) (defaults to: false)
  • smtp_sasl_security_options (Any) (defaults to: [ 'noplaintext', 'noanonymous' ])
  • smtpd_sasl_auth_enable (Any) (defaults to: false)
  • smtpd_use_tls (Any) (defaults to: false)
  • smtpd_tls_protocols (Any) (defaults to: [ '!SSLv2', '!SSLv3' ])
  • smtp_use_tls (Any) (defaults to: false)
  • smtp_tls_exclude_ciphers (Any) (defaults to: [])
  • smtpd_tls_mandatory_ciphers (Any) (defaults to: undef)
  • tls_medium_cipherlist (Any) (defaults to: [])
  • queue_run_delay (Any) (defaults to: undef)
  • minimal_backoff_time (Any) (defaults to: undef)
  • maximal_backoff_time (Any) (defaults to: undef)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'manifests/init.pp', line 26

class postfix (
                $smtpdbanner                         = "${::hostname} ESMTP",
                $mydestination                       = [ $::fqdn, 'localhost' ],
                $mydomain                            = $::domain,
                $myhostname                          = $::hostname,
                $mynetworks                          = [ '127.0.0.1' ],
                $myorigin                            = $::domain,
                $inetinterfaces                      = '127.0.0.1',
                $mail_spool_directory                = '/var/mail',
                $append_dot_mydomain                 = undef,
                $biff                                = false,
                $ipv6                                = false,
                $opportunistictls                    = false,
                $recipient_delimiter                 = undef,
                $relayhost                           = undef,
                $relayhost_mx_lookup                 = false,
                $generatecert                        = false,
                $subjectselfsigned                   = undef,
                $tlscert                             = undef,
                $tlspk                               = undef,
                $install_mailclient                  = true,
                $default_process_limit               = '100',
                $smtpd_client_connection_count_limit = '10',
                $smtpd_client_connection_rate_limit  = '30',
                $in_flow_delay                       = '1s',
                $setgid_group                        = $postfix::params::setgid_group_default,
                $readme_directory                    = $postfix::params::readme_directory_default,
                $smtp_fallback_relay                 = undef,
                $postfix_username_uid                = $postfix_username_uid_default,
                $postfix_username_gid                = $postfix_username_gid_default,
                $add_default_smtpd_instance          = true,
                $manage_mastercf                     = $postfix::params::manage_mastercf_default,
                $resolve_null_domain                 = true,
                $debug_peer_level                    = '2',
                $debug_peer_list                     = undef,
                $smtpd_verbose                       = false,
                $syslog_name                         = undef,
                $daemon_directory                    = $postfix::params::daemon_directory_default,
                $unknown_local_recipient_reject_code = '550',
                $postfix_username                    = 'postfix',
                $home_mailbox                        = 'Maildir/',
                $alias_maps                          = '/etc/aliases',
                $data_directory                      = '/var/lib/postfix',
                $service_ensure                      = 'running',
                $service_enable                      = true,
                $smtp_generic_maps                   = "${postfix::params::baseconf}/generic_maps",
                $smtpd_reject_footer                 = undef,
                $message_size_limit                  = undef, # @param message_size_limit The maximal size in bytes of a message, including envelope information. (default: undef)
                $compatibility_level                 = $postfix::params::compatibility_level_default,
                $mynetworks_style                    = 'subnet',
                $smtpd_helo_required                 = false,
                $disable_vrfy_command                = false,
                $smtp_sasl_auth_enable               = false,
                $smtp_sasl_security_options          = [ 'noplaintext', 'noanonymous' ],
                $smtpd_sasl_auth_enable              = false,
                $smtpd_use_tls                       = false,
                $smtpd_tls_protocols                 = [ '!SSLv2', '!SSLv3' ],
                $smtp_use_tls                        = false,
                $smtp_tls_exclude_ciphers            = [],
                $smtpd_tls_mandatory_ciphers         = undef,
                $tls_medium_cipherlist               = [],
                $queue_run_delay                     = undef,
                $minimal_backoff_time                = undef,
                $maximal_backoff_time                = undef,
              ) inherits postfix::params {

  Exec {
    path => '/bin:/sbin:/usr/bin:/usr/sbin',
  }

  validate_array($mynetworks)

  if($biff)
  {
    validate_bool($biff)
  }

  if($append_dot_mydomain)
  {
    validate_bool($append_dot_mydomain)
  }

  if($readme_directory)
  {
    validate_string($readme_directory)
  }

  validate_string($myorigin)

  validate_string($mydomain)

  if($recipient_delimiter)
  {
    validate_string($recipient_delimiter)
  }

  validate_array($mydestination)

  if($smtp_fallback_relay!=undef)
  {
    validate_array($smtp_fallback_relay)
  }

  validate_re($home_mailbox, [ '^Maildir/$', '^Mailbox$', '^$' ], 'Not a supported home_mailbox - valid values: Mailbox, Maildir/ or empty string')

  user { $postfix_username:
    ensure  => 'present',
    uid     => $postfix_username_uid,
    gid     => $postfix_username_gid,
    require => Group[$postfix_username],
  }

  group { $postfix_username:
    ensure  => 'present',
    gid     => $postfix_username_gid,
    require => Package[$postfix::params::package_name],
  }

  if($tlscert) or ($tlspk) or ($opportunistictls)
  {

    exec { 'postfix mkdir /etc/pki/tls/private':
      command => 'mkdir -p /etc/pki/tls/private',
      creates => '/etc/pki/tls/private',
    }

    exec { 'postfix mkdir /etc/pki/tls/certs':
      command => 'mkdir -p /etc/pki/tls/certs',
      creates => '/etc/pki/tls/certs',
    }

    exec { 'eyp-postfix which openssl':
      command => 'which openssl',
      unless  => 'which openssl',
      require => Exec[ ['postfix mkdir /etc/pki/tls/certs', 'postfix mkdir /etc/pki/tls/certs' ] ]
    }

    if($generatecert)
    {
      if($subjectselfsigned)
      {
        exec { 'openssl pk':
          command => 'openssl genrsa -out /etc/pki/tls/private/postfix-key.key 2048',
          creates => '/etc/pki/tls/private/postfix-key.key',
          require => Exec['eyp-postfix which openssl'],
        }

        exec { 'openssl cert':
          command => "openssl req -new -key /etc/pki/tls/private/postfix-key.key -subj '${subjectselfsigned}' | openssl x509 -req -days 10000 -signkey /etc/pki/tls/private/postfix-key.key -out /etc/pki/tls/certs/postfix.pem",
          unless  => "openssl x509 -in /etc/pki/tls/certs/postfix.pem -noout -subject | grep '${subjectselfsigned}'",
          notify  => Class['postfix::service'],
          require => Exec['openssl pk'],
        }
      }
      else
      {
        fail('to generate a selfsigned certificate I need a subject (variable subjectselfsigned)')
      }
    }
    else
    {
      if ($subjectselfsigned)
      {
        fail('you need to enable selfsigned certificates using the variable generatecert')
      }

      if($tlscert==undef) or ($tlspk==undef) or ($opportunistictls==undef)
      {
        fail("everytime you forget required a TLS file, God kills a kitten - OTLS(${opportunistictls}) - CERT(${tlscert}) - KEY(${tlspk}) - please think of the kittens")
      }
      else
      {
        file { '/etc/pki/tls/private/postfix-key.key':
          ensure  => present,
          owner   => 'root',
          group   => 'root',
          mode    => '0644',
          require => Exec['eyp-postfix which openssl'],
          notify  => Class['postfix::service'],
          audit   => 'content',
          source  => $tlspk
        }

        file { '/etc/pki/tls/certs/postfix.pem':
          ensure  => present,
          owner   => 'root',
          group   => 'root',
          mode    => '0644',
          require => Exec['eyp-postfix which openssl'],
          notify  => Class['postfix::service'],
          audit   => 'content',
          source  => $tlscert
        }
      }
    }
  }

  if($install_mailclient)
  {
    package { $postfix::params::mailclient:
      ensure => 'installed',
      before => Package[$postfix::params::package_name],
    }
  }

  if($postfix::params::purge_default_mta!=undef)
  {
    package { $postfix::params::purge_default_mta:
      ensure  => 'absent',
      require => Package[$postfix::params::package_name],
    }
  }

  package { $postfix::params::package_name:
    ensure => 'installed',
  }

  #data_directory
  file { $data_directory:
    ensure  => 'directory',
    owner   => $postfix_username,
    group   => $postfix_username,
    mode    => '0755',
    require => Package[$postfix::params::package_name],
  }

  concat { '/etc/postfix/main.cf':
    ensure  => present,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package[$postfix::params::package_name],
    notify  => Class['postfix::service'],
  }

  concat::fragment{ '/etc/postfix/main.cf base':
    target  => '/etc/postfix/main.cf',
    order   => '00',
    content => template("${module_name}/main.cf.erb"),
  }

  class { 'postfix::service':
    ensure         => $service_ensure,
    enable         => $service_enable,
    manage_service => true,
  }

  if($postfix::params::switch_to_postfix)
  {
    exec { 'switch_mta_to_postfix':
      command => $postfix::params::switch_to_postfix,
      unless  => $postfix::params::check_postfix_mta,
      require => Package[$postfix::params::package_name],
    }
  }

  #
  # smtp_generic_maps
  #

  exec { 'reload postfix smtp_generic_maps':
    command     => "postmap ${smtp_generic_maps}",
    refreshonly => true,
    notify      => Class['postfix::service'],
    require     => [ Package[$postfix::params::package_name], Concat[$smtp_generic_maps] ],
  }

  concat { $smtp_generic_maps:
    ensure  => 'present',
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package[$postfix::params::package_name],
    notify  => Exec['reload postfix smtp_generic_maps'],
  }

  concat::fragment{ "${smtp_generic_maps} header":
    target  => $smtp_generic_maps,
    order   => '00',
    content => template("${module_name}/header.erb"),
  }

  #
  # alias maps
  #

  exec { 'reload postfix local aliases':
    command     => "newaliases -oA${alias_maps}",
    refreshonly => true,
    notify      => [ File["${alias_maps}.db"], Class['postfix::service']],
    require     => [ Package[$postfix::params::package_name], Concat[$alias_maps] ],
  }

  file { "${alias_maps}.db":
    ensure  => file,
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    seltype => 'etc_aliases_t',
  }

  concat { $alias_maps:
    ensure  => 'present',
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package[$postfix::params::package_name],
    notify  => Exec['reload postfix local aliases'],
  }

  concat::fragment{ "${postfix::alias_maps} header":
    target  => $alias_maps,
    order   => '00',
    content => template("${module_name}/aliases/header.erb"),
  }

  concat::fragment{ "${postfix::alias_maps} base":
    target  => $alias_maps,
    order   => '01',
    content => template("${module_name}/aliases/aliases_base.erb"),
  }

  if($manage_mastercf)
  {
    #
    # master.cf
    #

    concat { '/etc/postfix/master.cf':
      ensure  => 'present',
      owner   => 'root',
      group   => 'root',
      mode    => '0644',
      require => Package[$postfix::params::package_name],
      notify  => Class['::postfix::service'],
    }

    concat::fragment{ '/etc/postfix/master.cf header':
      target  => '/etc/postfix/master.cf',
      order   => '00',
      content => template("${module_name}/mastercf/header.erb"),
    }

    if($smtpd_verbose)
    {
      $smtpd_instance_args='-v'
    }
    else
    {
      $smtpd_instance_args=undef
    }

    class { '::postfix::mastercf':
      add_default_smtpd_instance => $add_default_smtpd_instance,
      default_smtpd_args         => $smtpd_instance_args,
    }
  }
}