* fix pr check
This commit is contained in:
parent
d0552a1d6b
commit
0fc9c4c5e1
4 changed files with 36 additions and 41 deletions
|
|
@ -44,9 +44,9 @@ func applyPlatformIsolation(cmd *exec.Cmd, isolation config.IsolationConfig, roo
|
||||||
originalArgs := append([]string{}, cmd.Args...)
|
originalArgs := append([]string{}, cmd.Args...)
|
||||||
originalDir := cmd.Dir
|
originalDir := cmd.Dir
|
||||||
|
|
||||||
// Start from the configured mount plan, then add the executable, its resolved
|
// Start from the configured mount plan, then add only the executable, its
|
||||||
// path, the working directory, and any absolute path arguments the process may
|
// resolved path, and the working directory. Any additional host paths must be
|
||||||
// need at runtime.
|
// exposed explicitly via config instead of being inferred from argv.
|
||||||
plan := BuildLinuxMountPlan(root, isolation.ExposePaths)
|
plan := BuildLinuxMountPlan(root, isolation.ExposePaths)
|
||||||
plan = ensureLinuxMountRule(plan, originalPath, originalPath, "ro")
|
plan = ensureLinuxMountRule(plan, originalPath, originalPath, "ro")
|
||||||
plan = ensureLinuxMountRule(plan, filepath.Dir(originalPath), filepath.Dir(originalPath), "ro")
|
plan = ensureLinuxMountRule(plan, filepath.Dir(originalPath), filepath.Dir(originalPath), "ro")
|
||||||
|
|
@ -60,11 +60,6 @@ func applyPlatformIsolation(cmd *exec.Cmd, isolation config.IsolationConfig, roo
|
||||||
plan = ensureLinuxMountRule(plan, resolved, resolved, "rw")
|
plan = ensureLinuxMountRule(plan, resolved, resolved, "rw")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, arg := range originalArgs[1:] {
|
|
||||||
if filepath.IsAbs(arg) {
|
|
||||||
plan = ensureLinuxPathForArgument(plan, arg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.DebugCF("isolation", "linux isolation mount plan",
|
logger.DebugCF("isolation", "linux isolation mount plan",
|
||||||
map[string]any{
|
map[string]any{
|
||||||
"root": root,
|
"root": root,
|
||||||
|
|
@ -166,24 +161,3 @@ func linuxBindFlag(rule MountRule) (string, error) {
|
||||||
}
|
}
|
||||||
return "--ro-bind", nil
|
return "--ro-bind", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureLinuxPathForArgument exposes absolute-path arguments conservatively so
|
|
||||||
// common CLI flags that point at files or directories keep working in the
|
|
||||||
// isolated filesystem view.
|
|
||||||
func ensureLinuxPathForArgument(plan []MountRule, arg string) []MountRule {
|
|
||||||
clean := filepath.Clean(arg)
|
|
||||||
if info, err := os.Stat(clean); err == nil {
|
|
||||||
if info.IsDir() {
|
|
||||||
return ensureLinuxMountRule(plan, clean, clean, "rw")
|
|
||||||
}
|
|
||||||
return ensureLinuxMountRule(plan, filepath.Dir(clean), filepath.Dir(clean), "rw")
|
|
||||||
}
|
|
||||||
parent := filepath.Dir(clean)
|
|
||||||
if parent == "." || parent == "/" {
|
|
||||||
return plan
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(parent); err == nil {
|
|
||||||
return ensureLinuxMountRule(plan, parent, parent, "rw")
|
|
||||||
}
|
|
||||||
return plan
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ func TestBuildLinuxBwrapArgs_IncludesNamespaceFlagsAndExec(t *testing.T) {
|
||||||
hasExec := false
|
hasExec := false
|
||||||
for i := range args {
|
for i := range args {
|
||||||
switch args[i] {
|
switch args[i] {
|
||||||
|
case "--unshare-net":
|
||||||
|
hasNet = true
|
||||||
case "--unshare-ipc":
|
case "--unshare-ipc":
|
||||||
hasIPC = true
|
hasIPC = true
|
||||||
case "--":
|
case "--":
|
||||||
|
|
|
||||||
|
|
@ -294,7 +294,11 @@ func BuildWindowsAccessRules(root string, overrides []config.ExposePath) []Acces
|
||||||
// IsSupported reports whether the current platform has an implemented isolation
|
// IsSupported reports whether the current platform has an implemented isolation
|
||||||
// backend.
|
// backend.
|
||||||
func IsSupported() bool {
|
func IsSupported() bool {
|
||||||
switch runtime.GOOS {
|
return isSupportedOn(runtime.GOOS)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSupportedOn(goos string) bool {
|
||||||
|
switch goos {
|
||||||
case "linux", "windows":
|
case "linux", "windows":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
|
|
@ -309,6 +313,9 @@ func Preflight() error {
|
||||||
if !isolation.Enabled {
|
if !isolation.Enabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if !IsSupported() {
|
||||||
|
return fmt.Errorf("subprocess isolation is not supported on %s", runtime.GOOS)
|
||||||
|
}
|
||||||
root, err := ResolveInstanceRoot()
|
root, err := ResolveInstanceRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package isolation
|
package isolation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -25,17 +26,28 @@ func TestPrepareInstanceRoot_CreatesDirectories(t *testing.T) {
|
||||||
if err := PrepareInstanceRoot(root); err != nil {
|
if err := PrepareInstanceRoot(root); err != nil {
|
||||||
t.Fatalf("PrepareInstanceRoot() error = %v", err)
|
t.Fatalf("PrepareInstanceRoot() error = %v", err)
|
||||||
}
|
}
|
||||||
for _, dir := range []string{
|
for _, dir := range InstanceDirs(root) {
|
||||||
root,
|
if info, err := os.Stat(dir); err != nil {
|
||||||
filepath.Join(root, "workspace"),
|
t.Fatalf("os.Stat(%q): %v", dir, err)
|
||||||
filepath.Join(root, "skills"),
|
} else if !info.IsDir() {
|
||||||
filepath.Join(root, "logs"),
|
t.Fatalf("%q is not a directory", dir)
|
||||||
filepath.Join(root, "cache"),
|
}
|
||||||
filepath.Join(root, "state"),
|
}
|
||||||
filepath.Join(root, "runtime-user-env"),
|
}
|
||||||
} {
|
|
||||||
if _, err := filepath.Abs(dir); err != nil {
|
func TestIsSupportedOn(t *testing.T) {
|
||||||
t.Fatalf("filepath.Abs(%q): %v", dir, err)
|
tests := []struct {
|
||||||
|
goos string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{goos: "linux", want: true},
|
||||||
|
{goos: "windows", want: true},
|
||||||
|
{goos: "darwin", want: false},
|
||||||
|
{goos: "freebsd", want: false},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
if got := isSupportedOn(tt.goos); got != tt.want {
|
||||||
|
t.Fatalf("isSupportedOn(%q) = %v, want %v", tt.goos, got, tt.want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue