Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

increase systemd service security #42

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
that: ansible_service_mgr == 'systemd'
msg: "This role only works with systemd"

- name: Get systemd version
command: systemctl --version
changed_when: false
check_mode: false
register: __systemd_version
tags:
- skip_ansible_lint

- name: Set systemd version fact
set_fact:
blackbox_exporter_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}"

- name: Naive assertion of proper listen address
assert:
that:
Expand Down
22 changes: 21 additions & 1 deletion templates/blackbox_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Description=Blackbox Exporter
After=network-online.target
StartLimitInterval=0
StartLimitIntervalSec=0

[Service]
Type=simple
Expand All @@ -19,7 +20,26 @@ ExecStart=/usr/local/bin/blackbox_exporter \
SyslogIdentifier=blackbox_exporter
KillMode=process
Restart=always
RestartSec=1
RestartSec=5

CapabilityBoundingSet=CAP_SET_UID
LockPersonality=true
NoNewPrivileges=true
MemoryDenyWriteExecute=true
PrivateTmp=true
ProtectHome=true
RemoveIPC=true
RestrictSUIDSGID=true

{% if blackbox_exporter_systemd_version | int >= 232 %}
PrivateUsers=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=yes
ProtectSystem=strict
{% else %}
ProtectSystem=full
{% endif %}

[Install]
WantedBy=multi-user.target