English
ui (app/ui)
app/ui (the ours-ui package) is the Admin API of the running process and the browser dashboard next to it. It is enabled by the --dashboard <loopback IP:port> flag of the run command or by the admin.listen section (the flag takes precedence). The user side is in usage.
Why not a module
- A module may not depend on
ours-kernel(tests/layers.py: onlyapp/crates may). The API, however, works with the kernel instance as a whole:preview_reload,reload,dial_table,rules, the connection tracker — this isours_kernel::Instance, not a contract point. - Modules live inside a configuration and are rebuilt on reload. The API drives reload itself (apply, rollback) and must survive it.
- What depends on the build's composition (protocols, subscriptions, the log) the binary lends the API through the
Hosttrait (app/ui/src/lib.rs):version,modules,explain,events,load,subscriptions,update_subscriptions,clients,prepare_log,reloaded. The implementation isAdmininapp/ours/src/main.rs. - The
adminsection and its schema part are still registered the way a module's are:ui::MODULE(Provide::Section,Provide::Schema) is in the binary'sLIST, ahead of the modules that describe schema parts, so the part keeps its place inours schema.
Features
toml
default = ["api", "dashboard"]
api = ["dep:ours-native-config", "dep:subtle", "dep:ours-route-api", "dep:ours-tracker", "dep:argon2", "dep:base64", "dep:hmac", "dep:sha2"]
dashboard = ["api", "dep:flate2"]api is the loopback HTTP Admin API, dashboard adds the dashboard static files next to it. In the binary: api = ["ui/api"], dashboard = ["api", "ui/dashboard"] (in default). Without api, app/ui/src/disabled.rs is compiled — uninhabited stubs with the same names (Request, Requests, State, listen): the binary builds the same way, and --dashboard reports that there is no API in the build. With api but without dashboard, the API works, but static files are not served.
Transport (app/ui/src/http.rs)
- Listens only on loopback; otherwise an error with advice about an SSH tunnel.
- Without
admin.users— a token: 32 bytes from/dev/urandomin hex; the URLhttp://<addr>/#token=<token>is printed to stderr. When systemd sends stderr to its journal, the printed URL omits the token. Every/api/*requiresAuthorization: Bearer <token>. - With
admin.users(app/ui/src/auth.rs) — HTTP Basic on every path, including static files;401carriesWWW-Authenticate: Basic realm="ours", the token is not accepted. The password is checked against an argon2id hash inspawn_blockingunder a semaphore allowing one check at a time; an unknown name is checked against a decoy hash of the same cost. A success is remembered as an HMAC-SHA256 of the header (a per-process key) → role, for 10 minutes, up to 64 entries; a refusal answers after a second and is logged once a minute (likeours_runtime::listen::refused). Themetricsrole — onlyGET /api/v1/metrics, otherwise403. Requests::configuretakes the users of a new configuration and drops what was remembered; the binary calls it afterSIGHUP,--watchand an apply from the API (admin_reloadedinmain.rs), and whenadmin.listenchanges it opens a new listener —Requestsstops its own when dropped.- HTTP/1.1 only;
Host— the listener's address,localhostor a loopback address with any port (an SSH tunnel), a name pointing to loopback is not accepted (DNS rebinding);Origin(if present) —http://<Host>;GET /with a foreignHost— an HTML hint; repeated headers,Transfer-Encoding— refused; head ≤ 16 KiB, body ≤ 2 MiB; methodsGET/POST; no more than 32 connections (an extra one gets503and is closed), a 15 s timeout. - Static files (
/,/app.js,/style.css,/favicon.svg) are embedded gzipped bybuild.rsfromapp/ui/assets/. They are the build ofapp/ui/web/(SolidJS 2, Vite):npm ci && npm run buildthere rewrites them, and CI checks the committed files match.npm run devserves the page with/apisent toOURS_ADMIN(by defaulthttp://127.0.0.1:9090). - Accepted requests go to a queue of 16 (
Requests); overflow —503.
API (app/ui/src/api.rs)
Version 1 under PREFIX = "/api/v1/"; status returns api: 1 and the build (Host::version). A path outside the prefix — 404 with a hint. The response schema is OpenAPI docs/usage/admin-api.json; test_admin.py checks live responses against it, so a field removed from a response but left in the schema breaks the test.
Requests are executed in the binary's signal loop (next_admin in main.rs), so an apply from the API, SIGHUP, --watch and subscription updates never interleave. What waits for the network is taken out of the loop: probe takes the group's Arc from dial_table and waits for the probe in its own task (tokio::spawn), replying through the same oneshot. Every POST, except subscriptions/update, clients/* and module requests, carries a revision; a wrong one — 409 conflict, an unknown path — 404, other errors — 400 (the status function).
Path (after /api/v1/) | What it does |
|---|---|
GET status | API and build version, revision, modules with an API, can_rollback/can_save/saved |
GET config | the text, the decoded configuration (ours_native_config::runtime), objects, the graph |
GET connections, groups, events | live resources the dashboard polls every 2 s; config — only when the revision changes |
GET metrics | Prometheus text (ours_metrics::render); the only path the metrics role may read |
GET subscriptions, POST subscriptions/update | subscription state, a download in the background |
POST preview | a full check by the builder without opening listeners or probes: the plan, the effect on connections |
POST apply, rollback | reload to a new text / to the previous one |
POST save | write the text to the file, if the configuration came from exactly one regular file |
POST route | route simulation on the active rules (walk_limited), without the network |
POST select, probe | a choice in a selector, a one-off group probe (outside the loop) |
POST close | close a connection by id |
POST edit, move, draft | in-place editing of the YAML text (ours_native_config::replace_object and others), without applying |
GET clients, POST clients/{add,remove,export} | the clients module through Host::clients: a changed config_file the binary writes itself, and the API applies the same YAML again; a changed YAML the API applies and saves (save) if the active configuration was saved, otherwise — a warning. Responses with a private key — only behind the token, like all of /api/* |
<module>/<path> | ours_api::admin::Admin: module requests (currently adblock) |
Resources are polled, not streamed; connections is not paginated; an error is text plus the HTTP status.
Who uses it
Only the app/ours binary. Dependencies: ours-api, ours-kernel, ours-config, ours-codec, ours-clock, ours-runtime, ours-metrics, ours-json, tokio, tracing; under api also ours-native-config, ours-route-api, ours-tracker, subtle and argon2, hmac, sha2, base64 (RustCrypto, MIT OR Apache-2.0); under dashboard, flate2.
Tests
Unit tests in src/; integration tests in app/ui/tests/; fuzz targets in app/ui/fuzz/ (request, credentials, accept_encoding). The black-box and browser tests are in tests/dashboard/, see Dashboard.