mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 17:57:54 -10:00
* feat(sandbox): unify command execution and enforcement * test(sandbox): make platform contracts portable * fix(sandbox): close execution lifecycle races Bound retained interactive output, preserve interruption state, and start workspace observation before process launch. Protect active runtime roots with cross-platform leases, capture transient protected-path creation events, and restore process attributes after PTY fallback. * fix(sandbox): restore strict macOS isolation Remove Seatbelt host-local network allowances after native validation showed localhost filters can reach host interfaces. Track process reap completion so retained sessions cannot signal a stale numeric PID.
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
//go:build linux
|
|
|
|
package sandbox
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestLinuxSandboxInnerStageReliesOnOuterNamespaceForNetworkDeny(t *testing.T) {
|
|
originalNetworkGuard := applyLinuxIsolatedNetworkGuardFilter
|
|
originalUnixBlock := applyUnixSocketBlockFilter
|
|
t.Cleanup(func() {
|
|
applyLinuxIsolatedNetworkGuardFilter = originalNetworkGuard
|
|
applyUnixSocketBlockFilter = originalUnixBlock
|
|
})
|
|
|
|
networkGuardCalls := 0
|
|
unixBlockCalls := 0
|
|
applyLinuxIsolatedNetworkGuardFilter = func() error {
|
|
networkGuardCalls++
|
|
return nil
|
|
}
|
|
applyUnixSocketBlockFilter = func() error {
|
|
unixBlockCalls++
|
|
return nil
|
|
}
|
|
|
|
var stderr bytes.Buffer
|
|
code := runLinuxSandboxInnerStage(LinuxSandboxHelperConfig{
|
|
PermissionProfile: PermissionProfile{Network: NetworkPolicy{Mode: NetworkDeny}},
|
|
BlockUnixSockets: true,
|
|
Command: []string{"definitely-not-a-real-zero-test-command"},
|
|
}, &stderr)
|
|
|
|
if code != 127 {
|
|
t.Fatalf("exit code = %d, want lookup failure 127 after Unix-socket filter; stderr=%s", code, stderr.String())
|
|
}
|
|
if networkGuardCalls != 1 {
|
|
t.Fatalf("isolated network guard calls = %d, want 1", networkGuardCalls)
|
|
}
|
|
if unixBlockCalls != 1 {
|
|
t.Fatalf("unix socket filter calls = %d, want 1", unixBlockCalls)
|
|
}
|
|
}
|
|
|
|
func TestLinuxSandboxInnerStageSkipsIsolatedNetworkGuardWhenNetworkAllowed(t *testing.T) {
|
|
originalNetworkGuard := applyLinuxIsolatedNetworkGuardFilter
|
|
t.Cleanup(func() {
|
|
applyLinuxIsolatedNetworkGuardFilter = originalNetworkGuard
|
|
})
|
|
|
|
applyLinuxIsolatedNetworkGuardFilter = func() error {
|
|
return errors.New("isolated network guard should not run")
|
|
}
|
|
|
|
var stderr bytes.Buffer
|
|
code := runLinuxSandboxInnerStage(LinuxSandboxHelperConfig{
|
|
PermissionProfile: PermissionProfile{Network: NetworkPolicy{Mode: NetworkAllow}},
|
|
Command: []string{"definitely-not-a-real-zero-test-command"},
|
|
}, &stderr)
|
|
|
|
if code != 127 {
|
|
t.Fatalf("exit code = %d, want lookup failure 127 without isolated network guard; stderr=%s", code, stderr.String())
|
|
}
|
|
}
|