Archived
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.
This commit is contained in:
1 parent
c3a4775f54
commit
0f011f27e1
1 file changed
+13
-8
+13
-8
@@ -477,6 +477,10 @@ private:
|
|||||||
std::string reload();
|
std::string reload();
|
||||||
void stop_all();
|
void stop_all();
|
||||||
void add_routes();
|
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();
|
json status();
|
||||||
void history_loop();
|
void history_loop();
|
||||||
json placement(const std::string& name);
|
json placement(const std::string& name);
|
||||||
@@ -2580,14 +2584,18 @@ json Fleet::status() {
|
|||||||
{ "cards", cards }, { "groups", groups }, { "host", host }, { "warm_up", warm } };
|
{ "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() {
|
void Fleet::add_routes() {
|
||||||
/* The fleet's own routes. Without a bearer key they answer the local operator only, on the
|
/* 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
|
* 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
|
* 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). */
|
* 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> {
|
auto guard = [this](const server::HttpRequest& q) -> std::optional<server::HttpResponse> {
|
||||||
const Config& c = fc_.models.front().cfg;
|
if (operator_ok(q))
|
||||||
if (!c.api_key.empty() || server::local_operator(q, c.host, c.allow_hosts))
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
return server::HttpResponse::json_body(
|
return server::HttpResponse::json_body(
|
||||||
403, server::error_body(q.path, 403, "permission_error",
|
403, server::error_body(q.path, 403, "permission_error",
|
||||||
@@ -2824,12 +2832,9 @@ int Fleet::run() {
|
|||||||
if (required) preload.push_back(e.name);
|
if (required) preload.push_back(e.name);
|
||||||
}
|
}
|
||||||
front_.set_demand([this](const std::string& n) { demand(n); });
|
front_.set_demand([this](const std::string& n) { demand(n); });
|
||||||
/* The guarded routes wake models only for callers their own handlers would admit: the
|
/* The guarded routes wake models only for callers their own handlers would admit: the same
|
||||||
* same three-leg rule add_routes' guard reads (fleet.cpp), keyed deployments always. */
|
* operator_ok predicate add_routes' guard reads, keyed deployments always. */
|
||||||
front_.set_operator_rule([this](const server::HttpRequest& q) {
|
front_.set_operator_rule([this](const server::HttpRequest& q) { return operator_ok(q); });
|
||||||
const Config& c = fc_.models.front().cfg;
|
|
||||||
return !c.api_key.empty() || server::local_operator(q, c.host, c.allow_hosts);
|
|
||||||
});
|
|
||||||
front_.set_describe([this](const std::string& n) { return describe(n); });
|
front_.set_describe([this](const std::string& n) { return describe(n); });
|
||||||
front_.set_metrics([this] { return metrics(); });
|
front_.set_metrics([this] { return metrics(); });
|
||||||
add_routes();
|
add_routes();
|
||||||
|
|||||||
Reference in new issue
Block a user