From 0f011f27e11a496c363c3d514ee0c1a1b32afb5a Mon Sep 17 00:00:00 2001 From: fl0l0u Date: Sun, 15 Nov 2026 19:34:05 +0000 Subject: [PATCH] fleet: the local-operator rule is one predicate, read twice add_routes' guard and the front's operator rule computed the same expression byte for byte -- !c.api_key.empty() || server::local_operator( q, c.host, c.allow_hosts) -- once to answer a fleet admin route with a 403 and once to decide whether a guarded route may wake a model. The second-pass audit had to touch both to move them together, which is the telling. Fleet::operator_ok(q) owns it now; both callers call it. The two must agree or the front lets through a request the handler then refuses (or wakes a model the guard would not have admitted), so a single source is the point -- keyed deployments pass, keyless ones answer the three-leg local-operator rule exactly as before. No behaviour change. --- core/fleet/fleet.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/core/fleet/fleet.cpp b/core/fleet/fleet.cpp index e796ecf1..43d54b66 100644 --- a/core/fleet/fleet.cpp +++ b/core/fleet/fleet.cpp @@ -477,6 +477,10 @@ private: std::string reload(); void stop_all(); void add_routes(); + /* Whether `q`'s caller may reach the fleet's admin routes: everyone who pays the api key, or + * -- keyless -- the local operator on the three-leg rule (loopback, no foreign Origin, pinned + * Host). One predicate, read by add_routes' guard and the front's operator rule alike. */ + bool operator_ok(const server::HttpRequest& q) const; json status(); void history_loop(); json placement(const std::string& name); @@ -2580,14 +2584,18 @@ json Fleet::status() { { "cards", cards }, { "groups", groups }, { "host", host }, { "warm_up", warm } }; } +bool Fleet::operator_ok(const server::HttpRequest& q) const { + const Config& c = fc_.models.front().cfg; + return !c.api_key.empty() || server::local_operator(q, c.host, c.allow_hosts); +} + void Fleet::add_routes() { /* 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 { - const Config& c = fc_.models.front().cfg; - if (!c.api_key.empty() || server::local_operator(q, c.host, c.allow_hosts)) + if (operator_ok(q)) return std::nullopt; return server::HttpResponse::json_body( 403, server::error_body(q.path, 403, "permission_error", @@ -2824,12 +2832,9 @@ int Fleet::run() { if (required) preload.push_back(e.name); } front_.set_demand([this](const std::string& n) { demand(n); }); - /* The guarded routes wake models only for callers their own handlers would admit: the - * same three-leg rule add_routes' guard reads (fleet.cpp), keyed deployments always. */ - front_.set_operator_rule([this](const server::HttpRequest& q) { - const Config& c = fc_.models.front().cfg; - return !c.api_key.empty() || server::local_operator(q, c.host, c.allow_hosts); - }); + /* The guarded routes wake models only for callers their own handlers would admit: the same + * operator_ok predicate add_routes' guard reads, keyed deployments always. */ + front_.set_operator_rule([this](const server::HttpRequest& q) { return operator_ok(q); }); front_.set_describe([this](const std::string& n) { return describe(n); }); front_.set_metrics([this] { return metrics(); }); add_routes();