Skip to content

Commit

Permalink
Simplify configuration of SASL authenticated relay host
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeto committed Mar 12, 2021
1 parent 478658a commit 56b20ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ Accepting mail
directly; it will typically be used for MTAs that only need to send cron mails
etc.

* ``mta_relayhost_auth`` (mapping): This is only meaningful if
``mta_relayhost`` is set. In that case, this mapping allows to set up
authentication with the relay host using SASL:
* ``mta_relayhost_auth_username`` (string): This is only meaningful
if ``mta_relayhost`` is set. In that case this set the SASL user name to use
to set up authentication with the relay host using SASL.

* ``mta_relayhost_auth.username`` (string): the SASL user name to use
* ``mta_relayhost_auth.mapfile`` (path): A path where a config file
containing the credentials will be written to.
* ``mta_relayhost_auth_password`` (string): The password to use for relayhost SASL
authentication. Required if ``mta_relayhost_auth_username`` is used.

* ``mta_relayhost_auth_mapfile`` (path): A path where a config file containing
the SASL authentication credentials will be written to.

* ``mta_relayhost_password`` (string): The password to use for relayhost SASL
authentication. Required if ``mta_relayhost_auth`` is used.

* ``mta_transport_map`` (mapping): A lookup table, mapping destination
address patterns to their respective nexthop. Refer to the `postfix
Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ mta_local_sender_canonical_maps: []
mta_local_recipient_canonical_maps: []
mta_local_canonical_header_checks: []
mta_relayhost: False
mta_relayhost_auth: False
mta_relayhost_auth_username: null
mta_relayhost_auth_mapfile: /etc/postfix/password_map
mta_smtp_tls_wrappermode: no
mta_smtp_tls_security_level: "may"
mta_smtp_tls_ca_file: ""
Expand Down
6 changes: 3 additions & 3 deletions tasks/postfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@

- name: deploy sasl password map for relaying
template: src=postfix/password_map
dest="{{ mta_relayhost_auth.mapfile }}"
when: mta_relayhost and mta_relayhost_auth
dest="{{ mta_relayhost_auth_mapfile }}"
when: mta_relayhost and mta_relayhost_auth_username
register: password_map
notify:
- reload postfix

- name: compile sasl password map for relaying
command: postmap "{{ mta_relayhost_auth.mapfile }}"
command: postmap "{{ mta_relayhost_auth_mapfile }}"
when: password_map is changed
notify:
- reload postfix
Expand Down
6 changes: 3 additions & 3 deletions templates/postfix/main.cf
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ delay_warning_time = {{ mta_delay_warning }}
{% if mta_relayhost -%}
# origin: mta_relayhost
relayhost = {{ mta_relayhost }}
{% if mta_relayhost_auth -%}
# origin: mta_relayhost and mta_relayhost_auth
{% if mta_relayhost_auth_username and mta_relayhost_auth_password -%}
# origin: mta_relayhost and mta_relayhost_auth_mapfile
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:{{ mta_relayhost_auth.mapfile }}
smtp_sasl_password_maps = hash:{{ mta_relayhost_auth_mapfile }}
smtp_sasl_mechanism_filter =
smtp_sasl_security_options =
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion templates/postfix/password_map
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{ mta_relayhost }} {{ mta_relayhost_auth.username }}:{{ mta_relayhost_password }}
{{ mta_relayhost }} {{ mta_relayhost_auth_username }}:{{ mta_relayhost_auth_password }}

0 comments on commit 56b20ec

Please sign in to comment.