Skip to content

Commit

Permalink
fix(node_exporter): Fix ProtectHome for textfiles
Browse files Browse the repository at this point in the history
Set the node_exporter `ProtectHome=read-only` when the textfile dir is
in `/home`.

Fixes: #183

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ authored and gardar committed Aug 17, 2023
1 parent c3d24a0 commit 55507f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions roles/node_exporter/molecule/latest/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- prometheus.prometheus.node_exporter
vars:
node_exporter_version: latest
node_exporter_textfile_dir: "/home/node_exporter"
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def test_files(host, files):
assert f.is_file


def test_directories(host):
dirs = [
"/home/node_exporter"
]
for dir in dirs:
d = host.file(dir)
assert d.is_directory
assert d.exists


def test_service(host):
s = host.service("node_exporter")
# assert s.is_enabled
Expand All @@ -28,7 +38,7 @@ def test_service(host):
def test_protecthome_property(host):
s = host.service("node_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"
assert p.get("ProtectHome") == "read-only"


def test_socket(host):
Expand Down
3 changes: 3 additions & 0 deletions roles/node_exporter/templates/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ StartLimitInterval=0
{% for m in ansible_mounts if m.mount.startswith('/home') %}
{% set ns.protect_home = 'read-only' %}
{% endfor %}
{% if node_exporter_textfile_dir.startswith('/home') %}
{% set ns.protect_home = 'read-only' %}
{% endif %}
ProtectHome={{ ns.protect_home }}
NoNewPrivileges=yes

Expand Down

0 comments on commit 55507f9

Please sign in to comment.