Skip to content

Port the sister API server (util/api-server.py) to Rust #711

Open

Description

@pithead-developer

What's the problem

util/api-server.py (132 lines, Python stdlib) serves the sister feed and is a runtime dependency on python3 for every rig (ExecStart in systemd/rigforge-api.service.template). It is the smallest slice and is testable over HTTP.

What it impacts

Every Pithead and LAN client reading /1/summary, /2/summary, /health, /tune; the unit template; the python3 runtime dependency. Blocked by #681 (revoke), #692 (with #690 and #691, the log route) and #699-#701, which change this server and land in Python first; the Python behavior at that point is the reference, so it is ported once.

How I found it

Reading util/api-server.py and the tests that drive it (the api-server sections of tests/run.sh, tests/contract/v1/) at ea41133. Behavior to preserve: GET only; fixed routes with summary-authed.json preferred when a token is set; headers exactly Content-Type, Content-Length, Connection: close; bodies {"error":"unauthorized"} 401, {"error":"not found"} 404, {"error":"read-only API"} 405 for POST/PUT/DELETE/PATCH/HEAD/OPTIONS, {"error":"warming up - first refresh pending"} 503; tokens are ACCESS_TOKEN plus every ACCESS_TOKENS value; accepted bearers are the raw token or HMAC-SHA256(token, rigforge:api-read:v1) hex for ASCII tokens of at least 32 chars, compared in constant time over all candidates; unparseable config is fatal at start; 10 s request timeout; dual-stack IPv6 bind; query string ignored; no request logging.

How important is it

Medium; first slice of the port and removes python3 for this unit. No user-visible change allowed.

Acceptance criteria

  • With RIGFORGE_IMPL=rust, the unit starts the Rust server and make test-suite passes; no file under tests/ is modified. A documented make target builds or locates the binary and fails loudly if it is missing.
  • Responses match Python byte for byte for each route and status above, including the exact header set; tests/contract/v1/feed.json and feed-authed.json byte-match as served.
  • One verify function takes the candidate set; a native unit test with a counting comparator shows every candidate is evaluated for matching and non-matching input, and cargo deny pins the allowed crypto crate. Derived-bearer for a fixed token and the short or non-ASCII refusal are asserted natively, mirroring the existing assertions.
  • Startup refuses an unparseable config; IPv6 dual-stack bind and the 10 s slow-client cap are exercised by a test.
  • The grep and runpy assertions on the Python source in tests/run.sh are left unedited and run only in Python mode; PARITY.md pairs each with its native Rust test.
  • The token, derived-bearer and compare module lives in the library crate for reuse by the control receiver.
  • rigforge-api.service.template keeps DynamicUser, ProtectSystem=strict and credential loading, and the DynamicUser can read the binary. tests/test-api-allowlist-linux.sh passes. The Python server is not deleted. make check passes.

Possible solutions

  • Hand-rolled HTTP/1.1 on std::net versus tiny_http versus hyper; pick by binary size, cargo deny audit and the benchmark.
  • JSON: serde_json versus a smaller parser; the server only needs token lists from config and static file bodies.
  • HMAC and compare: hmac+sha2+subtle, or ring.
  • Unknown: whether wire bytes differ for malformed requests the tests do not cover; add cases found.

Activity

  1. added this to the v1.20.0 milestone on Nov 17, 2026
  2. added
    enhancement
    refactor
    blocked
    P4-code-health
    size:M
    on Nov 17, 2026
  3. pithead-architect commented on Nov 27, 2026

    @pithead-architect

    Blocked by #692 and #701 (native links added).

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

    P4-code-healthblockedenhancementrefactorsize:M

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions