From 782a07a45014e92501b6c47a904debf92a5c5401 Mon Sep 17 00:00:00 2001 From: Morre Date: Fri, 3 Jul 2020 13:46:00 +0200 Subject: [PATCH] Add basic LDAP config for recipients and senders --- defaults/main.yml | 4 ++++ tasks/main.yml | 22 +++++++++++----------- templates/main.cf.j2 | 9 ++++++++- templates/virtual-recipients.cf.j2 | 12 ++++++++++++ templates/virtual-senders.cf.j2 | 11 +++++++++++ 5 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 templates/virtual-recipients.cf.j2 create mode 100644 templates/virtual-senders.cf.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 0629124..8efcc04 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,5 +15,9 @@ postfix: virtual_mailbox_domains: [] mynetworks: [] mydestination: [] + ldap: + enable: false + server_host: ldap.example.com + search_base: "dc=example,dc=com" postfixmaps: [] diff --git a/tasks/main.yml b/tasks/main.yml index d3cd553..80bc2fc 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,23 +1,23 @@ - name: install postfix apt: - pkg: postfix + pkg: + - postfix + - postfix-ldap - name: remove exim4 package apt: name: exim4 state: absent -- name: copy main.cf +- name: copy postfix config template: - src: main.cf.j2 - dest: /etc/postfix/main.cf - notify: - - restart postfix - -- name: copy master.cf - template: - src: master.cf.j2 - dest: /etc/postfix/master.cf + src: "{{ item.src }}" + dest: "{{ item.dest }}" + with_items: + - { src: "main.cf.j2", dest: "/etc/postfix/main.cf" } + - { src: "master.cf.j2", dest: "/etc/postfix/master.cf" } + - { src: "virtual-senders.cf.j2", dest: "/etc/postfix/virtual-senders.cf" } + - { src: "virtual-recipients.cf.j2", dest: "/etc/postfix/virtual-recipients.cf" } notify: - restart postfix diff --git a/templates/main.cf.j2 b/templates/main.cf.j2 index 5dcc5d1..e818263 100644 --- a/templates/main.cf.j2 +++ b/templates/main.cf.j2 @@ -48,7 +48,7 @@ relay_domains = {{ postfix.relay_domains|join(', ') }} relay_transport = {{ postfix.relay_transport }} sender_dependent_relayhost_maps = {{ postfix.sender_dependent_relayhost_maps }} virtual_alias_maps = {{ postfix.virtual_alias_maps }} -virtual_mailbox_domains = {{ postfix.virtual_mailbox_domains|join(' ') }} +virtual_mailbox_domains = {{ postfix.virtual_mailbox_domains|join(' ') }} mailbox_size_limit = 0 recipient_delimiter = + @@ -69,6 +69,13 @@ dovecot_destination_recipient_limit = 1 virtual_transport = dovecot {% endif %} +{% if postfix.ldap.enable %} +# LDAP config +smtpd_sender_login_maps = proxy:ldap:/etc/postfix/virtual-senders.cf +virtual_mailbox_maps = proxy:ldap:/etc/postfix/virtual-recipients.cf +local_recipient_maps = $virtual_mailbox_maps +{% endif %} + # opendkim {% if postfix.enable_opendkim %} diff --git a/templates/virtual-recipients.cf.j2 b/templates/virtual-recipients.cf.j2 new file mode 100644 index 0000000..cc78874 --- /dev/null +++ b/templates/virtual-recipients.cf.j2 @@ -0,0 +1,12 @@ +{% if postfix.ldap.enable %} +bind = yes +# bind_dn = +# bind_pw = +server_host = {{ postfix.ldap.server_host }} +search_base = {{ postfix.ldap.recipients.search_base }} +query_filter = {{ postfix.ldap.recipients.query_filter }} +result_attribute = cn +result_format =%s +{% else %} +# LDAP is not configured for this server. +{% endif %} diff --git a/templates/virtual-senders.cf.j2 b/templates/virtual-senders.cf.j2 new file mode 100644 index 0000000..6699ad6 --- /dev/null +++ b/templates/virtual-senders.cf.j2 @@ -0,0 +1,11 @@ +{% if postfix.ldap.enable %} +bind = yes +# bind_dn = +# bind_pw = +server_host = {{ postfix.ldap.server_host }} +search_base = {{ postfix.ldap.senders.search_base }} +query_filter = {{ postfix.ldap.senders.query_filter }} +result_attribute = cn +{% else %} +# LDAP is not configured for this server. +{% endif %}