Skip to content

metrics-plugin: add authentication - #12

Open
Nazarevsky wants to merge 3 commits into
masterfrom
feature/metrics-authentication
Open

Nazarevsky wants to merge 3 commits into
masterfrom
feature/metrics-authentication

Conversation

@Nazarevsky

@Nazarevsky Nazarevsky commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

The /metrics endpoint was previously served without any authentication, exposing node liquidity data to anyone who could reach the port. This adds bearer-token auth, gated behind an explicit opt-out for local/dev use.

What's changed

  • Added --metrics-token-file and --metrics-disable-auth plugin options. The plugin now refuses to start unless one of them is set, so /metrics can't be exposed unauthenticated by accident.
  • Token is read once at startup from the given file (never passed as a CLI arg, so it doesn't leak into the process list, CLN config, or shell history), with surrounding whitespace trimmed.
  • Tokens shorter than 16 characters (or empty) are rejected at startup to catch weak/placeholder values before the endpoint is ever exposed.
  • /metrics is protected via an axum middleware layer checking Authorization: Bearer <token>, using a constant-time comparison to avoid timing side-channels.
  • Updated the README with the new config options, a --metrics-disable-auth warning, curl/Prometheus scrape examples with the bearer token, and guidance to generate the token with openssl rand -hex 32.
  • Added unit tests covering token file parsing (trimming, empty/short/missing file) and the auth middleware (missing/wrong/correct token, unprotected fallback).

Related issue: #11

Adds authorization layer for /metrics endpoint which is a bearer token.
When a query is performed, under the hood the token gets stripped and
compared with the one that is provided to the plugin.

Adds --metrics-token-file (path to a file holding the bearer token) and
--metrics-disable-auth. The plugin refuses to start unless one of the two
is set, so /metrics can't be exposed unauthenticated by accident; the
disable flag logs a warning. Reading the token from a file keeps it out
of the process list, CLN config, and shell history.
Reject tokens shorter than 16 characters (and empty ones) when reading
--metrics-token-file at startup, to catch weak or placeholder values
before /metrics is exposed. Updates the README example to generate a
random token with openssl instead of a short placeholder.
Switches the token plumbing from Arc<str> to String throughout, and
fixes the auth test helper in metrics.rs.
@Nazarevsky Nazarevsky self-assigned this Sep 17, 2026
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