Repository navigation
feat(server): give each program its own akou key and let an admin log in over the network - #43
Merged
Merged
Conversation
…container's In a container Bun is pid 1 on every start, so a lock left on the volume by an unclean stop named a pid that looked alive, the app refused to start and exited 0, and the restart policy saw a clean exit. The lock now records the holder's pid and an id made once at process start, and the holder touches it every 10 s. - A lock with this process's pid and id is refused (a second acquire). - A live pid that is not this process is refused, as before. - In app mode a dead pid is taken at once, as before. - Otherwise (this pid with another id, or in server mode a pid this namespace cannot see) the lock is taken once its mtime is 30 s old, so a second container on the same volume stays out while the first runs. The call log writer follows the same rule. Refs akou-5an.60 (SI-4).
Server mode (`server.enabled`, or AKOU_SERVER=1) is the same /v1 with a door for programs on the network. This lays the base the job routes build on. - Bind: the app stays on 127.0.0.1. Server mode binds `api.bind`, 0.0.0.0 by default, and refuses to start (exit 78, naming both keys) on an address that is not loopback unless `server.behind_proxy` says a proxy terminates TLS. - Host: `server.public_host` when set, any host behind a proxy, or loopback. Browser headers are allowed there; the web UI's door is the admin login. - Keys: `akou keys create|list|revoke` edit keys.json (0600, the key's SHA-256 and the whsec_ secret) with no app running; the server reads the file again when it changes, so a revoked key gets 401 on its next request. - Scopes: every route declares `open`, `jobs` or `admin`, a route that says nothing is admin, and the guard checks the caller once before any handler. A jobs key gets 403 on PATCH /v1/config; the app token keeps admin. - Callback hosts: `requireCallbackAllowed` answers 422 callback_not_allowed for a host off the key's list; `*` allows any. - Uploads: a route added with `upload: true` takes multipart up to `server.max_upload_mb` (512 MiB); every other route keeps 64 KB of JSON. - `server.trusted_proxies`: only those peers' X-Forwarded-For names the source address; a refused key is logged under that source. - Open routes: GET /healthz (503 while models download), GET /v1/server (mode, presets, engines, capabilities that turn true with their routes), and GET /v1/keys/me for any key. Refs akou-5an.2, akou-5an.3, akou-5an.8, akou-5an.9, akou-5an.15, akou-5an.16, akou-5an.17, akou-5an.18, akou-5an.59.
A page reachable over the network needs a door, and the one-time code that opens it on loopback is minted by a CLI on the same machine. In server mode the API's own listener now serves the page behind the proxy, and the page opens a session with the admin password or an admin key pasted once. - `akou admin set-password` reads the password from stdin (never argv) and stores an argon2id hash as `server.admin_password_hash`; the login reads it from the file, so it works without a restart. - A wrong password or key gets 401 after 2 s; a jobs key cannot log in. - The session lives in the tab's sessionStorage, never a cookie, so it dies with the tab and there is no CSRF; a request from another Origin is refused. - A save over the API keeps the file's own keys as they are on disk, so a PATCH /v1/config no longer drops a hash written since the start. Refs akou-5an.47 (SV-U1).
…ddresses A key holding only '*' could point callbacks at 127.0.0.1, 10/8, link-local and akou's own API. The owner's rule is that '*' matches public hosts only; loopback, RFC 1918, shared, link-local and unique-local literals and localhost must be listed on the key by name.
Mounted on the API listener, the page inherited Bun's upload-sized body limit, so an anonymous POST /session could make akou hold up to 512 MiB. The page now refuses a declared body over 64 KB before reading it, and reads every body through the same capped reader as the API.
…ner comes back After a crash or OOM kill the restarted container is pid 1 again and the lock it left is under 30 s old. The entry point called that 'already running (pid 1)', naming itself, and exited 0, so Docker's on-failure policy left the service down. It now exits 75 (EX_TEMPFAIL) and says when the lock frees.
… models models_ready meant only that the files were on disk, so while the recognizer was still loading them, or after it failed to, /healthz said healthy and Compose's service_healthy released clients before any job could run.
…uessing The delay applied to each request on its own, so parallel guesses were not slowed at all, and each ran an argon2id check with no credentials needed. Logins now queue across the process, and a wrong one holds the queue for its delay: one guess per 2 s, one password check at a time.
nginx sends Host: $proxy_host by default, so akou saw its own loopback address while the browser sent Origin: https://akou.example, and every page POST, the login included, got 403 cross_site. An Origin naming server.public_host is now accepted too, and the SI-6 recipe says the proxy must pass the original Host or set the public host.
Run in a terminal, akou admin set-password waited silently for end of input and echoed the password as it was typed. It now says to pipe the password in from a file, and reads nothing.
…r keyless request key.refused wrote the first 7 characters of any bearer, so a client sending another service's secret left part of it in akou's log, and every request with no key wrote a warn line, so a scanner could grow the log without bound.
…age's dead TLS check The CLI always dials 127.0.0.1, so a server bound to ::1, 127.0.0.2 or one LAN address started fine and then could not be reached from its own box. Server mode now binds 127.0.0.1, 0.0.0.0 or :: and refuses anything else at start. With that rule in apiBind the page's own plain-HTTP refusal could never fire, so it is gone.
An unknown path was checked as an admin route, so a valid jobs key asking for GET /v1/jbos was told the route needs admin. It is now checked as needing any key: no key is still 401 before any 404, and a valid key gets the 404 or 405.
At a tenth of the timings the acceptance's 40 s is 4 s, the threshold plus one heartbeat; the test allowed 5 s.
Rule 2 says every request needs the token, GETs included, but /healthz and GET /v1/server answer with none in app mode too; the server-mode note listed only server-mode changes.
create and revoke each read keys.json, changed it and wrote it back with no lock, so a create running beside a revoke could write the revoked key back. Both now run under keys.json.lock and refuse while another edit holds it. revoke also matched by name, so a key named like another key's id took that key down with it; it matches the id only, as its usage says.
declare wrote 2 MiB of every large body. Past the drain cap the server closed on unread bytes, and past Bun's own limit Bun refused at the headers and closed at once, so the client's write hit EPIPE or ECONNRESET before the 413 arrived: 2 of 6 runs failed on the lane's first head. It now sends one byte past the drain cap, which the server reads whole, and nothing when the length is past Bun's limit. 12 of 12 runs pass.
…word changes A session opened with an admin key stayed valid after the key was revoked, and a new admin password left every session opened with the old one alive until a restart. Each admin session now carries a check of the credential that opened it, run on every use.
|
Warning Review limit reachedNext included review available in 46 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (36)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Sep 25, 2026
Put the keys lane's routes into the OpenAPI route table: GET /v1/server (open) and GET /v1/keys/me (jobs) carry RouteDocs and are in openapi.json; /healthz stays outside /v1 and the file. The guard's upload rule reads the route's multipart body spec instead of a second flag, an unknown path stays UNKNOWN_ROUTE (any key, so 401 before 404), ApiApp.mode is the method the OpenAPI route calls, the keys and admin commands carry the flag descriptions and examples the CLI registry requires, and stdin is read through the one readStdin.
GeiserX
added a commit
that referenced
this pull request
Sep 26, 2026
Brings in the keys (#43) and jobs (#45) lanes this branch's CI needs: /healthz, api.bind and server.behind_proxy. Conflicts: decode.ts takes main's version (#45's superset with maxSamples and too_long); cli.ts keeps both serve and the server commands; args.ts keeps the secret-flag refusal beside main's described COMMON flags; ci.yml keeps the server job beside diarize and executor, all under ci-ok; floors add both sides' skips; the docs keep this branch's SV-P3, SV-T1 and SI-1 rows and main's SV-P4, SV-P5, SV-T2, SV-T3 and SI-2 to SI-4 rows. To pass main's CLI rules: flag descriptions and examples for jobs, serve and models pull, serve listed as local-only, and parity rows for jobs and serve.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In server mode akou has to be reachable from other programs on the network, each with its own credentials, without opening the desktop app's loopback guard to anyone who can reach the port. Before this PR there was one app token, a loopback-only listener, no way to scope or revoke access, no health check a container orchestrator can use, and no way for an admin to open the web UI from another machine. A container restart could also leave a lock behind that the new container never took.
Fix
akou keys create|list|revokeissuesak_keys with ajobsoradminscope and a callback-host allowlist. Only the hash is stored (keys.json, mode 0600). The server re-reads the file when it changes, so a revoked key gets 401 on the next request. Edits run under a lock file, andrevokematches by id only.jobsoradmin. Ajobskey on an admin route gets 403. A keyed typo gets 404 or 405, not "needs admin".callback_not_allowed).*matches public hosts only: loopback, RFC 1918, CGNAT, link-local, unique-local andlocalhostmust be named on the key. SERVER.md SV-K4 now says so.api.binddefaults to127.0.0.1in app mode and0.0.0.0in server mode. A non-loopback bind withoutserver.behind_proxyexits 78 naming both settings. Only127.0.0.1,0.0.0.0or::are accepted in server mode, so the local CLI can always reach it.X-Forwarded-Foris believed only fromserver.trusted_proxies.GET /healthz(ok,version,models_ready,queue_depth) answers 503 while models download or the recognizer loads.GET /v1/serverlists presets, engines and capabilities.GET /v1/keys/menames the caller./healthzand/v1/serverneed no token in either mode; DESIGN 6.3 says so.upload: truetake multipart up toserver.max_upload_mb(default 512). Every other route, and the web UI on the same listener, keeps the 64 KB JSON cap.akou admin set-password(piped in; it refuses a terminal) stores an Argon2 hash, or an admin key can be pasted once. A wrong password costs 2 s, and logins run one at a time, so the delay is a real rate limit. Sessions live in the tab only and end when their key is revoked or the password changes. The cross-origin refusal sits at the login. AnOriginnamingserver.public_hostis accepted for proxies that rewrite Host.config.jsonfrom memory and would have dropped a password set after start.Beads
tests/lock.test.ts(two real processes at 1/10 timings, boundstale + beat); entry-point test for exit 75. Red on today's rule, on dropping the mtime check, on a no-op heartbeattests/server-mode.e2e.test.ts;tests/security.e2e.test.tsunchanged and green/callsgets 415tests/server-mode.e2e.test.tsagainst a stub upload route; 64 KB cap on the web UI bodiestests/server-access.e2e.test.tsserver.routes(); a route with no row fails the test*accepts both*["jobs"]; revoked and no key 401tests/server-login.e2e.test.ts, browser testtests/ui/server-login.test.tsEvery rule above was proven red by a one-line mutation, then restored.
Fully done: akou-5an.2, akou-5an.8, akou-5an.9, akou-5an.15, akou-5an.16, akou-5an.47, akou-5an.59, akou-5an.60.
Partial:
POST /v1/jobsand streaming the body to disk belong to the server-jobs lane, which is stacked on this branch.POST /v1/jobsis the server-jobs lane's. The refusal name is open (below).For the owner to check
callback_not_allowed(SERVER.md, shipped here) orcallback_host_not_allowed(what Telegram-Archive's design expects).docker killon the first (needs the image, SV-P1).127.0.0.1:<port>,localhost:<port>) is accepted in server mode even whenserver.public_hostis set, so the CLI on the same box keeps working. That is looser than SV-D2's wording.api.bind,server.enabled,behind_proxy,public_host,trusted_proxiesandadmin_password_hashare file-only; the API cannot write them.