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>
57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
package claude
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// A chat's Claude Code process never sees Pipelines' own secret pointers,
|
|
// while the server still resolves its service token for it.
|
|
func TestChatProcessEnvironmentScrubsPipelinesSecrets(t *testing.T) {
|
|
chat := directoryChat(t)
|
|
t.Setenv("PIPELINES_SERVER_TOKEN_FILE", "/secret/server-token")
|
|
t.Setenv("PIPELINES_WEB_AUTH_FILE", "/secret/web-auth.json")
|
|
t.Setenv("PIPELINES_UPDATE_SIGNING_KEY", "/secret/update-signing-key.pem")
|
|
t.Setenv("FAKE_CLAUDE_ENV_KEYS", "PIPELINES_SERVER_TOKEN_FILE,PIPELINES_WEB_AUTH_FILE,PIPELINES_UPDATE_SIGNING_KEY,PIPELINES_CLAUDE_TOKEN_FILE,CLAUDE_CODE_OAUTH_TOKEN")
|
|
session := newCreatedChat(t, chat)
|
|
frames := subscribe(t, chat, session.ID)
|
|
if err := chat.Prompt(context.Background(), session.ID, "hello"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitStepEnded(t, frames)
|
|
spawn := lastSpawn(t)
|
|
for _, key := range []string{"PIPELINES_SERVER_TOKEN_FILE", "PIPELINES_WEB_AUTH_FILE", "PIPELINES_UPDATE_SIGNING_KEY", ServiceTokenEnvKey} {
|
|
if got := envOf(spawn, key); got != "<unset>" {
|
|
t.Errorf("%s reached Claude Code: %q", key, got)
|
|
}
|
|
}
|
|
if envOf(spawn, "CLAUDE_CODE_OAUTH_TOKEN") != "service-token" {
|
|
t.Fatalf("service token no longer resolved for the chat: %v", spawn.Env)
|
|
}
|
|
}
|
|
|
|
// A hosted chat's Claude Code (server -> pipelines-claude-host -> CLI) never
|
|
// sees them either.
|
|
func TestHostedChatProcessEnvironmentScrubsPipelinesSecrets(t *testing.T) {
|
|
hostedSetup(t)
|
|
t.Setenv("PIPELINES_SERVER_TOKEN_FILE", "/secret/server-token")
|
|
t.Setenv("PIPELINES_WEB_AUTH_FILE", "/secret/web-auth.json")
|
|
t.Setenv("FAKE_CLAUDE_ENV_KEYS", "PIPELINES_SERVER_TOKEN_FILE,PIPELINES_WEB_AUTH_FILE,CLAUDE_CONFIG_DIR")
|
|
chat := hostedChat(t)
|
|
session := newCreatedChat(t, chat)
|
|
frames := subscribe(t, chat, session.ID)
|
|
if err := chat.Prompt(context.Background(), session.ID, "hello"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
waitStepEnded(t, frames)
|
|
spawn := lastSpawn(t)
|
|
for _, key := range []string{"PIPELINES_SERVER_TOKEN_FILE", "PIPELINES_WEB_AUTH_FILE"} {
|
|
if got := envOf(spawn, key); got != "<unset>" {
|
|
t.Errorf("%s reached the hosted Claude Code: %q", key, got)
|
|
}
|
|
}
|
|
if envOf(spawn, "CLAUDE_CONFIG_DIR") == "<unset>" {
|
|
t.Fatalf("harness config directory dropped: %v", spawn.Env)
|
|
}
|
|
}
|