summaryrefslogtreecommitdiffstats
path: root/roles/common
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2016-05-11 18:07:09 +0200
committerGuilhem Moulin <guilhem@fripost.org>2016-05-12 11:33:55 +0200
commit90d498034b891123350785a134402172de477f4f (patch)
treea6e3c924054c3f689cdaffffe3a479e88fb97282 /roles/common
parente370313ad5895871479fffc922e3c72c0375dbf2 (diff)
Use systemd unit files for stunnel4.
Diffstat (limited to 'roles/common')
-rw-r--r--roles/common/files/etc/logcheck/ignore.d.server/common-local2
-rw-r--r--roles/common/files/lib/systemd/system/stunnel4.service14
-rw-r--r--roles/common/files/lib/systemd/system/stunnel4@.service23
-rw-r--r--roles/common/handlers/main.yml7
-rw-r--r--roles/common/tasks/bacula.yml29
-rw-r--r--roles/common/tasks/main.yml8
-rw-r--r--roles/common/tasks/munin-node-ssl.yml58
-rw-r--r--roles/common/tasks/munin-node.yml68
-rw-r--r--roles/common/tasks/stunnel.yml20
-rw-r--r--roles/common/templates/etc/stunnel/bacula-fd.conf.j23
-rw-r--r--roles/common/templates/etc/stunnel/munin-node.conf.j23
11 files changed, 145 insertions, 90 deletions
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
@@ -37,4 +37,4 @@
^\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
@@ -38,8 +38,11 @@
- 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
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,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
@@ -24,7 +14,7 @@
changed_when: r1.rc == 0
failed_when: r1.rc > 1
notify:
- - Restart stunnel
+ - Restart stunnel@bacula-fd
tags:
- genkey
@@ -46,7 +36,7 @@
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
@@ -56,7 +46,7 @@
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
@@ -66,11 +56,16 @@
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
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
@@ -12,6 +12,9 @@
tags:
- firewall
- iptables
+
+- include: stunnel.yml
+ tags: stunnel
- include: samhain.yml
tags: samhain
- include: auditd.yml
@@ -59,6 +62,11 @@
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 }}
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
@@ -137,71 +137,3 @@
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
@@ -7,7 +7,8 @@ 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
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
@@ -7,7 +7,8 @@ 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