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>
32 lines
1.1 KiB
Go
32 lines
1.1 KiB
Go
package opencode
|
|
|
|
import (
|
|
"os"
|
|
"slices"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/agentenv"
|
|
)
|
|
|
|
// The OpenCode serve processes (chat service and owned stage services) and the
|
|
// tools they run never see Pipelines' own secret pointers.
|
|
func TestServiceEnvironmentScrubsPipelinesSecrets(t *testing.T) {
|
|
t.Setenv("PIPELINES_SERVER_TOKEN_FILE", "/secret/server-token")
|
|
t.Setenv("PIPELINES_WEB_AUTH_FILE", "/secret/web-auth.json")
|
|
t.Setenv("PIPELINES_OPENCODE_ENDPOINT_PASSWORD_FILE", "/secret/opencode-password")
|
|
t.Setenv("KEEP_ME", "1")
|
|
for name, env := range map[string][]string{
|
|
"chat service": serviceEnvironment(`{"a":1}`),
|
|
"stage service (server env)": serviceEnvironmentFrom(nil, ""),
|
|
"stage service (run env)": serviceEnvironmentFrom(append(os.Environ(), "PIPELINES_X_TOKEN=envrc"), ""),
|
|
"stage service (owned config)": serviceEnvironmentFrom(os.Environ(), `{"b":2}`),
|
|
} {
|
|
if leaks := agentenv.Leaks(env); len(leaks) > 0 {
|
|
t.Errorf("%s leaks %v", name, leaks)
|
|
}
|
|
if !slices.Contains(env, "KEEP_ME=1") {
|
|
t.Errorf("%s dropped an ordinary variable", name)
|
|
}
|
|
}
|
|
}
|