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

Commit d1824cf

Browse files
ecksunpaulfantom
authored andcommitted
Lock down systemd service (#68)
To be on the safe side, restrict what the service can do.
1 parent 2d7026c commit d1824cf

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tasks/preflight.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
when: item in node_exporter_enabled_collectors
1616
with_items: "{{ node_exporter_disabled_collectors }}"
1717

18+
- name: Get systemd version
19+
shell: systemctl --version | awk '$1 == "systemd" {print $2}'
20+
changed_when: false
21+
check_mode: false
22+
register: node_exporter_systemd_version
23+
tags:
24+
- skip_ansible_lint
25+
1826
- name: Get checksum list from github
1927
set_fact:
2028
_checksums: "{{ lookup('url', 'https://github.com/prometheus/node_exporter/releases/download/v' + node_exporter_version + '/sha256sums.txt', wantlist=True) | list }}"

templates/node_exporter.service.j2

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,18 @@ ExecStart=/usr/local/bin/node_exporter \
2727
SyslogIdentifier=node_exporter
2828
Restart=always
2929

30+
PrivateTmp=yes
31+
ProtectHome=yes
32+
NoNewPrivileges=yes
33+
34+
{% if node_exporter_systemd_version.stdout | int >= 232 %}
35+
ProtectSystem=strict
36+
ProtectControlGroups=true
37+
ProtectKernelModules=true
38+
ProtectKernelTunables=yes
39+
{% else %}
40+
ProtectSystem=full
41+
{% endif %}
42+
3043
[Install]
3144
WantedBy=multi-user.target

0 commit comments

Comments
 (0)