Files
llmgw/internal/agent/engines/unsafeenv_test.go
T
Ilker ManapandClaude Opus 5.5 c19abe95e1 Refuse profile env and args that would run code or touch files on the nodes
env is an allowlist of tuning families less path, plugin, library, address
and credential names (NCCL_*_PLUGIN, CUDA_INJECTION64_PATH and the like
got through the old denylist); llama.cpp's LLAMA_ARG_* are checked as
flags. args refuse --trust-remote-code, --log-file, --slot-save-path,
--tool-parser-plugin, --middleware, --allowed-local-media-path and others
that read, write or load, and what the agent sets itself. Checked in the
catalog and again on the node before an engine starts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-04 09:54:45 +02:00

65 lines
2.4 KiB
Go

package engines
import "testing"
func TestTuningVariablesAreAllowedAndWaysToRunCodeAreNot(t *testing.T) {
for _, k := range []string{
"CUDA_VISIBLE_DEVICES", "CUDA_MODULE_LOADING", "NCCL_IB_HCA", "NCCL_DEBUG", "NCCL_NET",
"VLLM_ATTENTION_BACKEND", "PYTORCH_CUDA_ALLOC_CONF", "OMP_NUM_THREADS", "HF_HUB_OFFLINE",
"GGML_VK_VISIBLE_DEVICES", "TOKENIZERS_PARALLELISM", "PYTHONUNBUFFERED", "LLAMA_ARG_CTX_SIZE",
} {
if bad, why := UnsafeEnv(k); bad {
t.Errorf("%s refused: %s", k, why)
}
}
for _, k := range []string{
"LD_PRELOAD", "PATH", "PYTHONPATH", "PYTHONSTARTUP", "BASH_ENV",
// What the denylist missed: each loads a library or moves where the
// engine reads and writes.
"NCCL_NET_PLUGIN", "NCCL_TUNER_PLUGIN", "NCCL_PROFILER_PLUGIN", "CUDA_INJECTION64_PATH",
"NVTX_INJECTION64_PATH", "TRITON_CACHE_DIR", "HF_HOME", "HF_TOKEN", "NCCL_DEBUG_FILE",
"VLLM_PLUGINS", "UCX_MODULE_DIR", "TORCH_EXTENSIONS_DIR",
// llama.cpp's flags as variables.
"LLAMA_ARG_LOG_FILE", "LLAMA_ARG_HOST", "LLAMA_ARG_SLOT_SAVE_PATH",
// Anything outside the families.
"SOMETHING_ELSE", "",
} {
if bad, _ := UnsafeEnv(k); !bad {
t.Errorf("%s allowed", k)
}
}
}
func TestArgumentsThatReadWriteOrLoadAreRefused(t *testing.T) {
ok := map[string][]string{
"llamacpp": {"--ctx-size", "16384", "--embedding", "--parallel", "4", "--jinja", "--n-gpu-layers=999"},
"vllm": {"--max-model-len", "8192", "--gpu-memory-utilization", "0.9", "--enable-auto-tool-choice"},
"sglang": {"--mem-fraction-static", "0.8", "--tool-call-parser", "qwen25"},
}
for eng, args := range ok {
if err := UnsafeArgs(eng, args); err != nil {
t.Errorf("%s %v: %v", eng, args, err)
}
}
for _, c := range []struct {
eng string
args []string
}{
{"vllm", []string{"--trust-remote-code"}},
{"sglang", []string{"--trust-remote-code"}},
{"vllm", []string{"--tool-parser-plugin", "/tmp/x.py"}},
{"vllm", []string{"--middleware=evil.mod"}},
{"vllm", []string{"--allowed-local-media-path", "/"}},
{"llamacpp", []string{"--log-file", "/etc/cron.d/x"}},
{"llamacpp", []string{"--slot-save-path=/root"}},
{"llamacpp", []string{"--path", "/"}},
{"llamacpp", []string{"--system-prompt-file", "/etc/shadow"}},
{"llamacpp", []string{"--host", "0.0.0.0"}},
{"vllm", []string{"--api-key", "x"}},
} {
if err := UnsafeArgs(c.eng, c.args); err == nil {
t.Errorf("%s %v allowed", c.eng, c.args)
}
}
}