Skip to content

Commit dbd2d55

Browse files
committed
Add mailserver module
1 parent d6388c8 commit dbd2d55

12 files changed

+335
-0
lines changed

modules/mailmx.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2019 dhtech
2+
#
3+
# Use of this source code is governed by a BSD-style
4+
# license that can be found in the LICENSE file
5+
6+
7+
def generate(host, *args):
8+
9+
info = {}
10+
info['ldap_uri'] = 'ldaps://ldap3.tech.dreamhack.se',
11+
info['postfix_destinations'] = [
12+
'localhost',
13+
'mail.tech.dreamhack.se',
14+
'tech.dreamhack.se',
15+
'lists.tech.dreamhack.se',
16+
'event.dreamhack.se',
17+
]
18+
info['postfix_networks'] = [
19+
'127.0.0.0/8',
20+
'[::ffff:127.0.0.0]/104',
21+
'[::1]/128',
22+
'77.80.228.128/25',
23+
'77.80.231.0/24',
24+
]
25+
return {'mailmx': info}
26+
27+
# vim: ts=4: sts=4: sw=4: expandtab

modules/mailmx/manifests/init.pp

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright 2019 dhtech
2+
#
3+
# Use of this source code is governed by a BSD-style
4+
# license that can be found in the LICENSE file
5+
#
6+
# == Class: mailmx
7+
#
8+
# This module manages the rancid server which fetches and saves configuration
9+
# in the core and dist service.
10+
#
11+
# === Parameters
12+
#
13+
# [*postfix_networks*]
14+
# Decides how postfix will be used.
15+
# [*postfix_destinations*]
16+
# Decides how postfix will be used.
17+
#
18+
19+
class mailmx($ldap_uri, $postfix_networks, $postfix_destinations) {
20+
21+
#
22+
# Postfix
23+
#
24+
package { ['postfix', 'postfix-ldap', 'postfix-sqlite']:
25+
ensure => installed,
26+
}
27+
28+
file { '/etc/postfix/main.cf':
29+
ensure => file,
30+
content => template('mailmx/postfix/main.cf.erb'),
31+
notify => Service['postfix'],
32+
require => Package['postfix'],
33+
}
34+
35+
file { '/etc/postfix/dynamicmaps.cf':
36+
ensure => file,
37+
content => template('mailmx/postfix/dynamicmaps.cf.erb'),
38+
}
39+
40+
file { '/etc/postfix/ldap-lists-stage1.cf':
41+
ensure => file,
42+
content => template('mailmx/postfix/ldap-lists-stage1.cf.erb'),
43+
}
44+
45+
file { '/etc/postfix/ldap-lists-stage2.cf':
46+
ensure => file,
47+
content => template('mailmx/postfix/ldap-lists-stage2.cf.erb'),
48+
}
49+
50+
file { '/etc/postfix/ldap-people.cf':
51+
ensure => file,
52+
content => template('mailmx/postfix/ldap-people.cf.erb'),
53+
}
54+
55+
file { '/etc/postfix/pfix-no-srs.cf':
56+
ensure => file,
57+
content => template('mailmx/postfix/pfix-no-srs.cf.erb'),
58+
notify => Exec['postmap-pfix-no-srs'],
59+
}
60+
61+
exec { 'postmap-pfix-no-srs':
62+
refreshonly => true,
63+
command => '/usr/sbin/postmap /etc/postfix/pfix-no-srs.cf',
64+
}
65+
66+
file { '/etc/postfix/transport':
67+
ensure => file,
68+
content => template('mailmx/postfix/transport.erb'),
69+
notify => Exec['postmap-transport'],
70+
}
71+
72+
exec { 'postmap-transport':
73+
refreshonly => true,
74+
command => '/usr/sbin/postmap /etc/postfix/transport',
75+
}
76+
77+
service { 'postfix':
78+
ensure => 'running',
79+
name => 'postfix',
80+
enable => true,
81+
require => Package['postfix'],
82+
}
83+
84+
#
85+
# Dovecot
86+
#
87+
package { ['dovecot-core', 'dovecot-imapd']:
88+
ensure => installed,
89+
}
90+
91+
file { '/etc/dovecot/dovecot.conf':
92+
ensure => file,
93+
content => template('mailmx/dovecot/dovecot.conf.erb'),
94+
notify => Service['dovecot'],
95+
}
96+
97+
file { '/etc/pam.d/dovecot':
98+
ensure => file,
99+
content => template('mailmx/dovecot/dovecot.pam.erb'),
100+
}
101+
102+
service { 'dovecot':
103+
ensure => 'running',
104+
name => 'dovecot',
105+
enable => true,
106+
require => Package['dovecot-core'],
107+
}
108+
109+
}

modules/mailmx/metadata.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "dhtech-mailmx",
3+
"version": "0.1.0",
4+
"author": "dhtech",
5+
"summary": "This module manages a mailserver (SMTP and IMAP)",
6+
"license": "Apache 2.0",
7+
"source": "",
8+
"project_page": null,
9+
"issues_url": null,
10+
"dependencies": [
11+
{"name":"puppetlabs/stdlib","version_requirement":">= 1.0.0"}
12+
]
13+
}
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
# generated with `dovecot -n` to show settings that differ
5+
# from defaults
6+
7+
# 2.2.27 (c0f36b0): /etc/dovecot/dovecot.conf
8+
# Pigeonhole version 0.4.16 (fed8554)
9+
# OS: Linux 4.9.0-7-686-pae i686 Debian 9.7 ext4
10+
listen = *, [::]
11+
log_timestamp = "%Y-%m-%d %H:%M:%S "
12+
13+
mail_location = mbox:/var/mbox/%u:INBOX=/var/mail/%u
14+
mail_privileged_group = mail
15+
16+
passdb {
17+
driver = pam
18+
}
19+
20+
protocols = imap
21+
22+
protocol pop3 {
23+
pop3_uidl_format = %08Xu%08Xv
24+
}
25+
26+
service auth {
27+
user = root
28+
}
29+
30+
service imap-login {
31+
inet_listener imap {
32+
port = 0
33+
}
34+
}
35+
36+
ssl_cert = </etc/ssl/certs/server.crt
37+
ssl_key = </etc/ssl/private/server.key
38+
39+
userdb {
40+
driver = passwd
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
#
4+
# /etc/pam.d/dovecot - authentication for dovecot
5+
#
6+
#%PAM-1.0
7+
8+
@include common-auth
9+
@include common-account
10+
@include common-session
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
# Postfix dynamic maps configuration file.
5+
#
6+
# The first match found is the one that is used. Wildcards are not supported
7+
# as of postfix 2.0.2
8+
#
9+
#type location of .so file open function (mkmap func)
10+
#==== ================================ ============= ============
11+
ldap postfix-ldap.so dict_ldap_open
12+
sqlite postfix-sqlite.so dict_sqlite_open
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
# The purpose of this stage is to rewrite incoming dhtech@tech
5+
# to a temporary [email protected] that is handled by
6+
# our python hack in /usr/local/bin/listmgmr
7+
8+
server_host = ldaps://ldap3.tech.dreamhack.se
9+
tls_ca_cert_file = /etc/ssl/dhtech-ca.crt
10+
tls_require_cert = yes
11+
version = 3
12+
search_base = dc=dreamhack,dc=se
13+
14+
query_filter = cn=%s-mail
15+
result_attribute = cn
16+
result_format = %[email protected]
17+
root@mail:/etc/postfix# cat ldap-people.cf
18+
# Handle personal email forwarding
19+
20+
server_host = ldaps://ldap3.tech.dreamhack.se
21+
tls_ca_cert_file = /etc/ssl/dhtech-ca.crt
22+
tls_require_cert = yes
23+
version = 3
24+
search_base = ou=people,dc=tech,dc=dreamhack,dc=se
25+
26+
query_filter = uid=%s
27+
result_attribute = gosaMailForwardingAddress
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
# This stage handles the return traffic that has gone through
5+
# /usr/local/bin/listmgmr to send out to the actual recipients.
6+
# Since we only want to handle groups that have been processed,
7+
# limit to cn=*-mail.
8+
9+
server_host = ldaps://ldap3.tech.dreamhack.se
10+
tls_ca_cert_file = /etc/ssl/dhtech-ca.crt
11+
tls_require_cert = yes
12+
version = 3
13+
search_base = dc=dreamhack,dc=se
14+
15+
query_filter = (&(cn=%s)(cn=*-mail))
16+
special_result_attribute = member
17+
result_attribute = uid
18+
result_format = %[email protected]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
# Handle personal email forwarding
5+
6+
server_host = <%= @ldap_uri %>
7+
tls_ca_cert_file = /etc/ssl/dhtech-ca.crt
8+
tls_require_cert = yes
9+
version = 3
10+
search_base = ou=people,dc=tech,dc=dreamhack,dc=se
11+
12+
query_filter = uid=%s
13+
result_attribute = gosaMailForwardingAddress
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
5+
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
6+
biff = no
7+
8+
# appending .domain is the MUA's job.
9+
append_dot_mydomain = no
10+
11+
# Uncomment the next line to generate "delayed mail" warnings
12+
#delay_warning_time = 4h
13+
14+
readme_directory = no
15+
16+
# TLS parameters
17+
smtpd_tls_cert_file=/etc/ssl/certs/server.crt
18+
smtpd_tls_key_file=/etc/ssl/private/server.key
19+
smtpd_use_tls=yes
20+
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
21+
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
22+
23+
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
24+
# information on enabling SSL in the smtp client.
25+
26+
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
27+
myhostname = <%= @fqdn %>
28+
alias_maps = hash:/etc/aliases, ldap:/etc/postfix/ldap-people.cf, ldap:/etc/postfix/ldap-lists-stage1.cf, ldap:/etc/postfix/ldap-lists-stage2.cf
29+
30+
virtual_mailbox_domains =
31+
virtual_alias_maps = ldap:/etc/postfix/ldap-people.cf, ldap:/etc/postfix/ldap-lists-stage1.cf
32+
33+
alias_database = hash:/etc/aliases
34+
myorigin = /etc/mailname
35+
mydestination = <%= @postfix_destinations.join(', ') %>
36+
relayhost =
37+
mynetworks = <%= @postfix_networks.join(' ') %>
38+
mailbox_size_limit = 0
39+
recipient_delimiter = +
40+
inet_interfaces = all
41+
42+
# SRS for SPF forwarding
43+
recipient_canonical_maps = hash:/etc/postfix/pfix-no-srs.cf, tcp:127.0.0.1:10002
44+
recipient_canonical_classes = envelope_recipient
45+
sender_canonical_maps = hash:/etc/postfix/pfix-no-srs.cf, tcp:127.0.0.1:10001
46+
sender_canonical_classes = envelope_sender
47+
48+
transport_maps = hash:/etc/postfix/transport
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
5+
6+
7+
8+
9+
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# AUTOGENERATED BY PUPPET
2+
# All manual changes will be overwritten
3+
4+
lists.tech.dreamhack.se listmgmr:dummy
5+
.lists.tech.dreamhack.se listmgmr:dummy
6+
* :

0 commit comments

Comments
 (0)