Repository navigation
feat!: require auth on local metrics services - #120
Merged
Merged
Conversation
This was referenced Nov 26, 2026
gsanchietti
force-pushed
the
hardening_2
branch
10 times, most recently
from
November 27, 2026 09:53
6a8705b to
d8d98c4
Compare
gsanchietti
force-pushed
the
hardening_2
branch
from
November 27, 2026 09:56
d8d98c4 to
cda4c90
Compare
gsanchietti
force-pushed
the
hardening_2
branch
from
November 27, 2026 13:29
3be1c99 to
8e20b75
Compare
gsanchietti
commented
Dec 1, 2026
gsanchietti
force-pushed
the
hardening_2
branch
from
December 1, 2026 07:40
8e20b75 to
46d4c62
Compare
gsanchietti
marked this pull request as ready for review
December 1, 2026 07:40
gsanchietti
force-pushed
the
hardening_2
branch
from
December 1, 2026 08:17
4ced642 to
46d4c62
Compare
DavidePrincipi
left a comment
Member
There was a problem hiding this comment.
Checked with ns8-core#1429: routes on update and leader change, Grafana token claims, file permissions. Minor points inline. Optional: unset the stale PROMETHEUS_PATH env var in 30routes.
| --label="org.nethserver.authorizations=traefik@node:routeadm" \ | ||
| --label="org.nethserver.rootfull=0" \ | ||
| --label="org.nethserver.max-per-node=1" \ | ||
| --label="org.nethserver.min-core=3.26.0" \ |
Member
There was a problem hiding this comment.
Match also pre-releases (for tests)
Suggested change
| --label="org.nethserver.min-core=3.26.0" \ | |
| --label="org.nethserver.min-core=3.26.0-0" \ |
Member
Author
There was a problem hiding this comment.
I'd prefer to avoid this and install with force option.
I fear to forget changing it before the merge
Member
There was a problem hiding this comment.
There's no need to change it before the merge. It's safe to merge it in the main branch and release it as stable.
gsanchietti
force-pushed
the
hardening_2
branch
from
December 1, 2026 15:11
46d4c62 to
90fc6d8
Compare
DavidePrincipi
approved these changes
Dec 2, 2026
DavidePrincipi
left a comment
Member
There was a problem hiding this comment.
LGTM. Only a merge conflict in the test suite.
Prometheus, Alertmanager and Grafana listen on 127.0.0.1 but trusted any local process: it could read metrics, mute or fake alerts, or become Grafana admin by sending one X-AUTH-USER header. Prometheus and Alertmanager now require one random password, kept in basic_auth.json in the module state and sent by Prometheus, the Grafana data sources, reload-prometheus-rules and test-alert. Core runs on the same node as root and reads the file to list the alerts. Grafana switches to auth.jwt and accepts only the token signed by the local api-server. restore-configuration and a new update step reuse the configure-module route code, so existing installs pass the new token. Prometheus is no longer exposed through Traefik; the README shows how to reach it for debugging. Requires the core release that serves the token key. Assisted-by: Claude Code:claude-opus-5.5
Prometheus is no longer exposed through Traefik, so the setting has no purpose. Remove it from configure-module and get-configuration, and always serve Prometheus at the root path. Assisted-by: Claude Code:claude-opus-5.5
metrics_alert_rules.py is a library, not a command. Move it to imageroot/pypkg, which the module agent puts on PYTHONPATH, next to the other module library. Assisted-by: Claude Code:claude-opus-5.5
Grafana's Alertmanager data source has no health check and always answers 500: query it through the Grafana proxy instead. The password key check ran redis-cli inside a "while read" loop, so redis-cli ate the key list and only the first key was checked. Assisted-by: Claude Code:claude-opus-5.5
Robot Framework reads %{name} as an environment variable, so every
curl -w '%{http_code}' check failed with "Environment variable
'%{http_code}' not found". Escape it as \%{http_code}.
Assisted-by: Claude Code:claude-opus-5.5
Each alert rule check starts promtool in a new unnamed container. With the default journald log driver, its output was copied to the journal under the random container name, so the log server indexed a new log name at every check. The caller already captures promtool output and reports errors, so disable the container log driver for these runs. Assisted-by: Claude Code:claude-opus-5-5
gsanchietti
force-pushed
the
hardening_2
branch
from
December 2, 2026 12:33
e37ba6f to
49f6ba9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prometheus, Alertmanager and Grafana listen only on 127.0.0.1, but trust any program that connects from there. Any process on the server could read metrics, mute or fake alerts, or become Grafana admin by sending one header. This PR closes those paths.
Prometheus and Alertmanager now ask for a password, and Grafana accepts only a short-lived token signed by core's api-server instead of the plain
X-AUTH-USERheader. Login through the cluster admin page looks the same to users. Prometheus is no longer exposed through Traefik: the/prometheusroute is removed, and the README shows how to reach it for debugging. Requires NethServer/ns8-core#1429 (min-coreis provisional).basic_auth.jsonin the module state directory; its hash goes into the web config shared by Prometheus and Alertmanager. Prometheus, the Grafana data sources,reload-prometheus-rulesandtest-alertsend it. Core runs as root on the same node and reads the file to list the alerts.[auth.proxy]to[auth.jwt], with the public key fetched from the local api-server at start.restore-configurationand a new update step reuse theconfigure-moduleroute code, so existing installs get routes that pass the new token.Hand-made Loki alert rules will no longer reach Alertmanager.
How to test
curl http://127.0.0.1:9091/,curl http://127.0.0.1:9093/api/v2/alertsandcurl -H 'X-AUTH-USER: admin' http://127.0.0.1:3000/grafana/api/userall answer 401./prometheusroute exists.CI
The automatic "Test module" run fails until NethServer/ns8-core#1429 is released: it installs the stable core, which has no token public key, so Grafana does not start. The suite passed on a temporary commit that installed the core of NethServer/ns8-core#1429 (install on debian13, update on rocky9): https://github.com/NethServer/ns8-metrics/actions/runs/46604244263. That commit is removed from this branch.
Also tested by hand on a two-node cluster with the core of NethServer/ns8-core#1429: Grafana, Prometheus and Alertmanager answer 401 without credentials, also with a forged
X-AUTH-USERheader or token, both on the node and through Traefik; the admin login works. Same results after promoting the worker to leader and back. The new leader installs the latest metrics release, so the instance was updated to this branch after each switch.See also
Generated by Claude Code:claude-opus-5.5 with nethserver-pr