b24fc31761
New internal/agentenv drops every PIPELINES_* variable naming a token, secret, password, auth file or key (except *_PUBLIC_KEY) from the environment of processes started for agents: Claude stages and chats (direct and hosted), Pi stages, OpenCode stage CLI calls and serve processes, check commands, delivery-gate checks, `!` shell lines, the run's workspace environment and turn-diff git snapshots. MCP servers are children of the harness and inherit its scrubbed environment. The interactive terminal is unchanged. An agent's `pipelines` CLI call falls back to the default server-token location. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package agentenv
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
var planted = []string{
|
|
"PIPELINES_SERVER_TOKEN_FILE",
|
|
"PIPELINES_WEB_AUTH_FILE",
|
|
"PIPELINES_WEB_AUTH",
|
|
"PIPELINES_WEB_PASSWORD",
|
|
"PIPELINES_UPDATE_SIGNING_KEY",
|
|
"PIPELINES_CLAUDE_TOKEN_FILE",
|
|
"PIPELINES_OPENCODE_ENDPOINT_PASSWORD_FILE",
|
|
"PIPELINES_NTFY_TOKEN_FILE",
|
|
"PIPELINES_NTFY_TOKEN",
|
|
"PIPELINES_SOMETHING_SECRET",
|
|
}
|
|
|
|
func TestSecretNames(t *testing.T) {
|
|
for _, name := range planted {
|
|
if !Secret(name) {
|
|
t.Errorf("%s should be secret", name)
|
|
}
|
|
}
|
|
for _, name := range []string{"PATH", "HOME", "CLAUDE_CONFIG_DIR", "CODEX_HOME", "CLAUDE_CODE_OAUTH_TOKEN", "ANTHROPIC_API_KEY",
|
|
"PIPELINES_UPDATE_PUBLIC_KEY", "PIPELINES_DEFAULT_MODEL", "PIPELINES_WEB_PUBLIC_URL", "PIPELINES_NTFY_URL", "PIPELINES_ARTIFACTS_DIR", "PIPELINES_MDNS"} {
|
|
if Secret(name) {
|
|
t.Errorf("%s should be kept", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestScrubKeepsOrderAndInput(t *testing.T) {
|
|
in := []string{"PATH=/bin", "PIPELINES_SERVER_TOKEN_FILE=/x", "HOME=/h", "PIPELINES_WEB_AUTH_FILE=/y", "MALFORMED"}
|
|
out := Scrub(in)
|
|
if want := []string{"PATH=/bin", "HOME=/h", "MALFORMED"}; !slices.Equal(out, want) {
|
|
t.Fatalf("Scrub = %v, want %v", out, want)
|
|
}
|
|
if in[1] != "PIPELINES_SERVER_TOKEN_FILE=/x" {
|
|
t.Fatal("Scrub modified its input")
|
|
}
|
|
}
|
|
|
|
func TestScrubNilScrubsServerEnvironment(t *testing.T) {
|
|
for _, name := range planted {
|
|
t.Setenv(name, "/secret/"+name)
|
|
}
|
|
t.Setenv("KEEP_ME", "1")
|
|
out := Environ()
|
|
if !slices.Contains(out, "KEEP_ME=1") {
|
|
t.Fatal("ordinary variable dropped")
|
|
}
|
|
if leaks := Leaks(out); len(leaks) > 0 {
|
|
t.Fatalf("secrets leaked: %v", leaks)
|
|
}
|
|
}
|