Scrub Pipelines secret pointers from agent environments (H3, layer 1)

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>
This commit is contained in:
2026-12-03 23:16:57 +00:00
parent e39a9560ba
commit b24fc31761
23 changed files with 503 additions and 37 deletions
+31
View File
@@ -0,0 +1,31 @@
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)
}
}
}
+5 -2
View File
@@ -6,6 +6,8 @@ import (
"os"
"strconv"
"strings"
"git.a-wan.net/alan/pipelines/internal/agentenv"
)
// Stage and chat OpenCode limits. OpenCode reads tool_output and compaction
@@ -151,10 +153,11 @@ func serviceEnvironment(content string) []string {
}
// serviceEnvironmentFrom is serviceEnvironment over base instead of the
// server's own environment (a run directory's resolved environment).
// server's own environment (a run directory's resolved environment). Pipelines'
// own secrets never reach the serve process or the tools it runs.
func serviceEnvironmentFrom(base []string, content string) []string {
var env []string
for _, entry := range base {
for _, entry := range agentenv.Scrub(base) {
if strings.HasPrefix(entry, "OPENCODE_SERVER_PASSWORD=") || strings.HasPrefix(entry, "OPENCODE_SERVER_USERNAME=") ||
(content != "" && strings.HasPrefix(entry, "OPENCODE_CONFIG_CONTENT=")) {
continue