Archived
server: name the caller a vouched proxy carried, without arming the guard
An operator running radiance behind a reverse proxy sees one address in every log line: the proxy's. --trusted-proxy CIDR (repeatable) vouches for the networks whose sockets may say who they carried. An X-Forwarded-For from inside a vouched network is walked from the right: vouched hops are skipped, the first address no vouched CIDR covers is the caller, a chain of only vouched hops ends at its leftmost, and anything else falls back to the socket. From an unvouched socket the header names no one, because it has not been vouched for. Attribution is not authority, and the split that keeps them apart is mechanical. HttpRequest carries `peer`, the attributed caller, sanitized where it is built because a named address arrives in a header and the log keeps no client text otherwise -- and `raw_peer`, the socket as the kernel saw it, which is now the only address peer_is_loopback() reads. A proxy on loopback therefore hands the keyless loopback-only routes to none of its clients; it only names them where the proxy used to stand. transport_test pins both halves: the walk at the unit level, and over a real socket that a vouched proxy plus X-Forwarded-For leaves the loopback guard answering 200 and the cross-origin 403 untouched. httplib's own set_trusted_proxies -- new this side of the vendor bump -- is deliberately unarmed. It rewrites req.remote_addr, the very field the guards would read as the socket peer, so one over-broad vouched network would move the guard rather than the log line. Radiance reads the header itself, and ip_in_cidr refuses across families: a vouched ::ffff:0:0/96 vouches for no IPv4 socket. Config rejects anything but a numeric network with a prefix at startup, because a typo there would silently unvouch a proxy; the refusals the transport answers before the router log the attributed caller too, so the audit trail stays one line per request whoever the socket belongs to.
This commit is contained in:
1 parent
40e1b3073b
commit
b6acbd69e4
11 files changed
+352
-22
No files matched your search
@@ -8,6 +8,7 @@
|
||||
#include "format/rope_override.h"
|
||||
#include "sample/host_ref.h"
|
||||
#include "server/oai.h"
|
||||
#include "server/http.h"
|
||||
#include "diag/diag.h"
|
||||
#include "util/kernel_list.h"
|
||||
#include "place/planner.h"
|
||||
@@ -220,6 +221,9 @@ static const Flag g_flags[] = {
|
||||
{ "--allow-host", "NAME", "a Host name the keyless loopback-only routes (/diagnostics,\n"
|
||||
" /admin/control-vector, the LoRA and session admin) accept besides\n"
|
||||
" localhost; repeatable" },
|
||||
{ "--trusted-proxy", "CIDR", "a network whose sockets may name the client behind them via\n"
|
||||
" X-Forwarded-For, for the log; vouching changes attribution,\n"
|
||||
" never access; repeatable" },
|
||||
{ "--served-model-name", "NAME", "the model id /v1/models lists and responses carry; default the container's name" },
|
||||
{ "--mm-max-patches", "N", "patches one encoder pass carries, and so the largest image (a patch is 16x16\n"
|
||||
"pixels). Default `auto`: 16384 when the container carries a vision tower. 0\n"
|
||||
@@ -850,6 +854,15 @@ int config_parse(int argc, char** argv, Config* c) {
|
||||
if (!*v) { RAD_ERR("--allow-host takes a non-empty name"); return RAD_E_INVAL; }
|
||||
c->allow_hosts.emplace_back(v);
|
||||
}
|
||||
else if (S("--trusted-proxy")) {
|
||||
if (!(v = need(i))) return RAD_E_INVAL;
|
||||
if (!server::cidr_valid(v)) {
|
||||
RAD_ERR("--trusted-proxy takes a numeric network with a prefix length, like "
|
||||
"127.0.0.0/8 or ::1/128 (no brackets, no bare address), got '%s'", v);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
c->trusted_proxies.emplace_back(v);
|
||||
}
|
||||
else if (S("--served-model-name")) {
|
||||
if (!(v = need(i))) return RAD_E_INVAL;
|
||||
if (!*v) { RAD_ERR("--served-model-name takes a non-empty name"); return RAD_E_INVAL; }
|
||||
@@ -1380,6 +1393,10 @@ const ShowRow kShow[] = {
|
||||
std::string o;
|
||||
for (const std::string& h : c.allow_hosts) o += (o.empty() ? "" : ",") + h;
|
||||
return o.empty() ? std::string("the loopback names only") : o; } },
|
||||
{ "--trusted-proxy", [](const Config& c) {
|
||||
std::string o;
|
||||
for (const std::string& p : c.trusted_proxies) o += (o.empty() ? "" : ",") + p;
|
||||
return o.empty() ? std::string("no socket vouches for a caller") : o; } },
|
||||
{ "--served-model-name", [](const Config& c) { return or_none(c.served_model_name, "the container's name"); } },
|
||||
{ "--mm-max-patches", [](const Config& c) { return c.mm_max_patches < 0 ? std::string("auto") : num(c.mm_max_patches); } },
|
||||
{ "--image-gen-max-pixels", [](const Config& c) { return c.image_gen_max_pixels > 0 ? num(c.image_gen_max_pixels) : std::string("the model's"); } },
|
||||
|
||||
Reference in new issue
Block a user