metrics-plugin: add authorization for `/metrics` endpoint

Ouverte
#11 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
45/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
grafana, prometheus, rust

Piste de recherche

Commencez par le handler /metrics de metrics-plugin et par le mécanisme normal d’options des plugins CLN. Suivez la manière dont les réponses de métriques sont actuellement servies, puis déterminez et documentez le comportement sans identifiants avant de couvrir les identifiants valides, absents et invalides dans des tests automatisés. La tâche est terminée lorsque les scrapes authentifiés conservent le format de métriques existant et que les requêtes échouées ne renvoient aucune donnée de métriques.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Problem

metrics-plugin exposes /metrics endpoint in order for scraping services (e.g. Prometheus or Grafana Alloy) to collect CLN metrics. Currently, /metrics is open - if the port is configured to be open for the whole world, potentially everyone could access it and observe inner channel data that affects the privacy.

Solution

Add an optional authentication layer in front of the /metrics endpoint so a scraper must present a valid credential before any metrics are returned. When no credential is configured, the plugin should either keep current behavior for backwards compatibility or fail closed — that decision is worth calling out explicitly below.

  • HTTP authentication on /metrics. Support at least one of the standard schemes that both Prometheus and Grafana Alloy natively understand on the scrape side:
    • Bearer token - plugin is configured with a token; requests must send Authorization: Bearer <token>. Matches Prometheus/Alloy authorization scrape config.
    • HTTP Basic auth - plugin is configured with a username/password; matches Prometheus/Alloy basic_auth.
  • Configuration via plugin options. Expose the credential through the normal CLN plugin option mechanism (e.g. metrics-auth-token / metrics-basic-user + metrics-basic-pass), and support reading the secret from a file or environment variable rather than a plaintext CLI arg, so it doesn't leak into ps/logs.
  • Constant-time comparison of the presented credential against the configured one to avoid timing side-channels.
  • Correct HTTP semantics. Return 401 Unauthorized (with WWW-Authenticate for Basic) on missing/invalid credentials; 200 only on success. Never leak metric data in the body of a failed request.

Open decision to resolve in the issue: should an unconfigured endpoint stay open (backwards compatible, log a warning) or fail closed (secure by default, but breaks existing setups on upgrade)? Recommend fail-closed with a clear migration note, or an explicit metrics-auth-disabled=true opt-out.

Acceptance criteria

[] A request to /metrics without valid credentials returns 401 and no metric data in the body.
[] A request to /metrics with valid credentials returns 200 and the expected metrics.
[] The credential (token or basic user/pass) is configurable through plugin options, and can be supplied via file/env var rather than only a plaintext CLI argument.
[] 401 responses include a WWW-Authenticate header when Basic auth is in use.
[] The behavior when no credential is configured is explicitly defined and documented (fail-closed with opt-out, per decision above), and that path is covered by a test.
[] The secret does not appear in process listings (ps) or plugin logs.
[] Automated tests cover: valid credential -> 200, missing credential -> 401, wrong credential -> 401.
[] Existing metric collection/format is unchanged for authenticated scrapes (no regression).

Langage dominant
Rust
Étoiles
3
Forks
1
Merge moyen
3 j 14 h
PR mergées (30 j)
2

Préparer son environnement

  • Fournit un Dockerfile ou un fichier Docker Compose
  • Aucun modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Blockstream/cln-plugins

Toutes les issues de Blockstream/cln-plugins

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.