Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: node_exporter - Fix Systemd ProtectHome option in service unit #94

Merged
merged 1 commit into from
May 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def test_service(host):
assert s.is_running


def test_protecthome_property(host):
s = host.service("node_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_socket(host):
sockets = [
"tcp://127.0.0.1:8080"
Expand Down
6 changes: 6 additions & 0 deletions roles/node_exporter/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_service(host):
assert s.is_running


def test_protecthome_property(host):
s = host.service("node_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_socket(host):
sockets = [
"tcp://127.0.0.1:9100"
Expand Down
6 changes: 6 additions & 0 deletions roles/node_exporter/molecule/latest/tests/test_alternative.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def test_service(host):
assert s.is_running


def test_protecthome_property(host):
s = host.service("node_exporter")
p = s.systemd_properties
assert p.get("ProtectHome") == "yes"


def test_socket(host):
s = host.socket("tcp://0.0.0.0:9100")
assert s.is_listening
6 changes: 3 additions & 3 deletions roles/node_exporter/templates/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ Restart=always
RestartSec=1
StartLimitInterval=0

{% set protect_home = 'yes' %}
{% set ns = namespace(protect_home = 'yes') %}
{% for m in ansible_mounts if m.mount.startswith('/home') %}
{% set protect_home = 'read-only' %}
{% set ns.protect_home = 'read-only' %}
{% endfor %}
ProtectHome={{ protect_home }}
ProtectHome={{ ns.protect_home }}
NoNewPrivileges=yes

{% if (ansible_facts.packages.systemd | first).version is version('232', '>=') %}
Expand Down