Skip to content

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: only app/ crates may). The API, however, works with the kernel instance as a whole: preview_reload, reload, dial_table, rules, the connection tracker — this is ours_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 Host trait (app/ui/src/lib.rs): version, modules, explain, events, load, subscriptions, update_subscriptions, clients, prepare_log, reloaded. The implementation is Admin in app/ours/src/main.rs.
  • The admin section and its schema part are still registered the way a module's are: ui::MODULE (Provide::Section, Provide::Schema) is in the binary's LIST, ahead of the modules that describe schema parts, so the part keeps its place in ours 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/urandom in hex; the URL http://<addr>/#token=<token> is printed to stderr. When systemd sends stderr to its journal, the printed URL omits the token. Every /api/* requires Authorization: Bearer <token>.
  • With admin.users (app/ui/src/auth.rs) — HTTP Basic on every path, including static files; 401 carries WWW-Authenticate: Basic realm="ours", the token is not accepted. The password is checked against an argon2id hash in spawn_blocking under 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 (like ours_runtime::listen::refused). The metrics role — only GET /api/v1/metrics, otherwise 403.
  • Requests::configure takes the users of a new configuration and drops what was remembered; the binary calls it after SIGHUP, --watch and an apply from the API (admin_reloaded in main.rs), and when admin.listen changes it opens a new listener — Requests stops its own when dropped.
  • HTTP/1.1 only; Host — the listener's address, localhost or 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 foreign Host — an HTML hint; repeated headers, Transfer-Encoding — refused; head ≤ 16 KiB, body ≤ 2 MiB; methods GET/POST; no more than 32 connections (an extra one gets 503 and is closed), a 15 s timeout.
  • Static files (/, /app.js, /style.css, /favicon.svg) are embedded gzipped by build.rs from app/ui/assets/. They are the build of app/ui/web/ (SolidJS 2, Vite): npm ci && npm run build there rewrites them, and CI checks the committed files match. npm run dev serves the page with /api sent to OURS_ADMIN (by default http://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 statusAPI and build version, revision, modules with an API, can_rollback/can_save/saved
GET configthe text, the decoded configuration (ours_native_config::runtime), objects, the graph
GET connections, groups, eventslive resources the dashboard polls every 2 s; config — only when the revision changes
GET metricsPrometheus text (ours_metrics::render); the only path the metrics role may read
GET subscriptions, POST subscriptions/updatesubscription state, a download in the background
POST previewa full check by the builder without opening listeners or probes: the plan, the effect on connections
POST apply, rollbackreload to a new text / to the previous one
POST savewrite the text to the file, if the configuration came from exactly one regular file
POST routeroute simulation on the active rules (walk_limited), without the network
POST select, probea choice in a selector, a one-off group probe (outside the loop)
POST closeclose a connection by id
POST edit, move, draftin-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.

GPL-3.0-or-later