Repository navigation
Description
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 andmake test-suitepasses; no file undertests/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.jsonandfeed-authed.jsonbyte-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 denypins 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
runpyassertions on the Python source intests/run.share left unedited and run only in Python mode;PARITY.mdpairs 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.templatekeepsDynamicUser,ProtectSystem=strictand credential loading, and the DynamicUser can read the binary.tests/test-api-allowlist-linux.shpasses. The Python server is not deleted.make checkpasses.
Possible solutions
- Hand-rolled HTTP/1.1 on
std::netversustiny_httpversushyper; pick by binary size,cargo denyaudit and the benchmark. - JSON:
serde_jsonversus a smaller parser; the server only needs token lists from config and static file bodies. - HMAC and compare:
hmac+sha2+subtle, orring. - Unknown: whether wire bytes differ for malformed requests the tests do not cover; add cases found.
Activity
pithead-architect commentedon Nov 27, 2026
Blocked by #692 and #701 (native links added).