Skip to content

feat(server): metricsAddr, a telemetry listener that scrapers can reach - #33

Merged
blakebauman merged 1 commit into
mainfrom
feat/metrics-listener
Aug 11, 2026
Merged

blakebauman merged 1 commit into
mainfrom
feat/metrics-listener

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Closes the /metrics 403 found while building the compose observability profile (#31), and makes the chart's ServiceMonitor work for the first time.

The problem

DNS-rebinding protection covers /metrics like every other path, so a scraper arriving under any name outside server.allowedHosts is answered 403 — the target reads as "down" with no other symptom. A pod IP is a Host no static allowlist can name.

Why not just exempt the path

A scrape names upstream ids, namespaces, tenant ids, and multi-endpoint upstreams' endpoint URLs — the federation's shape and its internal hostnames. On the loopback-bound default, exempting it would let any page an operator visits read that from their own machine.

And Origin checking cannot substitute: in a rebinding attack the page and the target share the attacker's hostname, so the browser treats the request as same-origin and sends no Origin header at all. The Host allowlist is the check that catches it.

What this does instead

server.metricsAddr moves /metrics and /health to their own listener — not an origin a browser can be steered to, so it needs no Host allowlist, and what guards it is being bound to an internal interface. The public port keeps its checks and stops carrying the disclosure: /metrics leaves that mux rather than being served in both places, since a second copy would forfeit the point.

  • Absent by default — nothing changes for anyone who doesn't set it.
  • The gateway owns the listener when the document asks for one; embedders who'd rather mount it themselves use the new MetricsHandler() and leave the field unset.
  • Binds eagerly, so a port in use fails New where an operator sees it, instead of vanishing into a log line while the gateway serves on without metrics.
  • Construction-wired; a reload rejects a change.

Chart

metrics.listener.enabled opens the container/service port, sets metricsAddr in the rendered config (an explicit value in config wins — the chart fills in only what was left unsaid), and points the ServiceMonitor at it. Rendered:

config server section -> {"allowedHosts": ["gw.example.com"], "metricsAddr": ":9090"}
container ports -> [('http', 8080), ('metrics', 9090)]
service ports   -> [('http', 8080, 'http'), ('metrics', 9090, 'metrics')]
servicemonitor  -> [('metrics', '/metrics')]

The default render is unchanged, port for port.

Tests

State the property, not the plumbing: a scrape under an unlisted Host is 403 on the main mux (pinning the behavior that motivated this), the same scrape succeeds under any Host on the telemetry listener, the move is a move and not a copy, Close releases the port, a bind failure fails New, MetricsHandler is mountable, and a reload rejects the change.

make check green, make helm-check green, latency gate 185 µs. Chart to 0.1.5. security-model.md gains "Telemetry is a disclosure surface" recording the reasoning above.

🤖 Generated with Claude Code

fold's DNS-rebinding protection covers /metrics like every other path, so a
scraper arriving under any name outside server.allowedHosts is answered 403 and
the target reads as down with no other symptom. That is why the chart's
ServiceMonitor could not scrape a pod IP, and why the compose profile needed
the service name allowlisted.

The obvious fix — exempt the path — is the wrong one here. A scrape names
upstream ids, namespaces, tenant ids, and multi-endpoint upstreams' endpoint
URLs: a description of the federation and its internal hostnames. On the
loopback-bound default, exempting it would let any page an operator visits read
that. Origin checking cannot substitute either: in a rebinding attack the page
and the target share the attacker's hostname, so the browser calls it
same-origin and sends no Origin header at all. The Host allowlist is the check
that catches it.

So server.metricsAddr moves /metrics and /health to their own listener instead.
It is not an origin a browser can be steered to, so it needs no Host allowlist,
and what guards it is that an operator binds it to an internal interface. The
public port keeps its checks and stops carrying the disclosure: /metrics leaves
that mux entirely rather than being served in both places, since a second copy
would forfeit the point.

Absent by default, so nothing changes for anyone who does not set it. The
gateway owns the listener when the document asks for one — an embedder who
would rather mount it themselves uses the new MetricsHandler and leaves the
field unset — and it binds eagerly, so a port already in use fails New where an
operator sees it rather than disappearing into a log line while the gateway
serves on without metrics. Construction-wired like the rest of the server
section; a reload rejects a change.

In the chart, metrics.listener.enabled opens the port, sets metricsAddr in the
rendered config (an explicit value in `config` wins — the chart fills in only
what was left unsaid), and points the ServiceMonitor at it, which makes that
ServiceMonitor work for the first time without "*" in allowedHosts. The default
render is unchanged, port for port.

Tests state the property rather than the plumbing: a scrape under an unlisted
Host is 403 on the main mux, the same scrape succeeds under any Host on the
telemetry listener, the move is a move and not a copy, Close releases the port,
a bind failure fails New, MetricsHandler is mountable, and a reload rejects the
change. Latency gate 185us; chart to 0.1.5.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 823dd0e into main Aug 11, 2026
6 checks passed
@blakebauman
blakebauman deleted the feat/metrics-listener branch August 11, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant