mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
Require a token to scrape /metrics
The metrics endpoint fans out a gather to every connected host, so anyone who could reach the controller could read cluster statistics and put load on all hosts at will. Scraping now needs a user token holding the new core.controller.metrics permission. The token is accepted via Authorization: Bearer as well as X-Access-Token because Prometheus can only send the former. Concurrent scrapes share one gather so hosts see at most one metrics request at a time. The three connection gauges in controller.ts now no-op before the controller exists, like the other gauges there, so the endpoint can be tested against the mock controller. Closes #1009 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
2b981a5734
commit
87aa7b3b4c
6 files changed
+151
-10
No files matched your search
@@ -274,3 +274,28 @@ Remote updates are enabled by default but can be disabled on a per-machine basis
|
||||
controller> config set controller.allow_plugin_install true/false
|
||||
|
||||
Remote installs are disabled by default but can be enabled on a per-machine basis at the owner's discretion. For security reasons, this configuration setting cannot be changed remotely. To modify it, run the above commands locally while the remote is offline.
|
||||
|
||||
|
||||
## Prometheus Metrics
|
||||
|
||||
The controller exports metrics for the whole cluster on the `/metrics` endpoint.
|
||||
Fetching it requires a token for a user with the `core.controller.metrics` permission, sent either as an `Authorization: Bearer <token>` header or as an `X-Access-Token` header.
|
||||
Requests without a valid token get a 401 response and requests for users lacking the permission get a 403 response.
|
||||
|
||||
Create a role with just this permission, a user to hold it, and generate a token for that user:
|
||||
|
||||
ctl> role create Prometheus --permissions core.controller.metrics
|
||||
ctl> user create prometheus
|
||||
ctl> user set-roles prometheus Prometheus
|
||||
$ npx clusteriocontroller bootstrap generate-user-token prometheus
|
||||
|
||||
Then pass the token in the scrape job for the controller in `prometheus.yml`:
|
||||
|
||||
scrape_configs:
|
||||
- job_name: clusterio
|
||||
authorization:
|
||||
credentials: <token>
|
||||
static_configs:
|
||||
- targets: ["localhost:8080"]
|
||||
|
||||
Concurrent scrapes share a single round of metrics gathering from the hosts, so multiple scrapers polling the controller do not multiply the load on the hosts.
|
||||
Reference in new issue
Block a user