make it possible to disable the isolated home for local agents (#6251)

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
confusedsushi
2026-03-19 13:40:24 +01:00
committed by GitHub
parent 2bc56896f3
commit ab73370e93
4 changed files with 19 additions and 3 deletions

View File

@@ -124,6 +124,11 @@ func (e *local) writeNetRC(step *types.Step, state *workflowState) (string, erro
return "", nil
}
if !e.isolatedHome {
log.Trace().Msg("writing .netrc skipped due to disabled isolated home")
return "", nil
}
file := filepath.Join(state.homeDir, ".netrc")
rmCmd := fmt.Sprintf("rm \"%s\"", file)
if e.os == "windows" {

View File

@@ -28,4 +28,10 @@ var Flags = []cli.Flag{
DefaultText: "system temporary directory",
Value: os.TempDir(),
},
&cli.BoolFlag{
Sources: cli.EnvVars("WOODPECKER_BACKEND_LOCAL_ISOLATED_HOME"),
Name: "backend-local-isolated-home",
Usage: "set HOME, USERPROFILE and other variables to an isolated directory, if false we ignore netrc",
Value: true,
},
}

View File

@@ -47,6 +47,7 @@ type stepState struct {
type local struct {
tempDir string
isolatedHome bool
workflows sync.Map
pluginGitBinary string
os, arch string
@@ -84,6 +85,7 @@ func (e *local) Load(ctx context.Context) (*types.BackendInfo, error) {
c, ok := ctx.Value(types.CliCommand).(*cli.Command)
if ok {
e.tempDir = c.String("backend-local-temp-dir")
e.isolatedHome = c.Bool("backend-local-isolated-home")
}
e.loadClone()
@@ -154,9 +156,11 @@ func (e *local) StartStep(ctx context.Context, step *types.Step, taskUUID string
}
}
// Set HOME and CI_WORKSPACE
env = append(env, "HOME="+state.homeDir)
env = append(env, "USERPROFILE="+state.homeDir)
if e.isolatedHome {
env = append(env, "HOME="+state.homeDir)
env = append(env, "USERPROFILE="+state.homeDir)
}
env = append(env, "CI_WORKSPACE="+state.workspaceDir)
switch step.Type {

View File

@@ -190,6 +190,7 @@ func TestRunStep(t *testing.T) {
backend, _ := New().(*local)
backend.tempDir = t.TempDir()
backend.isolatedHome = true
ctx := t.Context()
taskUUID := "test-run-tasks"