From 853ae490e162e8703fde5425fead1ea8da09fdcf Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Wed, 15 May 2024 14:42:57 -0700 Subject: [PATCH] Sanitize the env var debug log Only dump env vars we care about in the logs --- llm/server.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/llm/server.go b/llm/server.go index 87f5b5455..119699971 100644 --- a/llm/server.go +++ b/llm/server.go @@ -317,8 +317,22 @@ func NewLlamaServer(gpus gpu.GpuInfoList, model string, ggml *GGML, adapters, pr } slog.Info("starting llama server", "cmd", s.cmd.String()) - // Log at debug as the environment is inherited and might contain sensitive information - slog.Debug("subprocess", "environment", s.cmd.Env) + if envconfig.Debug { + filteredEnv := []string{} + for _, ev := range s.cmd.Env { + if strings.HasPrefix(ev, "CUDA_") || + strings.HasPrefix(ev, "ROCM_") || + strings.HasPrefix(ev, "HIP_") || + strings.HasPrefix(ev, "HSA_") || + strings.HasPrefix(ev, "GGML_") || + strings.HasPrefix(ev, "PATH=") || + strings.HasPrefix(ev, "LD_LIBRARY_PATH=") { + filteredEnv = append(filteredEnv, ev) + } + } + // Log at debug as the environment is inherited and might contain sensitive information + slog.Debug("subprocess", "environment", filteredEnv) + } if err = s.cmd.Start(); err != nil { // Detect permission denied and augment them essage about noexec