Repository navigation
feat: sign module auth token, metrics password - #1429
Conversation
7014e81 to
14d48bc
Compare
14d48bc to
b2d23da
Compare
b2d23da to
ab0bef7
Compare
DavidePrincipi
left a comment
There was a problem hiding this comment.
Works with ns8-metrics#120 as designed. Please add the Robot tests for the new response, see inline comments.
| Alertmanager, read from the metrics module running on this (leader) | ||
| node, or None if it cannot be read.""" | ||
| try: | ||
| metrics_id = agent.redis_connect().get('cluster/default_instance/metrics') |
There was a problem hiding this comment.
In an uninitialized cluster Metrics is not installed.
| metrics_id = agent.redis_connect().get('cluster/default_instance/metrics') | |
| metrics_id = agent.redis_connect().get('cluster/default_instance/metrics') | |
| if not metrics_id: | |
| return None |
| # Prometheus requires the metrics module password | ||
| PROM_AUTH = cluster.metrics.basic_auth() | ||
|
|
||
| def discover_prom_query_url(base_url): |
There was a problem hiding this comment.
Metrics no longer sets a URL prefix for Prometheus, so this discovery can go. Replace the function and its call with:
PROM_QUERY_URL = "http://127.0.0.1:9091/api/v1/query"Until metrics is updated, clusters that set prometheus_path with api-cli lose node data: same recovery as the other cases, update metrics.
| if token, errSign := SignModuleToken(configuration.Config.TokenSigningKey, username, c.Param("module_id")); errSign != nil { | ||
| utils.LogError(errors.Wrap(errSign, "[BASIC AUTH] token signing failed for user "+username)) | ||
| } else { | ||
| c.Header("X-Auth-Token", token) |
There was a problem hiding this comment.
Please extend core/api-server/test/suite/50__basic_auth_2fa.robot to cover the new response: X-Auth-Token claims on success (sub, aud, iss, 60 seconds), no token on 401 and 403, and GET /module-token-pubkey without login. The Go unit tests cover signing only, not the handler and the route.
Modules behind Traefik forward auth only receive X-Auth-User, a plain header any local process can also send. api-server now adds X-Auth-Token, a 60 seconds EdDSA JWT for the user and the module, and serves its public key without login at /api/module-token-pubkey. Each node derives the key from its existing SECRET, so there is nothing to manage on install, update or leader change. The metrics Prometheus and Alertmanager now require a password, kept in the metrics module state. list-alerts and list-nodes run as root on the leader node, like the metrics module, and read it from there. bcrypt is added to the agent Python so modules can hash passwords. Assisted-by: Claude Code:claude-opus-5.5
ns8-metrics no longer exposes Prometheus through Traefik and no longer has the prometheus_path setting, so the metrics settings page does not need to read or send it. Assisted-by: Claude Code:claude-opus-5.5
ab0bef7 to
5632258
Compare
Local services of the metrics module (Prometheus, Alertmanager and Grafana) trust any program that connects from the same server. This PR gives core what it needs so the metrics module can stop trusting local connections. It must be released before the matching metrics change, which will require this core version.
Nothing changes for users. api-server now adds a short-lived signed token next to the user name it already sends to Traefik. Each node derives its signing key from its existing
SECRET, so there is no new key to manage on install, update or leader change. Core reads the new metrics password to list the active alerts.bcryptadded to the agent Python package lists, so modules can hash passwords.X-Auth-Token(EdDSA JWT, 60 seconds,aud=module/<id>) from the modulehttp-basicendpoint, and serves its public key without login atGET /api/module-token-pubkey.list-alertsandlist-nodesread the metrics password frombasic_auth.jsonin the metrics module state and send it to Alertmanager and Prometheus. They run as root on the leader node, where metrics also runs. Core and metrics are updated together.prometheus_path: metrics no longer exposes Prometheus through Traefik.How to test
curl http://127.0.0.1:9311/api/module-token-pubkeyreturns a PEM public key, the same after an api-server restart.See also
Generated by Claude Code:claude-opus-5.5 with nethserver-pr