diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2016-05-11 18:07:09 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2016-05-12 11:33:55 +0200 |
commit | 90d498034b891123350785a134402172de477f4f (patch) | |
tree | a6e3c924054c3f689cdaffffe3a479e88fb97282 | |
parent | e370313ad5895871479fffc922e3c72c0375dbf2 (diff) |
Use systemd unit files for stunnel4.
26 files changed, 207 insertions, 172 deletions
diff --git a/roles/IMAP-proxy/files/etc/stunnel/roundcube.conf b/roles/IMAP-proxy/files/etc/stunnel/roundcube.conf index 284bcc0..fe0bd5d 100644 --- a/roles/IMAP-proxy/files/etc/stunnel/roundcube.conf +++ b/roles/IMAP-proxy/files/etc/stunnel/roundcube.conf @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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/roundcube.pid +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/stunnel/mail.pem ;key = /etc/stunnel/mail.pem 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 diff --git a/roles/IMAP-proxy/handlers/main.yml b/roles/IMAP-proxy/handlers/main.yml index 5249a7e..39cf5f2 100644 --- a/roles/IMAP-proxy/handlers/main.yml +++ b/roles/IMAP-proxy/handlers/main.yml @@ -1,6 +1,6 @@ --- -- name: Restart stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=restarted +- name: Restart stunnel@roundcube + service: name=stunnel4@roundcube state=restarted - name: Restart Dovecot service: name=dovecot state=restarted diff --git a/roles/IMAP-proxy/tasks/main.yml b/roles/IMAP-proxy/tasks/main.yml index 587fc62..3d4efb1 100644 --- a/roles/IMAP-proxy/tasks/main.yml +++ b/roles/IMAP-proxy/tasks/main.yml @@ -26,72 +26,65 @@ mode=0644 register: r with_items: - 10-auth.conf - 10-logging.conf - 10-mail.conf - 10-master.conf - 15-mailboxes.conf - 20-imapc.conf - auth-imap.conf.ext notify: - Restart Dovecot - name: Start Dovecot service: name=dovecot state=started when: not r.changed - meta: flush_handlers -- 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 owner=root group=root mode=0755 - name: Copy Dovecot's X.509 certificate # XXX: it's unfortunate that we have to store the whole CA chain... # for some reason stunnel's level 4 "verify" (CA chain and only verify # peer certificate) doesn't always work: # https://www.stunnel.org/pipermail/stunnel-users/2013-July/004249.html assemble: src=certs/dovecot remote_src=no dest=/etc/stunnel/certs/imap.fripost.org.pem owner=root group=root mode=0644 register: r1 notify: - - Restart stunnel + - Restart stunnel@roundcube - name: Copy slapd's X.509 certificate copy: src=certs/ldap/ldap.fripost.org.pem dest=/etc/stunnel/certs/ldap.fripost.org.pem owner=root group=root mode=0644 register: r2 notify: - - Restart stunnel + - Restart stunnel@roundcube - name: Configure stunnel copy: src=etc/stunnel/roundcube.conf dest=/etc/stunnel/roundcube.conf owner=root group=root mode=0644 register: r3 notify: - - Restart stunnel + - Restart stunnel@roundcube + +- name: Enable stunnel@roundcube + service: name=stunnel4@roundcube enabled=yes -- name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started +- name: Start stunnel@roundcube + service: name=stunnel4@roundcube state=started when: not (r1.changed or r2.changed or r3.changed) - meta: flush_handlers diff --git a/roles/bacula-dir/handlers/main.yml b/roles/bacula-dir/handlers/main.yml index 175dfb2..778a1c4 100644 --- a/roles/bacula-dir/handlers/main.yml +++ b/roles/bacula-dir/handlers/main.yml @@ -1,9 +1,9 @@ --- - name: systemctl daemon-reload command: /bin/systemctl daemon-reload -- name: Restart stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=restarted +- name: Restart stunnel@bacula-dir + service: name=stunnel4@bacula-dir state=restarted - name: Restart bacula-director service: name=bacula-director state=restarted diff --git a/roles/bacula-dir/tasks/main.yml b/roles/bacula-dir/tasks/main.yml index f86d713..6799900 100644 --- a/roles/bacula-dir/tasks/main.yml +++ b/roles/bacula-dir/tasks/main.yml @@ -1,91 +1,84 @@ -- 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 owner=root group=root mode=0755 - name: Generate a private key and a X.509 certificate for Bacula Dir command: genkeypair.sh x509 --pubkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-dir.pem --privkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-dir.key --ou=BaculaDir --cn={{ inventory_hostname }} --dns={{ inventory_hostname }} -t rsa -b 4096 -h sha512 register: r1 changed_when: r1.rc == 0 failed_when: r1.rc > 1 notify: - - Restart stunnel + - Restart stunnel@bacula-dir tags: - genkey - name: Fetch Bacula Dir X.509 certificate # Ensure we don't fetch private data become: False fetch: src=/etc/stunnel/certs/{{ inventory_hostname_short }}-dir.pem dest=certs/bacula/ fail_on_missing=yes flat=yes tags: - genkey - name: Copy Bacula SD X.509 certificates copy: src=certs/bacula/{{ hostvars[item].inventory_hostname_short }}-sd.pem dest=/etc/stunnel/certs/ owner=root group=root mode=0644 with_items: "{{ groups['bacula-sd'] | difference([inventory_hostname]) | sort }}" register: r2 notify: - - Restart stunnel + - Restart stunnel@bacula-dir - name: Copy Bacula FD X.509 certificates copy: src=certs/bacula/{{ hostvars[item].inventory_hostname_short }}-fd.pem dest=/etc/stunnel/certs/ owner=root group=root mode=0644 with_items: "{{ groups.all | difference([inventory_hostname]) | sort }}" register: r3 notify: - - Restart stunnel + - Restart stunnel@bacula-dir - name: Configure stunnel template: src=etc/stunnel/bacula-dir.conf.j2 dest=/etc/stunnel/bacula-dir.conf owner=root group=root mode=0644 register: r4 notify: - - Restart stunnel + - Restart stunnel@bacula-dir + +- name: Enable stunnel@bacula-dir + service: name=stunnel4@bacula-dir enabled=yes -- name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started +- name: Start stunnel@bacula-dir + service: name=stunnel4@bacula-dir state=started when: not (r1.changed or r2.changed or r3.changed or r4.changed) - meta: flush_handlers - name: Install bacula-director apt: pkg={{ item }} with_items: - bacula-console - bacula-director-mysql - name: Create a 'bacula' SQL user mysql_user2: name=bacula password= auth_plugin=auth_socket state=present notify: - Restart bacula-director # Create with: # echo bconsole $(pwgen -sn 64 1) | sudo tee -a /etc/bacula/passwords-dir diff --git a/roles/bacula-dir/templates/etc/stunnel/bacula-dir.conf.j2 b/roles/bacula-dir/templates/etc/stunnel/bacula-dir.conf.j2 index 4dbb1db..e6ab105 100644 --- a/roles/bacula-dir/templates/etc/stunnel/bacula-dir.conf.j2 +++ b/roles/bacula-dir/templates/etc/stunnel/bacula-dir.conf.j2 @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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/bacula-dir.pid +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/stunnel/certs/{{ inventory_hostname_short }}-dir.pem key = /etc/stunnel/certs/{{ inventory_hostname_short }}-dir.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 diff --git a/roles/bacula-sd/handlers/main.yml b/roles/bacula-sd/handlers/main.yml index ce391d2..c6adb80 100644 --- a/roles/bacula-sd/handlers/main.yml +++ b/roles/bacula-sd/handlers/main.yml @@ -1,9 +1,9 @@ --- - name: systemctl daemon-reload command: /bin/systemctl daemon-reload -- name: Restart stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=restarted +- name: Restart stunnel@bacula-sd + service: name=stunnel4@bacula-sd state=restarted - name: Restart bacula-sd service: name=bacula-sd state=restarted diff --git a/roles/bacula-sd/tasks/main.yml b/roles/bacula-sd/tasks/main.yml index a888db6..5de0d3d 100644 --- a/roles/bacula-sd/tasks/main.yml +++ b/roles/bacula-sd/tasks/main.yml @@ -1,80 +1,73 @@ -- 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 owner=root group=root mode=0755 - name: Generate a private key and a X.509 certificate for Bacula SD command: genkeypair.sh x509 --pubkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-sd.pem --privkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-sd.key --ou=BaculaSD --cn={{ inventory_hostname }} --dns={{ inventory_hostname }} -t rsa -b 4096 -h sha512 register: r1 changed_when: r1.rc == 0 failed_when: r1.rc > 1 notify: - - Restart stunnel + - Restart stunnel@bacula-sd tags: - genkey - name: Fetch Bacula SD X.509 certificate # Ensure we don't fetch private data become: False fetch: src=/etc/stunnel/certs/{{ inventory_hostname_short }}-sd.pem dest=certs/bacula/ fail_on_missing=yes flat=yes tags: - genkey - name: Copy Bacula Dir/FD X.509 certificates assemble: src=certs/bacula regexp="-(dir|fd)\.pem$" remote_src=no dest=/etc/stunnel/certs/bacula-dir+fds.pem owner=root group=root mode=0644 register: r2 notify: - - Restart stunnel + - Restart stunnel@bacula-sd - name: Configure stunnel template: src=etc/stunnel/bacula-sd.conf.j2 dest=/etc/stunnel/bacula-sd.conf owner=root group=root mode=0644 register: r3 notify: - - Restart stunnel + - Restart stunnel@bacula-sd + +- name: Enable stunnel@bacula-sd + service: name=stunnel4@bacula-sd enabled=yes - name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started + service: name=stunnel4@bacula-sd state=started when: not (r1.changed or r2.changed or r3.changed) - meta: flush_handlers - name: Install bacula-sd apt: pkg=bacula-sd # Create with: # echo $director-dir $(pwgen -sn 64 1) | sudo tee -a /etc/bacula/passwords-sd - name: Ensure /etc/bacula/passwords-sd exists file: path=/etc/bacula/passwords-sd state=file owner=bacula group=bacula mode=0600 - name: Configure bacula template: src=etc/bacula/bacula-sd.conf.j2 dest=/etc/bacula/bacula-sd.conf diff --git a/roles/bacula-sd/templates/etc/stunnel/bacula-sd.conf.j2 b/roles/bacula-sd/templates/etc/stunnel/bacula-sd.conf.j2 index 767424a..f0234fa 100644 --- a/roles/bacula-sd/templates/etc/stunnel/bacula-sd.conf.j2 +++ b/roles/bacula-sd/templates/etc/stunnel/bacula-sd.conf.j2 @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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/bacula-sd.pid +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/stunnel/certs/{{ inventory_hostname_short }}-sd.pem key = /etc/stunnel/certs/{{ inventory_hostname_short }}-sd.key ; Some performance tunings socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1 ; Prevent MITM attacks verify = 4 ; Disable support for insecure protocols diff --git a/roles/common/files/etc/logcheck/ignore.d.server/common-local b/roles/common/files/etc/logcheck/ignore.d.server/common-local index 32bb906..8e654da 100644 --- a/roles/common/files/etc/logcheck/ignore.d.server/common-local +++ b/roles/common/files/etc/logcheck/ignore.d.server/common-local @@ -20,21 +20,21 @@ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ sudo:[[:space:]]+[_[:alnum:].-]+ : TTY=(unknown|(pts/|tty|vc/)[[:digit:]]+) ; PWD=[^;]+ ; USER=[._[:alnum:]-]+ (; ENV=([_a-zA-Z]+=\S* )+)?; COMMAND=(/(usr|etc|bin|sbin)/|sudoedit ) ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: bytecode\.(cld|cvd) (is up to date|updated) \(version: [[:digit:]]+, sigs: [[:digit:]]+, f-level: [[:digit:]]+, builder: [._[:alnum:]-]+\)$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: WARNING: Your ClamAV installation is OUTDATED!$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: WARNING: Local version: [[:digit:]]+(\.[[:digit:]]+)* Recommended version: [[:digit:]]+(\.[[:digit:]]+)*$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: WARNING: getfile: [._[:alnum:]-]+ not found on remote server \(IP: [.[:digit:]]+\)$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: WARNING: Incremental update failed, trying to download daily\.cvd$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: (WARNING|ERROR): (getpatch: )?Can't download [._[:alnum:]-]+ from [.[:alnum:]-]+$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: Trying host [.[:alnum:]-]+ \([.[:digit:]]+\)\.\.\.$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: Trying again in [[:digit:]]+ secs\.\.\.$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: Giving up on [.[:alnum:]-]+\.\.\.$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: Downloading [._[:alnum:]-]+ \[[[:digit:]]+%\]$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ freshclam\[[[:digit:]]+\]: DON'T PANIC! Read http://www\.clamav\.net/support/faq$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ kernel: \[ *[[:digit:]]+\.[[:digit:]]+ *\] Peer [.[:digit:]]+:[[:digit:]]+/[[:digit:]]+ unexpectedly shrunk window [[:digit:]]+:[[:digit:]]+ \(repaired\)$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ rsyslogd: \[origin software="rsyslogd" swVersion="[.[:digit:]]+" x-pid="[[:digit:]]+" x-info="http://www.rsyslog.com"\] rsyslogd was HUPed$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ rsyslogd-?([[:digit:]]+): action '[^']+' (resumed \(module '[.[:alnum:]-]+:[.[:alnum:]-]+'\)|suspended, next retry is \w{3} \w{3} [ :[:digit:]]{16}) \[try http://www\.rsyslog\.com/e/\1 \]$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ ansible-([_a-z]+|<stdin>): Invoked with ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ (sympa\((command|distribute)\)|wwsympa|archived|bounced|bulk|task_manager)\[[[:digit:]]+\]: (info|notice)\s ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ wwsympa\[[[:digit:]]+\]: err .* main::check_action_parameters\(\) user not logged in$ ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ rrdcached\[[[:digit:]]+\]: (flushing old values|rotating journals|started new journal /\S+$|removing old journal /\S+$) ^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ rrdcached\[[[:digit:]]+\]: queue_thread_main: rrd_update_r \(([^)]+)\) failed with status -1. \(opening '\1': No such file or directory\) -^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ stunnel: LOG3\[[[:digit:]]+\]: SSL_accept: (Peer suddenly disconnected|[[:xdigit:]]+: error:[[:xdigit:]]+:SSL routines:SSL2?3_GET_CLIENT_HELLO:(unknown protocol|http request|no shared cipher))$ +^\w{3} [ :[:digit:]]{11} [._[:alnum:]-]+ stunnel(:|4\[[[:digit:]]+\]: [0-9]{4}\.[0-9]{2}\.[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}) LOG3\[[[:digit:]]+\]: SSL_accept: (Peer suddenly disconnected|[[:xdigit:]]+: error:[[:xdigit:]]+:SSL routines:SSL2?3_GET_CLIENT_HELLO:(unknown protocol|http request|no shared cipher))$ diff --git a/roles/common/files/lib/systemd/system/stunnel4.service b/roles/common/files/lib/systemd/system/stunnel4.service new file mode 100644 index 0000000..990e07b --- /dev/null +++ b/roles/common/files/lib/systemd/system/stunnel4.service @@ -0,0 +1,14 @@ +# This service is actually a systemd target, +# but we are using a service since targets cannot be reloaded. + +[Unit] +Description=SSL tunnel for network daemons (multi-instance-master) + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/true +ExecReload=/bin/true + +[Install] +WantedBy=multi-user.target diff --git a/roles/common/files/lib/systemd/system/stunnel4@.service b/roles/common/files/lib/systemd/system/stunnel4@.service new file mode 100644 index 0000000..e53d29e --- /dev/null +++ b/roles/common/files/lib/systemd/system/stunnel4@.service @@ -0,0 +1,23 @@ +[Unit] +Description=SSL tunnel for network daemons (instance %i) +After=network.target nss-lookup.target +PartOf=stunnel4.service +ReloadPropagatedFrom=stunnel4.service + +[Service] +ExecStart=/usr/bin/stunnel4 /etc/stunnel/%i.conf +ExecReload=/bin/kill -HUP ${MAINPID} +KillSignal=SIGINT +TimeoutStartSec=120 +TimeoutStopSec=60 +Restart=on-failure + +# Hardening +NoNewPrivileges=yes +PrivateDevices=yes +ProtectHome=yes +ProtectSystem=full +ReadOnlyDirectories=/ + +[Install] +WantedBy=multi-user.target diff --git a/roles/common/handlers/main.yml b/roles/common/handlers/main.yml index 47e3db8..ebb40a0 100644 --- a/roles/common/handlers/main.yml +++ b/roles/common/handlers/main.yml @@ -21,31 +21,34 @@ service: name=fail2ban state=restarted - name: Reload networking # /etc/init.d/networking doesn't answer the status command; but since # it should be "up" whenever ansible has access to the machine, we use # pattern=init as a dummy assumption. service: name=networking pattern=init state=reloaded - name: Restart rsyslog service: name=rsyslog state=restarted - name: Restart ntp service: name=ntp state=restarted - name: Restart Postfix service: name=postfix state=restarted - name: Reload Postfix service: name=postfix state=reloaded -- name: Restart stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=restarted +- name: Restart stunnel@bacula-fd + service: name=stunnel4@bacula-fd state=restarted + +- name: Restart stunnel@munin-node + service: name=stunnel4@munin-node state=restarted - name: Restart bacula-fd service: name=bacula-fd state=restarted - name: Restart munin-node service: name=munin-node state=restarted - name: Restart freshclam service: name=clamav-freshclam state=restarted diff --git a/roles/common/tasks/bacula.yml b/roles/common/tasks/bacula.yml index e29f01c..f0919e4 100644 --- a/roles/common/tasks/bacula.yml +++ b/roles/common/tasks/bacula.yml @@ -1,93 +1,88 @@ -- 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 owner=root group=root mode=0755 - name: Generate a private key and a X.509 certificate for Bacula FD command: genkeypair.sh x509 --pubkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-fd.pem --privkey=/etc/stunnel/certs/{{ inventory_hostname_short }}-fd.key --ou=BaculaFD --cn={{ inventory_hostname }} --dns={{ inventory_hostname }} -t rsa -b 4096 -h sha512 register: r1 changed_when: r1.rc == 0 failed_when: r1.rc > 1 notify: - - Restart stunnel + - Restart stunnel@bacula-fd tags: - genkey - name: Fetch Bacula FD X.509 certificate # Ensure we don't fetch private data become: False fetch: src=/etc/stunnel/certs/{{ inventory_hostname_short }}-fd.pem dest=certs/bacula/ fail_on_missing=yes flat=yes tags: - genkey - name: Copy Bacula Dir X.509 certificates assemble: src=certs/bacula regexp="-dir\.pem$" remote_src=no dest=/etc/stunnel/certs/bacula-dirs.pem owner=root group=root mode=0644 register: r2 when: "'bacula-dir' not in group_names" notify: - - Restart stunnel + - Restart stunnel@bacula-fd - name: Copy Bacula SD X.509 certificates copy: src=certs/bacula/{{ hostvars[item].inventory_hostname_short }}-sd.pem dest=/etc/stunnel/certs/ owner=root group=root mode=0644 register: r3 with_items: "{{ groups['bacula-sd'] | difference([inventory_hostname]) }}" notify: - - Restart stunnel + - Restart stunnel@bacula-fd - name: Configure stunnel template: src=etc/stunnel/bacula-fd.conf.j2 dest=/etc/stunnel/bacula-fd.conf owner=root group=root mode=0644 register: r4 when: "'bacula-dir' not in group_names or 'bacula-sd' not in group_names" notify: - - Restart stunnel + - Restart stunnel@bacula-fd + +- name: Enable stunnel@bacula-fd + when: "'bacula-dir' not in group_names or 'bacula-sd' not in group_names" + service: name=stunnel4@bacula-fd enabled=yes -- name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started - when: not (r1.changed or r2.changed or r3.changed or r4.changed) +- name: Start stunnel@bacula-fd + service: name=stunnel4@bacula-fd state=started + when: ('bacula-dir' not in group_names or 'bacula-sd' not in group_names) and + not (r1.changed or r2.changed or r3.changed or r4.changed) - meta: flush_handlers - name: Install bacula-fd apt: pkg=bacula-fd - name: Create /var/lib/bacula/tmp file: path=/var/lib/bacula/tmp state=directory owner=root group=root mode=0700 - name: Delete /etc/bacula/common_default_passwords file: path=/etc/bacula/common_default_passwords state=absent # Create with: # echo $director-dir $(pwgen -sn 64 1) | sudo tee -a /etc/bacula/passwords-fd - name: Ensure /etc/bacula/passwords-fd exists diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 3e6a4a8..14cb7ae 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -1,34 +1,37 @@ --- - include: sysctl.yml tags: sysctl - include: hosts.yml - include: apt.yml tags: apt - name: Install intel-microcode apt: pkg=intel-microcode when: "ansible_processor[0] | search('^(Genuine)?Intel.*') and not (ansible_virtualization_role == 'guest' and ansible_virtualization_type == 'xen')" tags: intel - include: firewall.yml tags: - firewall - iptables + +- include: stunnel.yml + tags: stunnel - include: samhain.yml tags: samhain - include: auditd.yml tags: auditd - include: rkhunter.yml tags: rkhunter - include: clamav.yml tags: clamav - include: fail2ban.yml tags: fail2ban - include: smart.yml tags: - smartmontools - smart when: "not ((ansible_virtualization_role == 'guest' and ansible_virtualization_type == 'xen') or ansible_system_vendor == 'QEMU')" - include: haveged.yml tags: - haveged - entropy - name: Copy genkeypair.sh and gendhparam.sh @@ -42,33 +45,38 @@ - gendhparam.sh - name: Generate DH parameters command: gendhparam.sh /etc/ssl/private/dhparams.pem creates=/etc/ssl/private/dhparams.pem tags: genkey - include: logging.yml tags: logging - include: ntp.yml tags: ntp - include: mail.yml tags: - mail - postfix - include: bacula.yml tags: - bacula-fd - bacula - include: munin-node.yml tags: - munin-node - munin +- include: munin-node-ssl.yml + when: "'munin-master' not in group_names" + tags: + - munin-node + - munin - name: Install common packages apt: pkg={{ item }} with_items: - ca-certificates - etckeeper - ethtool - git - htop - molly-guard - rsync - screen - telnet-ssl diff --git a/roles/common/tasks/munin-node-ssl.yml b/roles/common/tasks/munin-node-ssl.yml new file mode 100644 index 0000000..59ed7d7 --- /dev/null +++ b/roles/common/tasks/munin-node-ssl.yml @@ -0,0 +1,58 @@ +- name: Create /etc/stunnel/certs + file: path=/etc/stunnel/certs + state=directory + owner=root group=root + mode=0755 + +- name: Generate a private key and a X.509 certificate for munin-node + command: genkeypair.sh x509 + --pubkey=/etc/stunnel/certs/munin-{{ inventory_hostname_short }}.pem + --privkey=/etc/stunnel/certs/munin-{{ inventory_hostname_short }}.key + --ou=Munin --cn={{ inventory_hostname }} --dns={{ inventory_hostname }} + -t rsa -b 4096 -h sha512 + register: r1 + changed_when: r1.rc == 0 + failed_when: r1.rc > 1 + notify: + - Restart stunnel@munin-node + tags: + - genkey + +- name: Fetch Munin X.509 certificate + # Ensure we don't fetch private data + become: False + fetch: src=/etc/stunnel/certs/munin-{{ inventory_hostname_short }}.pem + dest=certs/munin/{{ inventory_hostname }}.pem + fail_on_missing=yes + flat=yes + tags: + - genkey + +- name: Copy munin-master X.509 certificates + assemble: src=certs/munin regexp="{{ groups['munin-master'] | join('|') }}\.pem$" remote_src=no + dest=/etc/stunnel/certs/munin-master.pem + owner=root group=root + mode=0644 + register: r2 + when: "'munin-master' not in group_names" + notify: + - Restart stunnel@munin-node + +- name: Configure stunnel + template: src=etc/stunnel/munin-node.conf.j2 + dest=/etc/stunnel/munin-node.conf + owner=root group=root + mode=0644 + register: r3 + when: "'munin-master' not in group_names" + notify: + - Restart stunnel@munin-node + +- name: Enable stunnel@munin-node + service: name=stunnel4@munin-node enabled=yes + +- name: Start stunnel@munin-node + service: name=stunnel4@munin-node state=started + when: not (r1.changed or r2.changed or r3.changed) + +- meta: flush_handlers diff --git a/roles/common/tasks/munin-node.yml b/roles/common/tasks/munin-node.yml index c585d60..e1a931a 100644 --- a/roles/common/tasks/munin-node.yml +++ b/roles/common/tasks/munin-node.yml @@ -120,88 +120,20 @@ - Restart munin-node - name: Install 'postfix_stats_' Munin wildcard plugin file: src=/usr/local/share/munin/plugins/postfix_stats_ dest=/etc/munin/plugins/postfix_stats_{{ item }}_postfix owner=root group=root state=link force=yes register: r7 with_items: - smtpd - qmgr - smtp notify: - Restart munin-node - name: Start munin-node service: name=munin-node state=started when: not (r1.changed or r2.changed or r3.changed or r4.changed or r5.changed or r6.changed or r7.changed) - meta: flush_handlers - - - -- 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 - owner=root group=root - mode=0755 - -- name: Generate a private key and a X.509 certificate for munin-node - command: genkeypair.sh x509 - --pubkey=/etc/stunnel/certs/munin-{{ inventory_hostname_short }}.pem - --privkey=/etc/stunnel/certs/munin-{{ inventory_hostname_short }}.key - --ou=Munin --cn={{ inventory_hostname }} --dns={{ inventory_hostname }} - -t rsa -b 4096 -h sha512 - register: r1 - changed_when: r1.rc == 0 - failed_when: r1.rc > 1 - notify: - - Restart stunnel - tags: - - genkey - -- name: Fetch Munin X.509 certificate - # Ensure we don't fetch private data - become: False - fetch: src=/etc/stunnel/certs/munin-{{ inventory_hostname_short }}.pem - dest=certs/munin/{{ inventory_hostname }}.pem - fail_on_missing=yes - flat=yes - tags: - - genkey - -- name: Copy munin-master X.509 certificates - assemble: src=certs/munin regexp="{{ groups['munin-master'] | join('|') }}\.pem$" remote_src=no - dest=/etc/stunnel/certs/munin-master.pem - owner=root group=root - mode=0644 - register: r2 - when: "'munin-master' not in group_names" - notify: - - Restart stunnel - -- name: Configure stunnel - template: src=etc/stunnel/munin-node.conf.j2 - dest=/etc/stunnel/munin-node.conf - owner=root group=root - mode=0644 - register: r3 - when: "'munin-master' not in group_names" - notify: - - Restart stunnel - -- name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started - when: not (r1.changed or r2.changed or r3.changed) - -- meta: flush_handlers diff --git a/roles/common/tasks/stunnel.yml b/roles/common/tasks/stunnel.yml new file mode 100644 index 0000000..68469cd --- /dev/null +++ b/roles/common/tasks/stunnel.yml @@ -0,0 +1,20 @@ +- name: Install stunnel4 + apt: pkg=stunnel4 + +- name: Set 'ENABLED=0' in /etc/default/stunnel4 + lineinfile: dest=/etc/default/stunnel4 + regexp='^(\s*#)?\s*ENABLED=' + line='ENABLED=0' + owner=root group=root + mode=0644 + +- name: Copy stunnel4 service file + copy: src=lib/systemd/system/{{ item }} + dest=/lib/systemd/system/{{ item }} + owner=root group=root + mode=0644 + notify: + - systemctl daemon-reload + with_items: + - stunnel4.service + - stunnel4@.service diff --git a/roles/common/templates/etc/stunnel/bacula-fd.conf.j2 b/roles/common/templates/etc/stunnel/bacula-fd.conf.j2 index ed819c0..851f0ac 100644 --- a/roles/common/templates/etc/stunnel/bacula-fd.conf.j2 +++ b/roles/common/templates/etc/stunnel/bacula-fd.conf.j2 @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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/bacula-fd.pid +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/stunnel/certs/{{ inventory_hostname_short }}-fd.pem key = /etc/stunnel/certs/{{ inventory_hostname_short }}-fd.key ; Some performance tunings socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1 ; Prevent MITM attacks verify = 4 ; Disable support for insecure protocols diff --git a/roles/common/templates/etc/stunnel/munin-node.conf.j2 b/roles/common/templates/etc/stunnel/munin-node.conf.j2 index 83614b5..229def0 100644 --- a/roles/common/templates/etc/stunnel/munin-node.conf.j2 +++ b/roles/common/templates/etc/stunnel/munin-node.conf.j2 @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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/munin-node.pid +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/stunnel/certs/munin-{{ inventory_hostname_short }}.pem key = /etc/stunnel/certs/munin-{{ inventory_hostname_short }}.key ; Some performance tunings socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1 ; Prevent MITM attacks verify = 4 ; Disable support for insecure protocols diff --git a/roles/munin-master/handlers/main.yml b/roles/munin-master/handlers/main.yml index 4c41033..f65376c 100644 --- a/roles/munin-master/handlers/main.yml +++ b/roles/munin-master/handlers/main.yml @@ -3,22 +3,22 @@ command: /bin/systemctl daemon-reload - name: Restart rrdcached service: name=rrdcached state=restarted - name: Restart munin service: name=munin state=restarted - name: Restart munin-node service: name=munin-node state=restarted - name: Restart munin-cgi-graph service: name=munin-cgi-graph state=restarted - name: Restart munin-cgi-html service: name=munin-cgi-html state=restarted - name: Restart Nginx service: name=nginx state=restarted -- name: Restart stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=restarted +- name: Restart stunnel@munin-master + service: name=stunnel4@munin-master state=restarted diff --git a/roles/munin-master/tasks/main.yml b/roles/munin-master/tasks/main.yml index 4b3cfb7..1580197 100644 --- a/roles/munin-master/tasks/main.yml +++ b/roles/munin-master/tasks/main.yml @@ -86,51 +86,54 @@ state=link force=yes register: r2 notify: - Restart Nginx - name: Start Nginx service: name=nginx state=started when: not (r1.changed or r2.changed) - meta: flush_handlers - name: Copy munin-node X.509 certificates copy: src=certs/munin/{{ item }}.pem dest=/etc/stunnel/certs/munin-{{ hostvars[item].inventory_hostname_short }}.pem owner=root group=root mode=0644 with_items: "{{ groups.all | difference([inventory_hostname]) }}" register: r1 notify: - - Restart stunnel + - Restart stunnel@munin-master - name: Configure stunnel template: src=etc/stunnel/munin-master.conf.j2 dest=/etc/stunnel/munin-master.conf owner=root group=root mode=0644 register: r2 notify: - - Restart stunnel + - Restart stunnel@munin-master -- name: Start stunnel - service: name=stunnel4 pattern=/usr/bin/stunnel4 state=started +- name: Enable stunnel@munin-master + service: name=stunnel4@munin-master enabled=yes + +- name: Start stunnel@munin-master + service: name=stunnel4@munin-master state=started when: not (r1.changed or r2.changed) - meta: flush_handlers - name: Install 'munin_stats' and 'munin_update' plugins file: src=/usr/share/munin/plugins/{{ item }} dest=/etc/munin/plugins/{{ item }} owner=root group=root state=link force=yes with_items: - munin_stats - munin_update tags: - munin-node - munin notify: - Restart munin-node diff --git a/roles/munin-master/templates/etc/stunnel/munin-master.conf.j2 b/roles/munin-master/templates/etc/stunnel/munin-master.conf.j2 index bbe4114..ffc7d0d 100644 --- a/roles/munin-master/templates/etc/stunnel/munin-master.conf.j2 +++ b/roles/munin-master/templates/etc/stunnel/munin-master.conf.j2 @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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/munin-master.pid +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/stunnel/certs/munin-{{ inventory_hostname_short }}.pem key = /etc/stunnel/certs/munin-{{ inventory_hostname_short }}.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 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,39 +1,32 @@ -- 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 owner=root group=root mode=0755 - 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/smtp.conf.j2 index 9003686..ba38bfa 100644 --- a/roles/webmail/templates/etc/stunnel/postfix.conf.j2 +++ b/roles/webmail/templates/etc/stunnel/smtp.conf.j2 @@ -1,30 +1,31 @@ ; ************************************************************************** ; * 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 +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 @@ -34,24 +35,24 @@ 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 +CAfile = /etc/stunnel/certs/smtp.pem protocol = smtp ; vim:ft=dosini |