Archived
fleet: the admin routes read all three legs, as the engine's guards do
The fleet front guarded its admin routes with the loopback socket alone. The socket is the one leg that forges: a DNS-rebinding page is same-origin with its victim's browser and dials through loopback, and a localhost proxy delivers remote clients on loopback sockets carrying the public Host. With CORS open by default, a web page in the operator's browser could unload and park any model, reload the fleet, and read the topology -- disk paths in the body -- from outside the machine. The three-leg rule (loopback socket, no foreign Origin, a Host that names this box) was Server::local_operator's, locked inside Server. Hoist it to server::local_operator(request, bind_host, local_hosts) beside the request whose fields it reads, keep the member as the delegate it now is, and let the fleet's guard call the very same predicate with its own config's host and --allow-host names. One rule, two callers, no forked wording.
This commit is contained in:
1 parent
2a2b756371
commit
41a1aa00fe
6 files changed
+83
-32
No files matched your search
+12
-7
@@ -2581,13 +2581,17 @@ json Fleet::status() {
|
||||
}
|
||||
|
||||
void Fleet::add_routes() {
|
||||
/* The fleet's own routes. Without a bearer key they answer loopback callers only, as the
|
||||
* engine's other admin routes do. */
|
||||
/* The fleet's own routes. Without a bearer key they answer the local operator only, on the
|
||||
* very rule the engine's other admin routes apply: loopback socket, no foreign Origin, and a
|
||||
* Host that names this box. The socket alone forges -- a rebinding page or a localhost proxy
|
||||
* is loopback for any caller -- so all three legs are read here too (docs/GUIDE.md). */
|
||||
auto guard = [this](const server::HttpRequest& q) -> std::optional<server::HttpResponse> {
|
||||
if (!fc_.models.front().cfg.api_key.empty() || q.peer_is_loopback()) return std::nullopt;
|
||||
const Config& c = fc_.models.front().cfg;
|
||||
if (!c.api_key.empty() || server::local_operator(q, c.host, c.allow_hosts))
|
||||
return std::nullopt;
|
||||
return server::HttpResponse::json_body(
|
||||
403, server::error_body(q.path, 403, "permission_error",
|
||||
"the fleet's admin routes answer loopback callers only "
|
||||
"the fleet's admin routes answer the local operator only "
|
||||
"unless an api key is configured"));
|
||||
};
|
||||
auto ok = [](json j) { return server::HttpResponse::json_body(200, j.dump()); };
|
||||
@@ -2602,14 +2606,15 @@ void Fleet::add_routes() {
|
||||
* its finished requests and, as `live`, its latest /stats object; without it the fleet's, with
|
||||
* /admin/fleet's object as `live`. `since` (unix seconds) asks for what came after. Every byte
|
||||
* comes from the sampler's last read, so a page that polls this reads nothing of the engine:
|
||||
* it neither brings a model back nor costs a running one anything. A model's history is as
|
||||
* open as its /stats, the fleet's as /admin/fleet. */
|
||||
* it neither brings a model back nor costs a running one anything. Both shapes are dashboard
|
||||
* telemetry -- per-model figures name their model and its activity -- so the guard runs
|
||||
* before EITHER answer, exactly like the routes below. */
|
||||
front_.route("GET", "/history", [this, guard, ok](const server::HttpRequest& q) {
|
||||
if (auto g = guard(q)) return *g;
|
||||
double since = 0;
|
||||
if (auto it = q.query.find("since"); it != q.query.end()) since = std::strtod(it->second.c_str(), nullptr);
|
||||
if (auto it = q.query.find("model"); it != q.query.end() && !it->second.empty())
|
||||
return server::HttpResponse::json_body(200, history_.model_body(it->second, since));
|
||||
if (auto g = guard(q)) return *g;
|
||||
return server::HttpResponse::json_body(200, history_.fleet_body(since));
|
||||
});
|
||||
/* A command run by the scheduler thread, its answer awaited. */
|
||||
|
||||
Reference in new issue
Block a user