Merge branch 'worktree-agent-a6787b14310453b9c'
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user