feat(daemon): run a Kit profile's task in its Kit container on the egress path

This commit is contained in:
sam committed 2026-09-26 10:14:33 +10:00
1 parent 25f2299225
commit 70df8d1131
17 files changed
+734 -42

No files matched your search

+3
View File
@@ -22,3 +22,6 @@ func runAsHarnessUser(_ *exec.Cmd, name string) error {
// ownForHarness has nothing to do where the harness runs as the worker.
func ownForHarness(string, ...string) error { return nil }
// ownTreeForHarness has nothing to do where the harness runs as the worker.
func ownTreeForHarness(string, string) error { return nil }
+24
View File
@@ -5,9 +5,11 @@ package agentexec
import (
"errors"
"fmt"
"io/fs"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
"syscall"
@@ -91,3 +93,25 @@ func ownForHarness(name string, paths ...string) error {
}
return nil
}
// ownTreeForHarness gives the worktree to the harness user when the worker
// is root, except .git: the harness edits files and never writes the
// repository, so its refs and config stay the worker's.
func ownTreeForHarness(name, root string) error {
if name == "" || os.Geteuid() != 0 {
return nil
}
cred, err := harnessCredential(name)
if err != nil {
return err
}
return filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() && d.Name() == ".git" && path != root {
return filepath.SkipDir
}
return os.Lchown(path, int(cred.Uid), int(cred.Gid))
})
}
+3
View File
@@ -69,6 +69,9 @@ func (r *HarnessRunner) Run(ctx context.Context, workspace string, req Request,
if err := validateHarness(req); err != nil {
return Result{}, err
}
if err := ownTreeForHarness(req.Harness.User, workspace); err != nil {
return Result{}, fmt.Errorf("give the worktree to the harness user: %w", err)
}
mcpConfig, capturesPath, cleanup, err := r.prepareCaptures(req)
if err != nil {
return Result{}, err