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
+13 -7
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"git.a-wan.net/alan/pipelines/internal/agentenv"
"git.a-wan.net/alan/pipelines/internal/opencode"
"git.a-wan.net/alan/pipelines/internal/workenv"
"io"
@@ -138,13 +139,7 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
cmd := opencode.CommandContext(ctx, opencode.Executable(), args...)
cmd.Dir = directory
// The run's directory environment (workenv.WithEnvironment), if any.
cmd.Env = workenv.CommandEnv(ctx, directory)
if c.ArtifactsDir != "" {
if cmd.Env == nil {
cmd.Env = os.Environ()
}
cmd.Env = append(cmd.Env, ArtifactsEnv+"="+c.ArtifactsDir)
}
cmd.Env = openCodeCLIEnv(ctx, directory, c.ArtifactsDir)
if c.connection != nil {
c.connection.PinCLI(cmd)
}
@@ -517,3 +512,14 @@ func (b *boundedBuffer) Write(p []byte) (int, error) {
}
var _ io.Writer = (*boundedBuffer)(nil)
// openCodeCLIEnv is the environment of an OpenCode CLI call for a stage: the
// run directory's (or the server's) environment without Pipelines' own
// secrets, plus the stage's artifacts directory.
func openCodeCLIEnv(ctx context.Context, directory, artifactsDir string) []string {
env := agentenv.Scrub(workenv.CommandEnv(ctx, directory))
if artifactsDir != "" {
env = append(env, ArtifactsEnv+"="+artifactsDir)
}
return env
}