Skip to content

Token-authenticated API to check for and perform an update, with scope, rate limit and single flight #684

Open

Description

@pithead-developer

What's the problem

RigForge's only remote update is POST /upgrade, which needs a git checkout and a tag from the coordinator (rigforge.sh:4643-4760, ADR 0002) and cannot apply to an appliance rig (baked non-git tree). There is no check call and no way to update an appliance rig. RigForge has no request rate limiter (util/control-server.py has MAX_BODY and MAX_PENDING only).

What it impacts

Appliance rigs, paired or standalone, and the coordinator's Upgrade rig and Update all.

How I found it

Owner decisions of 2026-11-10 (items 5 to 7). Reading control-server.py and rigforge.sh control_upgrade; ACCESS_TOKENS and derive_read_token in the servers for the scope rule.

How important is it

High for the next feature release.

It is blocked by p2pool-starter-stack/pithead#4013.

Acceptance criteria

  • POST /update-check starts the image's Tor helper, reads the release channel, returns available OS and RigForge versions with the last-seen listing time, and stops Tor.
  • POST /update {tag?, coordinator_version?}: tag defaults to latest; with coordinator_version any target above it is refused (semantic comparison); equal or unsupported targets are refused with a reason. The tag must match a strict release-tag regex and resolve to the release host.
  • Token scope: only the control token may call these routes. A derived read token is always refused, and a named consumer token is refused unless explicitly granted an update scope.
  • Missing or wrong token gets 401. Failed-auth attempts are rate limited and logged; the rate limit is stated (global or per source). One request in flight (409), rate limit (429), /update returns 202 and a status route reports progress and verdict without leaking tokens or paths. Behaviour across reboot is defined: 202, then the connection drops, and status after boot.
  • On an appliance rig the call hands off to the image updater (pithead rig-update); on a standalone DIY install it keeps the git upgrade (with tor_socks5 if set).
  • With no call, the rig makes no update-related request and runs no timer.
  • Tests cover auth, scope, refusal, limits, handoff and the standalone path.

Possible solutions

New spool actions beside apply in the control server, consumed by the root oneshot that already does upgrades.

Activity

  1. added
    enhancement
    on Nov 10, 2026
  2. pithead-developer commented on Nov 16, 2026

    @pithead-developer
    ContributorAuthor

    Rulings of 2026-11-15/16 and the 2.0.5 scope. Request to the operator: move this to v1.19.0.

    Rulings that bind this issue

    1. Remote OS update for RigForge-only appliances moves to Pithead v2.0.5, scoped to per-rig update only. Rig identity, replace-stick, Update all, Remove rig, /release (Add a release (revoke) call so a removed rig can no longer be controlled or read through its old token #681), rig logs and install-to-disk removal stay in v2.1.0.
    2. The endpoint lives on the rig. The rig downloads its own signed bundle over its own on-demand Tor client. The coordinator never serves bundle files.
    3. A rig must work without Pithead. The Pithead dashboard's per-rig "Update OS" button is one client. With no Pithead, an owner updates a rig by a documented API call from any LAN computer, using the rig's token. No new UI on the rig, no timers, no automatic checks.
    4. Called by a Pithead, the coordinator's version is the ceiling. Called directly, the default is latest. Equal versions and downgrades are refused.
    5. Rig egress is Tor only. The one exception is stratum to an external pool the owner configured, which may be clearnet. Updates, time sync and everything else go over Tor. A separate egress audit will add the time and DNS items; it is a pending sibling and not designed here.
    6. If the RigForge release carrying this API is not ready when the rest of 2.0.5 is, 2.0.5 ships for Pithead boxes only and rig owners stay on 2.0.3.

    2.0.5 scope (control server)

    • POST /update-check, POST /update {tag?, coordinator_version?}, GET /update/status.
    • Appliance rigs only stage an intent for the root handoff into pithead rig-update. The control server does not download or verify anything itself.
    • Body is strict JSON with only those two optional fields. No URL, host or path is accepted; unknown fields are 400. tag must match the strict release-tag regex.
    • Token scoping is new work. Today _authed accepts the master token and any named ACCESS_TOKENS entry with no scope. Define it: the control (master) token may call update routes; a named consumer token may only if explicitly granted an update scope; the derived read token is always refused. Status codes: missing, wrong or read token gets 401; a named token without the scope gets 403.
    • Failed-auth and request rate limits are per source address, with a small global cap on top so a spread of sources cannot bypass it. Over the limit gets 429. The state and limits are documented.
    • Single flight: a second /update while one runs gets 409.
    • Equal or lower target than the running version gets a refusal with a reason; coordinator_version caps the target.
    • DIY rigs: /update is refused unless tor_socks5 is set. DIY keeps the git /upgrade path, which is out of scope here.
    • GET /update/status survives the reboot and returns progress and verdict with no tokens or paths.

    Done when

    • Docs describe the direct-call procedure for a rig with no Pithead (token, example call, status poll), and docs/pithead-integration.md, README and AGENTS reflect the new routes where they list the API.
    • tests/test-control-firewall.sh covers the new routes, the scope matrix, 401/403/409/429 and the strict body.
    • An ADR or API contract entry records the scope rule and limits.
    • Tests cover auth, scope, refusal, limits, handoff and the DIY refusal.

    Release order. Cut RigForge v1.19.0 containing this and #680 first. Only then does Pithead bump RIGFORGE_REF in its rig image Dockerfile and rebuild.

    Rig owners stay on 2.0.3 and skip 2.0.4 (p2pool-starter-stack/pithead#4136). One manual USB hop to 2.0.5 gives a rig this endpoint; after that updates are remote. A disk-installed rig uses Keep everything and stays adopted; a stick rig re-flashes, which means a new token and re-adopt. Blocked by p2pool-starter-stack/pithead#4013 (PR p2pool-starter-stack/pithead#4103, to be retargeted onto develop along with #4040 and #4056 by cherry-pick).

  3. added this to the v1.19.0 milestone on Nov 16, 2026
  4. pithead-developer commented on Nov 16, 2026

    @pithead-developer
    ContributorAuthor

    Blocked on p2pool-starter-stack/pithead#4013. Blocked by p2pool-starter-stack/pithead#4013 (rig-side updater), as both this issue's body and the binding 2026-11-15/16 rulings comment state. The three routes in scope cannot be finished before it lands on pithead develop: GET /update/status must return progress and a verdict sourced from the rig-update.json verdict file, and the appliance handoff calls the image updater pithead rig-update — both exist only in pithead PR p2pool-starter-stack/pithead#4103, still an open draft on develop-v2.1.0 that the same ruling says must be retargeted onto develop (cherry-pick, with #4040 and #4056) before v2.0.5; a code search of pithead develop finds no rig-update updater or verdict file. Writing the API now would define that handoff/verdict contract twice and guarantee rework. Finished so far: full reconnaissance — confirmed util/control-server.py today has no token scopes (_authed accepts master and every named ACCESS_TOKENS entry), no rate limit, no update routes, and reviewed the control_upgrade spool path in rigforge.sh and tests/test-control-firewall.sh, so auth scope, 401/403/409/429, strict body, single flight and status persistence can all be built on the existing spool/pending pattern once the contract is fixed. No code written; branch untouched, no PR. Unblocks when pithead#4103 is retargeted and merged so pithead#4013 closes (the pithead rig-update interface and rig-update.json verdict format on develop); the runner resumes this session then. For the next session: the work is also more than one local-session objective (scope+auth matrix, rate limiter, three routes, spool+handoff, systemd units, ADR and docs, firewall tests across control-server.py, rigforge.sh and templates) — hand it to a full-budget session or split it then; splitting now would create children blocked on the same #4013, which is why no split is filed here.

    The runner resumes this issue when that one closes.

  5. added
    blocked
    on Nov 16, 2026
  6. pithead-developer commented on Nov 17, 2026

    @pithead-developer
    ContributorAuthor

    Moved to v1.20.0 on 2026-11-17. The owner wants 1.19.0 released now, and this issue cannot finish before pithead#4013 lands. Split into stories: #699 (scope, rate limit and single flight; can start now), #700 (update-check) and #701 (update and status; blocked on pithead#4013), plus #702 (docs). Pithead v2.0.5's per-rig update needs the first RigForge tag that contains this issue, now planned as v1.20.0.

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

    blockedenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions