Skip to content

Commit 2bd9b1b

Browse files
slash3gcimbalo
authored andcommitted
[WIP] Postfix+Dovecot
1 parent 30de0fb commit 2bd9b1b

8 files changed

Lines changed: 341 additions & 0 deletions

File tree

mail_server.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- hosts: biff
3+
roles:
4+
- role: lxc_guest
5+
vm_name: mail
6+
- hosts: mail
7+
roles:
8+
- role: postfix
9+
ldap_server: "{{ hostvars['ldap'].ansible_host }}"
10+
fqdn_domain: "lilik.it"

roles/postfix/handlers/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: restart_postfix
2+
service: name=postfix state=restarted
3+
4+
- name: restart_dovecot
5+
service: name=dovecot state=restarted

roles/postfix/tasks/main.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
- name: configure Postfix (domain)
2+
debconf:
3+
name: 'postfix'
4+
question: 'postfix/domainpostfix/main_mailer_type'
5+
vtype: 'string'
6+
value: 'Internet Site'
7+
- name: configure Postfix (organization)
8+
debconf:
9+
name: 'postfix'
10+
question: 'postfix/mailname'
11+
vtype: 'string'
12+
value: 'lilik.it'
13+
- name: install postfix packages
14+
apt:
15+
name: '{{ item }}'
16+
state: latest
17+
install_recommends: false
18+
with_items:
19+
- postfix
20+
# - postfix-ldap
21+
- dovecot-ldap
22+
- dovecot-imapd
23+
- rsyslog
24+
- dovecot-lmtpd
25+
# - amavisd-new
26+
# - postgrey #TODO
27+
# - spamassassin
28+
# - clamav-daemon
29+
30+
#- name: upload ldap-aliases.cf
31+
# template:
32+
# src: ldap-aliases.cf.j2
33+
# dest: "/etc/postfix/ldap-aliases.cf"
34+
# notify: restart_postfix
35+
#- lineinfile: dest=/etc/postfix/main.cf line="virtual_alias_maps = proxy:ldap:/etc/postfix/ldap-aliases.cf"
36+
# notify: restart_postfix
37+
38+
#- name: upload ldap-domains.cf
39+
# template:
40+
# src: ldap-domains.cf.j2
41+
# dest: "/etc/postfix/ldap-domains.cf"
42+
# notify: restart_postfix
43+
#- lineinfile: dest=/etc/postfix/main.cf line="virtual_mailbox_domains = proxy:ldap:/etc/postfix/ldap-domains.cf"
44+
# notify: restart_postfix
45+
46+
#- name: upload ldap-accounts.cf
47+
# template:
48+
# src: ldap-accounts.cf.j2
49+
# dest: "/etc/postfix/ldap-accounts.cf"
50+
# notify: restart_postfix
51+
#- lineinfile: dest=/etc/postfix/main.cf line="virtual_mailbox_maps = proxy:ldap:/etc/postfix/ldap-accounts.cf"
52+
# notify: restart_postfix
53+
54+
- lineinfile: dest=/etc/postfix/main.cf line="virtual_transport = lmtp:unix:private/dovecot-lmtp" state=present
55+
notify: restart_postfix
56+
57+
- name: create postman group
58+
group: name=postman state=present gid=800
59+
60+
- name: create postman user
61+
user: name=postman state=present uid=800 shell=/dev/null
62+
63+
- lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf regexp='^mail_location' state=absent
64+
notify: restart_dovecot
65+
66+
- lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf line='mail_location = maildir:/home/postman/%d/%n' state=present
67+
notify: restart_dovecot
68+
69+
- lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf line='mail_gid = 800' state=present
70+
notify: restart_dovecot
71+
72+
- lineinfile: dest=/etc/dovecot/conf.d/10-mail.conf line='mail_uid = 800' state=present
73+
notify: restart_dovecot
74+
75+
- lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="!include auth-system.conf.ext" state=absent
76+
notify: restart_dovecot
77+
78+
- lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="!include auth-ldap.conf.ext" state=present
79+
notify: restart_dovecot
80+
81+
- lineinfile: dest=/etc/dovecot/conf.d/10-auth.conf line="auth_default_realm = {{ fqdn_domain }}"
82+
83+
- template: src=dovecot-ldap.conf.ext.j2 dest=/etc/dovecot/dovecot-ldap.conf.ext
84+
notify: restart_dovecot
85+
86+
#- lineinfile: dest=/etc/postfix/main.cf line="content_filter=smtp-amavis:[127.0.0.1]:10024" state=present
87+
# notify: restart_postfix
88+
89+
#- blockinfile: |
90+
# dest=/etc/postfix/master.cf
91+
# content=" smtp-amavis unix - - n - 2 smtp
92+
# -o smtp_data_done_timeout=1200
93+
# -o smtp_send_xforward_command=yes
94+
# -o disable_dns_lookups=yes
95+
# -o max_use=20
96+
#
97+
# 127.0.0.1:10025 inet n - n - - smtpd
98+
# -o content_filter=
99+
# -o smtpd_delay_reject=no
100+
# -o smtpd_client_restrictions=permit_mynetworks,reject
101+
# -o smtpd_helo_restrictions=
102+
# -o smtpd_sender_restrictions=
103+
# -o smtpd_recipient_restrictions=permit_mynetworks,reject
104+
# -o smtpd_data_restrictions=reject_unauth_pipelining
105+
# -o smtpd_end_of_data_restrictions=
106+
# -o smtpd_restriction_classes=
107+
# -o mynetworks=127.0.0.0/8
108+
# -o smtpd_error_sleep_time=0
109+
# -o smtpd_soft_error_limit=1001
110+
# -o smtpd_hard_error_limit=1000
111+
# -o smtpd_client_connection_count_limit=0
112+
# -o smtpd_client_connection_rate_limit=0
113+
# -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters
114+
# -o local_header_rewrite_clients="
115+
# notify: restart_postfix
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
uris = ldap://{{ ldap_server }}
2+
3+
# choose bind method instead of simple authentication
4+
auth_bind = yes
5+
6+
# pass_attrs
7+
# specifies a comma-separated list of attributes that are returned from the LDAP.
8+
# If you set it to empty, all the attributes are returned.
9+
# http://wiki2.dovecot.org/AuthDatabase/LDAP/PasswordLookups
10+
# pass_attrs = user=mail,
11+
12+
# http://wiki.dovecot.org/PasswordDatabase
13+
# Returning a user field can be used to change the username. Typically used only for case changes (e.g. "UseR" -> "user").
14+
# username: Like user, but doesn't drop existing domain name (e.g. "username=foo" for "user@domain" gives "foo@domain").
15+
# domain: Updates the domain part of the username; domain=%{ldap:vd}
16+
pass_attrs = disableUser=user
17+
18+
# pass_filter
19+
# specifies the LDAP filter how user is found from the LDAP.
20+
# You can use all the normal variables like %u in the filter.
21+
pass_filter = (&(objectClass=VirtualMailAccount)(mail=%n)(accountActive=TRUE)(delete=FALSE))
22+
23+
ldap_version = 3
24+
25+
# search in vd=domain,o=hosting,dc=lilik,dc=it
26+
base = vd=%d,o=hosting,dc=lilik,dc=it
27+
28+
deref = always
29+
30+
scope = subtree
31+
32+
# ldap filter, return an entity that is a virtual mail account
33+
user_filter = (&(objectClass=VirtualMailAccount)(mail=%n)(accountActive=TRUE)(delete=FALSE))
34+
35+
# to prevent the uid and gid mappings from the ldap object to
36+
# dovecot mailbox, we map them to unused ldap fields
37+
# the sytnax is: "ldap_attribute = dovecot_attribute"
38+
# this is done because otherwise dovecot will deliver
39+
# emails to the user directory instead of the maildir directory
40+
# handled by the user postman
41+
user_attrs = disablehomeDirectory=home,disableuidNumber=uid,disablegidNumber=gid
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server_host = {{ ldap_server }}
2+
search_base = vd=%D,o=hosting,dc=lilik,dc=it
3+
#query_filter = (&(objectClass=simpleSecurityObject)(mail=%s))
4+
query_filter = (&(objectClass=VirtualMailAccount)(mail=%u)(accountActive=TRUE)(delete=FALSE))
5+
result_attribute = mail
6+
#result_attribute = uid
7+
#result_format = %D/%s/
8+
dereference = 3
9+
version = 3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server_host = {{ ldap_server }}
2+
search_base = vd=%D,o=hosting,dc=lilik,dc=it
3+
#query_filter = (&(objectClass=simpleSecurityObject)(mail=%s))
4+
query_filter = (&(objectClass=VirtualMailAlias)(mail=%u)(accountActive=TRUE))
5+
result_attribute = maildrop
6+
#result_attribute = uid
7+
#result_format = %D/%s/
8+
dereference = 3
9+
version = 3
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server_host = {{ ldap_server }}
2+
search_base = o=hosting,dc=lilik,dc=it
3+
query_filter = (&(vd=%s)(objectClass=VirtualDomain))
4+
result_attribute = vd
5+
#scope = one
6+
#cache = yes
7+
dereference = 3
8+
version = 3
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# LDIF Export for dc=lilik,dc=it
2+
# Server: My LDAP Server (127.0.0.1)
3+
# Search Scope: sub
4+
# Search Filter: (objectClass=*)
5+
# Total Entries: 611
6+
#
7+
# Generated by phpLDAPadmin (http://phpldapadmin.sourceforge.net) on February 19, 2016 7:30 pm
8+
# Version: 1.2.2
9+
10+
# Entry 4: o=Group,dc=lilik,dc=it
11+
dn: o=Group,dc=lilik,dc=it
12+
hassubordinates: TRUE
13+
o: Group
14+
objectclass: organization
15+
objectclass: top
16+
structuralobjectclass: organization
17+
subschemasubentry: cn=Subschema
18+
19+
# Entry 10: cn=stdusers,o=Group,dc=lilik,dc=it
20+
dn: cn=stdusers,o=Group,dc=lilik,dc=it
21+
cn: stdusers
22+
gidnumber: 9000
23+
hassubordinates: FALSE
24+
objectclass: posixGroup
25+
objectclass: top
26+
structuralobjectclass: posixGroup
27+
subschemasubentry: cn=Subschema
28+
29+
# Entry 12: cn=users_sites,o=Group,dc=lilik,dc=it
30+
dn: cn=users_sites,o=Group,dc=lilik,dc=it
31+
cn: users_sites
32+
gidnumber: 500
33+
hassubordinates: FALSE
34+
memberuid: tommyblue
35+
objectclass: posixGroup
36+
objectclass: top
37+
structuralobjectclass: posixGroup
38+
subschemasubentry: cn=Subschema
39+
40+
41+
# Entry 14: o=hosting,dc=lilik,dc=it
42+
dn: o=hosting,dc=lilik,dc=it
43+
description: mail.lilik.it hosting root
44+
hassubordinates: TRUE
45+
o: hosting
46+
objectclass: top
47+
objectclass: organization
48+
structuralobjectclass: organization
49+
subschemasubentry: cn=Subschema
50+
51+
# Entry 22: vd=lilik.it,o=hosting,dc=lilik,dc=it
52+
dn: vd=lilik.it,o=hosting,dc=lilik,dc=it
53+
accountactive: TRUE
54+
delete: FALSE
55+
editav: FALSE
56+
hassubordinates: TRUE
57+
maxalias: 20
58+
maxmail: 11
59+
maxquota: 250
60+
objectclass: top
61+
objectclass: VirtualDomain
62+
postfixtransport: maildrop:
63+
structuralobjectclass: VirtualDomain
64+
subschemasubentry: cn=Subschema
65+
vd: lilik.it
66+
lastChange: 1228821387
67+
68+
# Entry 23: cn=postmaster,vd=lilik.it,o=hosting,dc=lilik,dc=it
69+
dn: cn=postmaster,vd=lilik.it,o=hosting,dc=lilik,dc=it
70+
accountactive: TRUE
71+
cn: postmaster
72+
editaccounts: TRUE
73+
hassubordinates: FALSE
74+
mail: postmaster
75+
maildrop: postmaster
76+
objectclass: top
77+
objectclass: VirtualMailAlias
78+
sn: postmaster
79+
structuralobjectclass: VirtualMailAlias
80+
subschemasubentry: cn=Subschema
81+
userpassword: {SSHA}4IuBxQNWgMNPX/lCtP2GgbJeiYX+u4ud
82+
lastChange: 1228821387
83+
84+
# Entry 24: mail=abuse,vd=lilik.it,o=hosting,dc=lilik,dc=it
85+
dn: mail=abuse,vd=lilik.it,o=hosting,dc=lilik,dc=it
86+
accountactive: TRUE
87+
cn: NONAME
88+
givenname: NONAME
89+
hassubordinates: FALSE
90+
mail: abuse
91+
maildrop: root
92+
objectclass: top
93+
objectclass: VirtualMailAlias
94+
smtpauth: FALSE
95+
sn: NONAME
96+
structuralobjectclass: VirtualMailAlias
97+
subschemasubentry: cn=Subschema
98+
userpassword: {CRYPT}!
99+
lastChange: 1228821387
100+
101+
dn: mail=tommyblue,vd=lilik.it,o=hosting,dc=lilik,dc=it
102+
objectclass: alias
103+
objectclass: extensibleObject
104+
uid: alias
105+
aliasedobjectname: uid=tommyblue,o=People,dc=lilik,dc=it
106+
107+
108+
# Entry 319: o=People,dc=lilik,dc=it
109+
dn: o=People,dc=lilik,dc=it
110+
hassubordinates: TRUE
111+
o: People
112+
objectclass: organization
113+
objectclass: top
114+
structuralobjectclass: organization
115+
subschemasubentry: cn=Subschema
116+
117+
dn: uid=tommyblue,o=People,dc=lilik,dc=it
118+
accountactive: TRUE
119+
cn: Tommaso Visconti
120+
delete: FALSE
121+
gidnumber: 100
122+
givenname: Tommaso
123+
hassubordinates: FALSE
124+
homedirectory: /home/tommyblue
125+
loginshell: /bin/sh
126+
mail: tommyblue
127+
mailbox: lilik.it/tommyblue/
128+
objectclass: top
129+
objectclass: inetOrgPerson
130+
objectclass: VirtualMailAccount
131+
objectclass: posixAccount
132+
objectclass: shadowAccount
133+
othertransport: phamm:
134+
quota: 1024000
135+
shadowlastchange: 14281
136+
smtpauth: FALSE
137+
sn: Visconti
138+
structuralobjectclass: VirtualMailAccount
139+
subschemasubentry: cn=Subschema
140+
uid: tommyblue
141+
uidnumber: 10001
142+
userpassword: {CRYPT}$1$8jnl0tRQ$YiKqohvCe8M63Zmlx5T/h1
143+
vdhome: /home/mail_deliver/lilik.it/tommyblue
144+
lastChange: 1228821387

0 commit comments

Comments
 (0)