Skip to content

Stop serving Grafana's /metrics endpoint to the public #745

Closed

Description

@HMarzban

Summary

https://grafana.docs.plus/metrics answers 200 to anyone, with no sign-in. It returns Grafana's internal Prometheus metrics, including alert rule group names and request counts by route. This issue changes one Traefik router label, so the public router no longer serves any path under /metrics. Grafana's sign-in pages and API keep working. It also turns Grafana's metrics off at the source, so a later router change cannot make them public again.

Benchmark

Field Value
Metric (1) Probed public paths that return Grafana metrics, count out of 6. (2) Bytes on GET https://grafana.docs.plus/metrics with no sign-in.
Before Laptop curl with no credentials, 2026-11-11 12:08Z: (1) 4 of 6 (/metrics, //metrics, /./metrics, /%6detrics). (2) 905,142 B, 5,895 samples.
After Not measured yet.
Condition Public internet, production Traefik, within 15 minutes of the observability deploy. Responses are deterministic, so n = 1 per path.
How to run The Verify loop, with %{size_download} in the -w format. Inside the Grafana container: docker exec docsplus-grafana wget -qO- http://localhost:3000/metrics.
Pass rule (1) 0 of 6, with 0 grafana_build_info lines on every path. (2) Traefik's 404 body, under 100 B. Inside the container, wget fails with 404. Stop rule: if /login stops answering 200, or more alert rules are in Error than before, revert the commit.
Guard Grafana /login answers 200. /api/health shows "database": "ok". The count of alert rules in Error is the same or fewer than before the deploy. The observability deploy ends success.
Owner Agent in the repo: steps 1-2, 4 and the Verify loop. Maintainer: step 3, the alert-rule count and the in-container read.
Claim "Grafana's internal metrics are no longer public: 905,142 B readable by anyone → 0."

Rows

Metric Before (2026-11-11 12:08Z) After
Probed public paths that return Grafana metrics 4 of 6 Not measured yet
Bytes on GET https://grafana.docs.plus/metrics, no sign-in 905,142 B, 5,895 samples Not measured yet
/metrics from inside the Grafana container Served Not measured yet
Grafana /login 200 Not measured yet
/api/health database field "database": "ok" Not measured yet
Alert rules in Error Not counted; it can no longer be taken (review, 2026-11-16) Covered by the #753 check: 66 provisioned, all healthy
Observability deploy — Not measured yet

Evidence

  • curl from a laptop, 2026-11-11 12:08Z, no credentials. GET https://grafana.docs.plus/metrics returned 200, 905,142 bytes and 5,895 samples. It holds 50 grafana_http_request_duration_seconds_count series and one grafana_alerting_rule_group_rules series per rule group, each with the group name.

  • Same read. //metrics, /./metrics and /%6detrics also return the metrics. /metrics/, /METRICS and /%2Fmetrics return a 302 to the sign-in page.

  • Read from code at 0b302b222. docker-compose.observability.yml:134 is the router rule:

    - 'traefik.http.routers.grafana.rule=Host(`grafana.docs.plus`)'

    The rule sends every path on that host to Grafana. Grafana serves /metrics without auth by default. The service at :112-148 sets no GF_METRICS_* variable.

  • Read from code. No Prometheus job scrapes Grafana (scripts/observability/prometheus/), so nothing in our stack reads this endpoint.

  • Local probe, 2026-11-11. A router with the rule in step 1, in front of a backend that answers 200 on every path. On Traefik 3.6.25 (production today) and on 3.7.18:

    • / and /api/health → 200;
    • /metrics, /metrics/, //metrics, /./metrics, /x/../metrics, /%6detrics and /metrics%2F → 404 from Traefik;
    • /METRICS and /%2Fmetrics still reach the backend. Grafana answers both with a 302 today, as above.

Risk

The endpoint shows a stranger our alert rule group names, alerting activity, request counts by route and Go runtime details. That maps our monitoring for anyone who wants to avoid it. It costs nothing to close. (/api/health also prints the version; that stays, because it holds nothing else.)

Steps

Deploy: one observability deploy. It recreates the Grafana container, so Grafana is down for a few seconds. Traefik does not restart. If #743 step 4 ran since the last observability deploy, this deploy recreates Loki, Prometheus, Grafana, Alloy and blackbox (#743 step 4g). Do not take another issue's observability before read that day.

  1. Owner: agent in the repo. Turn metrics off in Grafana, and keep the router rule as a second layer.

    • Add GF_METRICS_ENABLED: 'false' to the Grafana environment in docker-compose.observability.yml. No Prometheus job scrapes Grafana (scripts/observability/prometheus/prometheus.yml), so nothing loses data.
    • Edit docker-compose.observability.yml:134 to:
    - 'traefik.http.routers.grafana.rule=Host(`grafana.docs.plus`) && !PathPrefix(`/metrics`)'

    Add one comment line above it: # Grafana serves /metrics without auth; nothing outside the stack reads it.

    The !PathPrefix rule needs no Grafana setting. GF_METRICS_ENABLED needs no path matching. Each one covers a mistake in the other.

  2. Owner: agent in the repo. docker compose -f docker-compose.observability.yml config -q 2>/dev/null; echo rc=$? prints rc=0. On a laptop, warnings about unset variables are expected; the redirect hides them. Then a review checkpoint.

  3. Owner: maintainer. Depends on: Fail the observability deploy when Grafana or its provisioned rules do not load #753 live. Before the deploy, record the number of alert rules in Error (Grafana → Alerting → Alert rules). Commit through the commit-review skill with a (build): observability subject, and push to main. Or, after the commit lands, dispatch the deploy: gh workflow run observability.docs.plus.yml --repo docs-plus/docs.plus --ref main -f action=update.

  4. Owner: agent in the repo, from a laptop. Run Verify within 15 minutes of the deploy.

Verify

Owner: agent in the repo, from a laptop.

for p in /metrics //metrics /./metrics /%6detrics /METRICS /%2Fmetrics; do
  r=$(curl -s --path-as-is -o /tmp/gm.out -w '%{http_code} %{size_download}' "https://grafana.docs.plus$p")
  printf '%s %s %s\n' "$r" "$(grep -c '^grafana_build_info' /tmp/gm.out)" "$p"
done
curl -s -o /dev/null -w '%{http_code} login\n' https://grafana.docs.plus/login
curl -s https://grafana.docs.plus/api/health | grep -o '"database": *"ok"'
Line Before (2026-11-11) After
/metrics 200 905142 1 404 <bytes under 100> 0
//metrics, /./metrics, /%6detrics 200 <bytes> 1 404 <bytes under 100> 0
/METRICS, /%2Fmetrics 302 <bytes> 0 302 <bytes> 0
login 200 200
/api/health "database": "ok" "database": "ok"

The columns are the status, the body bytes and the count of grafana_build_info lines. The count must be 0 on every path after the fix.

Owner: maintainer, SSH. Optional (review, 2026-11-16). Inside the container, run the healthcheck's wget against /metrics instead of /api/health: docker exec docsplus-grafana wget -qO- http://localhost:3000/metrics >/dev/null; echo rc=$?. Pass: wget fails with a 404, so rc is not 0.

Rollback

Revert the commit and deploy with (build): observability. The endpoint is public again.

Acceptance criteria

  • Every Verify line matches the After column.
  • /metrics inside the Grafana container answers 404. Optional (review, 2026-11-16): the public probes and GF_METRICS_ENABLED: 'false' already cover it.
  • Grafana sign-in works, and its alert rules still evaluate. Grafana → Alerting → Alert rules lists no more rules in Error than before the deploy.
  • The observability deploy ends success.
  • The Benchmark After values are posted here.

Related

  • Future observability work may scrape Grafana inside the stack. A Prometheus job reaches the container on the Docker network, not through this router. Such work must first set GF_METRICS_ENABLED back to true, behind basic auth (GF_METRICS_BASIC_AUTH_*).

Activity

  1. added this to the v2.3.6 milestone on Nov 11, 2026
  2. added
    Security
    on Nov 11, 2026
  3. HMarzban commented on Nov 12, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-12: production after the observability deploy. Run 43224277563 ((build): observability, f61647754). Steps 1 to 8 passed, including "Deploy stack" at 13:08:16Z. A newer push cancelled the last step, Verify, during its wait, so its checks were read by hand, read-only, at about 13:12Z.

    Check Before (2026-11-11) After
    GET https://grafana.docs.plus/metrics 200, 905,142 B 404

    Grafana runs with GF_METRICS_ENABLED=false, and the router refuses /metrics as a second layer.

  4. HMarzban commented on Nov 14, 2026

    @HMarzban
    CollaboratorAuthor

    Moved to v2.3.7 at the v2.3.6 release audit. The after shows only /metrics 404. The other 5 paths, bytes, in-container read and alert-rule count are not posted.

  5. modified the milestones: v2.3.6, v2.3.7 on Nov 14, 2026
  6. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-16

    Steps 1 and 2 were already live (d272c50f3, 0a4de0890, deployed in run 43224277563 on 2026-11-12). This pass changed no file. It re-checked the compose config and read the public paths from a laptop. The read ran 4 days after the deploy, not within 15 minutes of it, so it shows the steady state, not the first minutes.

    What changed

    • No new change. GF_METRICS_ENABLED: 'false' is set, and the router rule is Host(`grafana.docs.plus`) && !PathPrefix(`/metrics`).
    • Step 2: docker compose -f docker-compose.observability.yml config -q 2>/dev/null; echo rc=$? prints rc=0.

    Before and after

    Metric Before (2026-11-11 12:08Z) After (2026-11-16 11:08:57Z) n, range, condition, source
    Public paths that serve Grafana metrics 4 of 6 0 of 6 n = 1 per path, fixed responses. Laptop curl, no credentials, production Traefik, 4 days after the deploy
    Bytes on GET /metrics, no sign-in 905,142 B, 200 19 B, 404, 0 grafana_build_info lines same read. 99% fewer bytes
    //metrics, /./metrics, /%6detrics 200, metrics 404 19 0 each same read
    /METRICS, /%2Fmetrics 302 302 51 0, 302 56 0 same read
    /login 200 200 same read
    /api/health "database": "ok" "database": "ok" same read
    /metrics inside the Grafana container served not read (needs SSH) maintainer
    Alert rules in Error not counted not counted maintainer

    The read printed only status codes and byte counts. The bodies were deleted.

    Verify loop (run within 15 minutes of the next observability deploy)

    for p in /metrics //metrics /./metrics /%6detrics /METRICS /%2Fmetrics; do
      r=$(curl -s --path-as-is -o /tmp/gm.out -w '%{http_code} %{size_download}' "https://grafana.docs.plus$p")
      printf '%s %s %s\n' "$r" "$(grep -c '^grafana_build_info' /tmp/gm.out)" "$p"
    done
    curl -s -o /dev/null -w '%{http_code} login\n' https://grafana.docs.plus/login
    curl -s https://grafana.docs.plus/api/health | grep -o '"database": *"ok"'

    Inside the container (maintainer, SSH):

    docker exec docsplus-grafana wget -qO- http://localhost:3000/metrics >/dev/null; echo rc=$?

    Pass: every metrics path shows 404 <under 100> 0. /METRICS and /%2Fmetrics show 302 <bytes> 0. login shows 200. /api/health shows "database": "ok". The in-container rc is not 0.

    Gates

    • docker compose -f docker-compose.observability.yml config -q: pass (rc=0).
    • bunx prettier --check docker-compose.observability.yml: pass.

    Left

    • Maintainer: count the alert rules in Error before the next observability deploy, then after it.
    • Maintainer: run the in-container wget read over SSH.
    • Agent from a laptop: run the Verify loop within 15 minutes of that deploy, and post all 6 lines.
  7. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Measured, 2026-11-16: Verify loop after the observability deploy

    Run from one laptop at 2026-11-16 13:47:54Z, 4 minutes after the (build): observability deploy (288d4d260, run 43878530215, started 13:43:32Z). That deploy recreated Grafana.

    404 19 0 /metrics
    404 19 0 //metrics
    404 19 0 /./metrics
    404 19 0 /%6detrics
    302 51 0 /METRICS
    302 56 0 /%2Fmetrics
    200 login
    "database": "ok"
    

    Pass: every metrics path shows 404 <under 100> 0, /METRICS and /%2Fmetrics show 302 <bytes> 0, login is 200, and /api/health shows "database": "ok". The read printed only status codes and byte counts.

    Metric Before (2026-11-11 12:08Z) After (2026-11-16 13:47Z)
    Public paths that serve Grafana metrics 4 of 6 0 of 6 (none)
    Bytes on GET /metrics, no sign-in 905,142 B, 200 19 B, 404 (99 % fewer)

    Alert rules after the deploy: 66 provisioned, all healthy (the #753 check printed got = want = 66).

    Left: the in-container wget read (maintainer, SSH).

  8. HMarzban commented on Nov 16, 2026

    @HMarzban
    CollaboratorAuthor

    Review, 2026-11-16 (maintainer approved).

    Closed: the fix is live and the Verify loop passed. The 2026-11-16 13:47Z Measured comment ran 4 minutes after deploy 288d4d260 (run 43878530215). Public paths that serve Grafana metrics went from 4 of 6 to 0 of 6. GET /metrics went from 905,142 B with 200 to 19 B with 404. Login answers 200, and /api/health shows "database": "ok". Alert rules: 66 provisioned, all healthy (#753 check, got = want = 66). That covers the Error guard, whose before count can no longer be taken. The repo holds both layers: GF_METRICS_ENABLED: 'false' and the !PathPrefix rule in docker-compose.observability.yml. The body now marks the in-container wget optional, so it does not hold the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DevOpsSecurity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions