-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
nixos/prometheus: systemd unit hardening of exporters #133189
Conversation
49a6d9d
to
f3ca9e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unable to run OpenVPN, PyAirControl and Kea tests as they seem broken even without these changes.
Kea fixed in #133201, please rebase.
Poking @lheckemann for OpenVPN
openvpn # [ 11.470102] openvpn_exporter[784]: 2021/08/09 00:01:29 Starting OpenVPN Exporter
openvpn # [ 11.486253] openvpn_exporter[784]: 2021/08/09 00:01:29 Listen address: 0.0.0.0:9176
openvpn: output:
Traceback (most recent call last):
File "/nix/store/2c972bcrwpqz8lcmq94r5m4yda89a5sa-nixos-test-driver/bin/.nixos-test-driver-wrapped", line 1065, in <module>
run_tests(args.interactive)
File "/nix/store/2c972bcrwpqz8lcmq94r5m4yda89a5sa-nixos-test-driver/bin/.nixos-test-driver-wrapped", line 937, in run_tests
test_script()
File "/nix/store/2c972bcrwpqz8lcmq94r5m4yda89a5sa-nixos-test-driver/bin/.nixos-test-driver-wrapped", line 1035, in test_script
openvpn # [ 11.493818] openvpn_exporter[784]: 2021/08/09 00:01:29 Metrics path: /metrics
exec(pathlib.Path(args.testscript).read_text(), globals())
File "<string>", line 4, in <module>
File "/nix/store/2c972bcrwpqz8lcmq94r5m4yda89a5sa-nixos-test-driver/bin/.nixos-test-driver-wrapped", line 482, in succeed
raise Exception(
Exception: command `curl -sSf http://localhost:9176/metrics | grep 'openvpn_up{.*} 1'` failed (exit code 1)
cleaning up
killing openvpn (pid 9)
(0.00 seconds)
builder for '/nix/store/abcvk9zh8bfbgqq6q9d4afk36siaxjhq-vm-test-run-prometheus-openvpn-exporter.drv' failed with exit code 1
Poking @mupdt @urbas for py-air-control-exporter, which has failing tests and therefore fails to build.
============================= test session starts ==============================
platform linux -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /build/py-air-control-exporter-0.3.0, configfile: setup.cfg
plugins: cov-2.12.1
collected 17 items
test/test_app.py . [ 5%]
test/test_main.py F..F. [ 35%]
test/test_metrics.py ........... [100%]
=================================== FAILURES ===================================
__________________________________ test_help ___________________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7ffff55dc220>
capfd = <_pytest.capture.CaptureFixture object at 0x7ffff55a4310>
def test_help(monkeypatch, capfd):
monkeypatch.setattr(sys, "argv", ["app-name", "--help"])
with pytest.raises(SystemExit) as ex_info:
main()
assert ex_info.value.code == 0
> assert "Usage: app-name" in capfd.readouterr().out
E AssertionError: assert 'Usage: app-name' in 'Usage: python -m pytest.app-name [OPTIONS]\n\nOptions:\n --host TEXT The hostname of the air pur... requests. [default: 9896]\n --help Show this message and exit.\n'
E + where 'Usage: python -m pytest.app-name [OPTIONS]\n\nOptions:\n --host TEXT The hostname of the air pur... requests. [default: 9896]\n --help Show this message and exit.\n' = CaptureResult(out='Usage: python -m pytest.app-name [OPTIONS]\n\nOptions:\n --host TEXT The hostn... requests. [default: 9896]\n --help Show this message and exit.\n', err='').out
E + where CaptureResult(out='Usage: python -m pytest.app-name [OPTIONS]\n\nOptions:\n --host TEXT The hostn... requests. [default: 9896]\n --help Show this message and exit.\n', err='') = <bound method CaptureFixture.readouterr of <_pytest.capture.CaptureFixture object at 0x7ffff55a4310>>()
E + where <bound method CaptureFixture.readouterr of <_pytest.capture.CaptureFixture object at 0x7ffff55a4310>> = <_pytest.capture.CaptureFixture object at 0x7ffff55a4310>.readouterr
test/test_main.py:15: AssertionError
____________________________ test_unknown_protocol _____________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7ffff55217c0>
capfd = <_pytest.capture.CaptureFixture object at 0x7ffff55bf070>
def test_unknown_protocol(monkeypatch, capfd):
"""check that failure is reporter if an invalid protocol is provided"""
monkeypatch.setattr(
sys, "argv", ["app-name", "--host", "192.168.1.123", "--protocol", "foobar"]
)
with pytest.raises(SystemExit) as ex_info:
main()
assert ex_info.value.code != 0
> assert "invalid choice: foobar" in capfd.readouterr().err
E assert 'invalid choice: foobar' in "Usage: python -m pytest.app-name [OPTIONS]\nTry 'python -m pytest.app-name --help' for help.\n\nError: Invalid value for '--protocol': 'foobar' is not one of 'http', 'coap', 'plain_coap'.\n"
E + where "Usage: python -m pytest.app-name [OPTIONS]\nTry 'python -m pytest.app-name --help' for help.\n\nError: Invalid value for '--protocol': 'foobar' is not one of 'http', 'coap', 'plain_coap'.\n" = CaptureResult(out='', err="Usage: python -m pytest.app-name [OPTIONS]\nTry 'python -m pytest.app-name --help' for help.\n\nError: Invalid value for '--protocol': 'foobar' is not one of 'http', 'coap', 'plain_coap'.\n").err
E + where CaptureResult(out='', err="Usage: python -m pytest.app-name [OPTIONS]\nTry 'python -m pytest.app-name --help' for help.\n\nError: Invalid value for '--protocol': 'foobar' is not one of 'http', 'coap', 'plain_coap'.\n") = <bound method CaptureFixture.readouterr of <_pytest.capture.CaptureFixture object at 0x7ffff55bf070>>()
E + where <bound method CaptureFixture.readouterr of <_pytest.capture.CaptureFixture object at 0x7ffff55bf070>> = <_pytest.capture.CaptureFixture object at 0x7ffff55bf070>.readouterr
test/test_main.py:59: AssertionError
----------- coverage: platform linux, python 3.9.6-final-0 -----------
Name Stmts Miss Cover
--------------------------------------------------------
py_air_control_exporter/app.py 10 0 100%
py_air_control_exporter/main.py 9 0 100%
py_air_control_exporter/metrics.py 75 0 100%
--------------------------------------------------------
TOTAL 94 0 100%
=========================== short test summary info ============================
FAILED test/test_main.py::test_help - AssertionError: assert 'Usage: app-name...
FAILED test/test_main.py::test_unknown_protocol - assert 'invalid choice: foo...
========================= 2 failed, 15 passed in 1.07s =========================
nixos/modules/services/monitoring/prometheus/exporters/bird.nix
Outdated
Show resolved
Hide resolved
nixos/modules/services/monitoring/prometheus/exporters/influxdb.nix
Outdated
Show resolved
Hide resolved
deccb3d
to
e82208b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add AF_UNIX as default instead of adding it to every other exporter?
What's the point of hardening if you hand out permissions like candy? |
A Prometheus exporter should not require |
e82208b
to
9d7419b
Compare
Fixed by 06a8b08. I just rebased this PR to include this fix. OpenVPN exporter is still broken: |
The OpenVPN exporter has been broken with OpenVPN 2.5.0 (31cf796). I submitted an issue upstream: kumina/openvpn_exporter#48 Maybe we could: What is your opinion? |
OpenVPN exporter is now unmaintained: kumina/openvpn_exporter@1cd8158 Should we remove this exporter from NixOS? |
I think marking it as broken is the first step to removing it. |
I can add |
I have marked prometheus-openvpn-exporter as broken. I don't know what should be done with the corresponding test. |
Is the openvpn-exporter the only thing that's missing from getting this merged? :) |
Yes I believe so. This exporter is broken and upstream is now unmaintained. |
@mweinelt what change do you require? |
@GrahamcOfBorg eval |
I'm fine with the broken mark, we didn't have a module for it anyway (pending me finishing #98735 with a test)? I'll hopefully find some time to fix or replace it eventually, but that time is not now :/ |
Prometheus OpenVPN exporter has been broken since OpenVPN 2.5.0 changed the format of the datetime to ISO8601. After submitting an issue to upstream, the upstream decided to no longer maintain this exporter.
48e8dda
to
0b6148f
Compare
Thank you! |
This also breaks the node-exporter filesystem exporter for anything mounted under /home. ProtectHome needs to be set to false, or possibly some read-only state? |
Same for the
|
The filesystem export works for |
The problem affects any filesystem mounted under /home, i.e. /home/foo, /home/.zfs/snapshot automounts, or similar. It does not affect /home itself; that directory entry is part of /, so it's still readable even with ProtectHome enabled. |
Motivation for this change
This increases the isolation of Prometheus exporters service.
I was unable to run OpenVPN, PyAirControl and Kea tests as they seem broken even without these changes.
Things done
sandbox
innix.conf
on non-NixOS linux)