Archived
hfget+deploy: fetch a repo on verified claims, and run with a key argv cannot show
The --model repo-id path trusts the hub with the machine's filesystem and the container runs with the kernel's door off. Both stop here. hfget.sh trusted a listing's file names to be names: an absolute path or a .. segment wrote wherever the destination's owner could write, and a name shadowing .hfget-manifest taught the next run whatever it liked. A listing is now vetted whole before anything is fetched -- absolute paths, .. segments, control characters (a tab splices one entry into two fields), names of hfget's own manifest -- and a child refuses a path that would escape anyway. Silent skipping was the alternative, and it leaves a directory that reads as complete and is not. And the content key was the hub's claim, never checked: an LFS file was kept for its size and its claimed oid recorded without ever hashing the download, so a swapped file of equal length -- or a spliced resume at any length -- passed forever after. The download is hashed on arrival and kept only when it matches the claimed sha256; a mismatch deletes the file, and the manifest now certifies verified content. --model-revision REV fetches at a branch, tag, sha or refs/pr/N instead of the moving main: without it a restart can serve weights nobody reviewed, and the guide now says to name one. --api-key-env NAME reads the key from the environment, where only the process and root can reach it, not the command line where every process on the host reads it in ps; an unset or empty variable refuses startup exactly like an empty --api-key. The compose files carry the key through environment: now -- the fail-closed :? guard moves with it -- across all 52 model files. And the containers' seccomp=unconfined has a way out: Docker's default profile, plus exactly the calls that forced the escape -- io_uring for the n-gram table, mbind/set_mempolicy/get_mempolicy for ROCm's NUMA binding -- is shipped as seccomp-radiance.json and selected through RADIANCE_SECCOMP; the default stays unconfined until each operator audits their own card stack. Verified: under the profile io_uring_setup and set_mempolicy behave as under unconfined and a non-listed syscall earns EPERM. hf_model_test: the escape-listing refusal, the oid verify (bad rejected and deleted, good certified), the pinned revision fetched -- against a fake curl for a hub. config_test: --api-key-env fails closed unset, reads the key set. ASan+UBSan: config/diag/hf_model/server/transport/ wire/lifecycle, 8/8.
This commit is contained in:
1 parent
ad3f03dbc6
commit
1577854d00
62 files changed
+1551
-61
No files matched your search
@@ -49,6 +49,8 @@ static const Flag g_flags[] = {
|
||||
"Hugging Face repo id (owner/name), fetched before startup" },
|
||||
{ "--download-dir", "DIR", "where a repo id is fetched to; default\n"
|
||||
"$XDG_CACHE_HOME/radiance/hf, else ~/.cache/radiance/hf" },
|
||||
{ "--model-revision", "REV", "the hub revision -- a branch, tag, full commit sha or refs/pr/N --\n"
|
||||
"a repo id is fetched at; default the repo's moving main branch" },
|
||||
{ "--radiance-home", "DIRS", "where kernels/, architectures/ and quantizers/ live; several\n"
|
||||
"homes separated by ':' are searched in order, the first winning" },
|
||||
{ "--kernels", "LIST", "the kernel libraries to use, separated by ',' or ':', first wins; unnamed ones are not loaded. Default: every library found" },
|
||||
@@ -213,6 +215,8 @@ static const Flag g_flags[] = {
|
||||
{ "--port", "N", "listen port" },
|
||||
{ "--api-key", "KEY", "require `Authorization: Bearer KEY` or `X-Api-Key: KEY` on every request but /health,\n"
|
||||
" /v1/health, /ping and the dashboard page" },
|
||||
{ "--api-key-env", "NAME", "read the API key from the named environment variable; keeps it off the\n"
|
||||
" command line, where every process on the machine can read it" },
|
||||
{ "--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" },
|
||||
@@ -523,6 +527,7 @@ int config_parse(int argc, char** argv, Config* c) {
|
||||
else if (S("-vv")) log_set_level(Log::Trace);
|
||||
else if (S("--model")) { if (!(v = need(i))) return RAD_E_INVAL; c->model = v; }
|
||||
else if (S("--download-dir")) { if (!(v = need(i))) return RAD_E_INVAL; c->download_dir = v; }
|
||||
else if (S("--model-revision")) { if (!(v = need(i))) return RAD_E_INVAL; c->model_revision = v; }
|
||||
else if (S("--radiance-home")) { if (!(v = need(i))) return RAD_E_INVAL; c->radiance_home = v; }
|
||||
else if (S("--kernels")) { if (!(v = need(i))) return RAD_E_INVAL; c->kernel_hierarchy = rad_split_kernel_list(v); }
|
||||
else if (S("--tp")) { if (!num(1, INT32_MAX, &c->tp)) return RAD_E_INVAL; }
|
||||
@@ -823,6 +828,23 @@ int config_parse(int argc, char** argv, Config* c) {
|
||||
return RAD_E_INVAL; }
|
||||
c->api_key = v;
|
||||
}
|
||||
else if (S("--api-key-env")) {
|
||||
if (!(v = need(i))) return RAD_E_INVAL;
|
||||
if (!*v) { RAD_ERR("--api-key-env takes the name of an environment variable");
|
||||
return RAD_E_INVAL; }
|
||||
const char* k = std::getenv(v);
|
||||
/* The empty --api-key refusal's sibling: a unit or compose file whose variable was
|
||||
* never set must not start a server that looks guarded and answers everything
|
||||
* keyless. The name is recorded so the config report can say where the key came
|
||||
* from without showing it. */
|
||||
if (!k || !*k) {
|
||||
RAD_ERR("--api-key-env: %s is unset or empty; refusing to serve keyless under a "
|
||||
"guarded-looking command line", v);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
c->api_key = k;
|
||||
c->api_key_env = v;
|
||||
}
|
||||
else if (S("--allow-host")) {
|
||||
if (!(v = need(i))) return RAD_E_INVAL;
|
||||
if (!*v) { RAD_ERR("--allow-host takes a non-empty name"); return RAD_E_INVAL; }
|
||||
@@ -1269,6 +1291,7 @@ struct ShowRow { const char* flag; Show show; };
|
||||
const ShowRow kShow[] = {
|
||||
{ "--model", [](const Config& c) { return c.model; } },
|
||||
{ "--download-dir", [](const Config& c) { return or_none(c.download_dir, "the XDG cache (~/.cache/radiance/hf)"); } },
|
||||
{ "--model-revision", [](const Config& c) { return or_none(c.model_revision, "the repo's main branch"); } },
|
||||
{ "--radiance-home", [](const Config& c) { return c.radiance_home; } },
|
||||
{ "--kernels", [](const Config& c) {
|
||||
std::string s;
|
||||
@@ -1352,6 +1375,7 @@ const ShowRow kShow[] = {
|
||||
{ "--port", [](const Config& c) { return num(c.port); } },
|
||||
/* Never print the secret, only whether it is set. */
|
||||
{ "--api-key", [](const Config& c) { return std::string(c.api_key.empty() ? "not set" : "set"); } },
|
||||
{ "--api-key-env", [](const Config& c) { return or_none(c.api_key_env, "not used"); } },
|
||||
{ "--allow-host", [](const Config& c) {
|
||||
std::string o;
|
||||
for (const std::string& h : c.allow_hosts) o += (o.empty() ? "" : ",") + h;
|
||||
|
||||
+7
-4
@@ -51,15 +51,18 @@ std::string hfget_path() {
|
||||
return fs::is_regular_file(p, ec) ? p.lexically_normal().string() : std::string();
|
||||
}
|
||||
|
||||
/* The script's exit status, or -1 when it could not be run. */
|
||||
int run_hfget(const std::string& script, const std::string& repo, const std::string& dest) {
|
||||
/* The script's exit status, or -1 when it could not be run. `rev` empty leaves the script's own
|
||||
* default: the repo's moving default branch. */
|
||||
int run_hfget(const std::string& script, const std::string& repo, const std::string& dest,
|
||||
const std::string& rev) {
|
||||
const pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
RAD_ERR("hfget: fork: %s", std::strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
const char* argv[] = { "sh", script.c_str(), repo.c_str(), dest.c_str(), nullptr };
|
||||
const char* argv[] = { "sh", script.c_str(), repo.c_str(), dest.c_str(),
|
||||
rev.empty() ? nullptr : rev.c_str(), nullptr };
|
||||
execv("/bin/sh", const_cast<char* const*>(argv));
|
||||
std::fprintf(stderr, "hfget: /bin/sh: %s\n", std::strerror(errno));
|
||||
_exit(127);
|
||||
@@ -134,7 +137,7 @@ bool resolve_hf_model(Config& c) {
|
||||
}
|
||||
RAD_INFO("model: %s is not a path here; fetching it as a Hugging Face repo into %s",
|
||||
repo.c_str(), dest.c_str());
|
||||
const int rc = run_hfget(script, repo, dest);
|
||||
const int rc = run_hfget(script, repo, dest, c.model_revision);
|
||||
if (rc != 0) {
|
||||
if (rc == 3 && cached) {
|
||||
RAD_WARN("model: %s could not be checked for changes (hfget.sh, above); serving the "
|
||||
|
||||
@@ -787,6 +787,8 @@ struct Config {
|
||||
std::string model; /* path to the .rad, or a Hugging Face repo id (hf_model.h) */
|
||||
LoraConfig lora; /* --lora, --max-loras, --max-lora-rank, --lora-target-modules */
|
||||
std::string download_dir; /* where a repo id is fetched to; empty = the XDG cache */
|
||||
std::string model_revision; /* --model-revision: the hub revision a repo id fetches;
|
||||
empty = the repo's moving default branch */
|
||||
std::string radiance_home;
|
||||
std::vector<std::string> kernel_hierarchy; /* ordered; first wins */
|
||||
|
||||
@@ -1049,6 +1051,9 @@ struct Config {
|
||||
/* --api-key: the bearer key every request but the probes and the dashboard page must carry.
|
||||
* Empty serves without one. */
|
||||
std::string api_key;
|
||||
/* --api-key-env: the environment variable api_key was read from, recorded so the config
|
||||
* report can say where the key came from. Empty when the key came from the command line. */
|
||||
std::string api_key_env;
|
||||
/* --allow-host, repeatable: Host names the keyless loopback-only routes accept beside the
|
||||
* loopback names themselves, for operators who reach the box by another name. */
|
||||
std::vector<std::string> allow_hosts;
|
||||
|
||||
Reference in new issue
Block a user