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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user