One API key per feeder + feeder-scoped ingest URLs (migrate off shared keys)

Abierto
#438 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
12/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
django, prometheus, python

Línea de trabajo

Start with the auth path: NodeAuthorizationPermission and the NodeAuth link between NodeAPIKey and ManagedNode, then common/meshcore_feeder_auth.py for the MeshCore equivalent. The issue's open points need a maintainer decision first, including the per-protocol key rule and the prod query for keys linked to several feeders. Done means the acceptance criteria are met: feeder-scoped endpoints reject shared keys, old v1/v3 URLs are unchanged, and Prometheus shows usage of old and new URLs.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement meshtastic-2.8 permissions

Part of #437. This ticket should land before the feeder re-key work (ID-4) and makes that work much smaller.

Problem

Today an API key can be shared between several feeders owned by the same person (NodeAuth is many-to-many between NodeAPIKey and ManagedNode). Because of that, the feeder's node number in the URL (/api/packets/{node_id}/...) is what chooses which feeder is posting, and NodeAuthorizationPermission authorises on the pair (key, node number).

From 2.8, a node's number is crc32(public_key), so it changes on upgrade. An upgraded feeder then posts under a number its key isn't linked to, gets a 403, and ingest stops silently.

MeshCore has the same sharing built in: common/meshcore_feeder_auth.py uses the X-MeshCore-Feeder-Pubkey header to tell a user's feeders apart.

Proposal: one feeder, one API key

When a key belongs to exactly one feeder, the key on its own identifies the ManagedNode. The node number the bot reports is then just information we record, not something we authorise on. If the number changes, the feeder simply reports a new one:

  • if crc32(public_key) equals the new number, update meshtastic_node_id automatically, keep the old number as an alias and notify the owner;
  • if it doesn't match, flag it for review rather than reject it. The likely cause is a bot config copied onto another radio.

Keys can still be rotated.

Migration

  1. API: add feeder-scoped endpoints with no node number in the path, for example /api/v4/feeder/ingest/, /api/v4/feeder/nodes/ and /api/v4/feeder/bot-version/. Exact paths to be decided; MeshCore gets the equivalent. These endpoints require a key linked to exactly one feeder. A shared key gets a clear 4xx telling the owner to mint a per-feeder key.
  2. Bot: post to the new URLs. Ship this in the same bot release as feeder identity reporting (ID-5).
  3. Owners upgrade their bot over time. The old v1/v3 URLs keep working unchanged, shared keys included. No new shared links can be created (UI/admin), though existing ones keep working on the old URLs.
  4. Track usage of the old and new URLs in Prometheus:
    • Request counts per URL version. django-prometheus per-view metrics may already cover this; check the views have distinct names.
    • Which feeders are still on the old URLs, so we can chase their owners. Use either a low-cardinality counter labelled by feeder (the fleet is small) or a last_used_legacy_url_at field on ManagedNode. Pick one.
  5. Retire the old URLs once legacy usage reaches zero, or stays at a known handful we've contacted. This joins up with #319 (retire v1 ingest URLs).
  6. Once the old URLs are gone, enforce one key per feeder in the schema: a unique constraint on NodeAuth.api_key, or move the key onto ManagedNode.

Open points

  • A bot running both a Meshtastic and a MeshCore radio on one key: should the rule be one key per feeder per protocol, or one bot record owning both radios? Check prod for keys linked across protocols.
  • Before step 6, find out how many prod keys are linked to more than one feeder:
    NodeAuth.objects.values("api_key").annotate(n=Count("node")).filter(n__gt=1)
  • Dual-API (prod plus pre-prod) is unaffected, because each environment has its own key.

Acceptance criteria

  • New feeder-scoped endpoints authenticate by key alone and reject shared keys with an actionable error.
  • A feeder whose node number changes keeps ingesting on the new endpoints. Its number is updated, with the CRC check, an alias for the old number, and an owner notification. If ID-4 lands separately, at minimum there is no 403.
  • Old v1/v3 endpoints behave exactly as they do today.
  • New shared key links can no longer be created.
  • Prometheus shows request volume for the old and new URLs, plus a way to list the feeders still on the old URLs.
  • Bot change tracked in a linked meshflow-bot issue.
  • Docs updated: API.md, API_KEYS.md and the ingestion docs.
Lenguaje dominante
Python
Estrellas
1
Forks
0
Merge medio
1 d 20 h
PR fusionados (30 d)
5

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pskillen/meshflow-api

Todos los issues de pskillen/meshflow-api

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.