From 90d498034b891123350785a134402172de477f4f Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 11 May 2016 18:07:09 +0200 Subject: Use systemd unit files for stunnel4. --- roles/webmail/handlers/main.yml | 4 +- roles/webmail/tasks/mail.yml | 27 ++++------ .../webmail/templates/etc/stunnel/postfix.conf.j2 | 57 --------------------- roles/webmail/templates/etc/stunnel/smtp.conf.j2 | 58 ++++++++++++++++++++++ 4 files changed, 70 insertions(+), 76 deletions(-) delete mode 100644 roles/webmail/templates/etc/stunnel/postfix.conf.j2 create mode 100644 roles/webmail/templates/etc/stunnel/smtp.conf.j2 (limited to 'roles/webmail') diff --git a/roles/webmail/handlers/main.yml b/roles/webmail/handlers/main.yml index f7e403e..6009de0 100644 --- a/roles/webmail/handlers/main.yml +++ b/roles/webmail/handlers/main.yml @@ -1,6 +1,6 @@ --- -- name: Restart stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=restarted +- name: Restart stunnel@smtp + service: name=stunnel4@smtp state=restarted - name: Restart Nginx service: name=nginx state=restarted diff --git a/roles/webmail/tasks/mail.yml b/roles/webmail/tasks/mail.yml index 7603a56..78eee38 100644 --- a/roles/webmail/tasks/mail.yml +++ b/roles/webmail/tasks/mail.yml @@ -1,13 +1,3 @@ -- name: Install stunnel - apt: pkg=stunnel4 - -- name: Auto-enable stunnel - lineinfile: dest=/etc/default/stunnel4 - regexp='^(\s*#)?\s*ENABLED=' - line='ENABLED=1' - owner=root group=root - mode=0644 - - name: Create /etc/stunnel/certs file: path=/etc/stunnel/certs state=directory @@ -16,24 +6,27 @@ - name: Copy the SMTP outgoing proxy's X.509 certificate assemble: src=certs/postfix regexp="{{ groups.out | difference([inventory_hostname]) | join('|') }}\.pem$" remote_src=no - dest=/etc/stunnel/certs/postfix.pem + dest=/etc/stunnel/certs/smtp.pem owner=root group=root mode=0644 register: r1 notify: - - Restart stunnel + - Restart stunnel@smtp - name: Configure stunnel - template: src=etc/stunnel/postfix.conf.j2 - dest=/etc/stunnel/postfix.conf + template: src=etc/stunnel/smtp.conf.j2 + dest=/etc/stunnel/smtp.conf owner=root group=root mode=0644 register: r2 notify: - - Restart stunnel + - Restart stunnel@smtp + +- name: Enable stunnel@smtp + service: name=stunnel4@smtp enabled=yes -- name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started +- name: Start stunnel@smtp + service: name=stunnel4@smtp state=started when: not (r1.changed or r2.changed) - meta: flush_handlers diff --git a/roles/webmail/templates/etc/stunnel/postfix.conf.j2 b/roles/webmail/templates/etc/stunnel/postfix.conf.j2 deleted file mode 100644 index 9003686..0000000 --- a/roles/webmail/templates/etc/stunnel/postfix.conf.j2 +++ /dev/null @@ -1,57 +0,0 @@ -; ************************************************************************** -; * Global options * -; ************************************************************************** - -; setuid()/setgid() to the specified user/group in daemon mode -setuid = stunnel4 -setgid = stunnel4 - -; PID is created inside the chroot jail -pid = /var/run/stunnel4/postfix.pid - -; Only log messages at severity warning (4) and higher -debug = 4 - -; ************************************************************************** -; * Service defaults may also be specified in individual service sections * -; ************************************************************************** - -; Certificate/key is needed in server mode and optional in client mode -cert = /etc/postfix/ssl/{{ ansible_fqdn }}.pem -key = /etc/postfix/ssl/{{ ansible_fqdn }}.key -client = yes -socket = a:SO_BINDTODEVICE=lo - -; Some performance tunings -socket = l:TCP_NODELAY=1 -socket = r:TCP_NODELAY=1 - -; Prevent MITM attacks -verify = 4 - -; Disable support for insecure protocols -options = NO_SSLv2 -options = NO_SSLv3 -options = NO_TLSv1 -options = NO_TLSv1.1 - -options = NO_COMPRESSION - -; These options provide additional security at some performance degradation -options = SINGLE_ECDH_USE -options = SINGLE_DH_USE - -; Select permitted SSL ciphers -ciphers = EECDH+AESGCM:!MEDIUM:!LOW:!EXP:!aNULL:!eNULL - -; ************************************************************************** -; * Service definitions (remove all services for inetd mode) * -; ************************************************************************** - -[smtp] -accept = localhost:2525 -connect = outgoing.fripost.org:{{ postfix_instance.out.port }} -CAfile = /etc/stunnel/certs/postfix.pem -protocol = smtp - -; vim:ft=dosini diff --git a/roles/webmail/templates/etc/stunnel/smtp.conf.j2 b/roles/webmail/templates/etc/stunnel/smtp.conf.j2 new file mode 100644 index 0000000..ba38bfa --- /dev/null +++ b/roles/webmail/templates/etc/stunnel/smtp.conf.j2 @@ -0,0 +1,58 @@ +; ************************************************************************** +; * Global options * +; ************************************************************************** + +; setuid()/setgid() to the specified user/group in daemon mode +setuid = stunnel4 +setgid = stunnel4 + +; PID is created inside the chroot jail +pid = +foreground = yes + +; Only log messages at severity warning (4) and higher +debug = 4 + +; ************************************************************************** +; * Service defaults may also be specified in individual service sections * +; ************************************************************************** + +; Certificate/key is needed in server mode and optional in client mode +cert = /etc/postfix/ssl/{{ ansible_fqdn }}.pem +key = /etc/postfix/ssl/{{ ansible_fqdn }}.key +client = yes +socket = a:SO_BINDTODEVICE=lo + +; Some performance tunings +socket = l:TCP_NODELAY=1 +socket = r:TCP_NODELAY=1 + +; Prevent MITM attacks +verify = 4 + +; Disable support for insecure protocols +options = NO_SSLv2 +options = NO_SSLv3 +options = NO_TLSv1 +options = NO_TLSv1.1 + +options = NO_COMPRESSION + +; These options provide additional security at some performance degradation +options = SINGLE_ECDH_USE +options = SINGLE_DH_USE + +; Select permitted SSL ciphers +ciphers = EECDH+AESGCM:!MEDIUM:!LOW:!EXP:!aNULL:!eNULL + +; ************************************************************************** +; * Service definitions (remove all services for inetd mode) * +; ************************************************************************** + +[smtp] +accept = localhost:2525 +connect = outgoing.fripost.org:{{ postfix_instance.out.port }} +CAfile = /etc/stunnel/certs/smtp.pem +protocol = smtp + +; vim:ft=dosini -- cgit v1.2.3