diff --git a/executor/server.go b/executor/server.go index 8780790..407398a 100644 --- a/executor/server.go +++ b/executor/server.go @@ -84,7 +84,7 @@ func runServer(ctx context.Context, config Config, rootDir string) error { } } - if runtimeConfig.IP != nil { + if !runtimeConfig.UseHostNetwork && runtimeConfig.IP != nil { if err := network.SetupContainer(runtimeConfig.IP); err != nil { return err } diff --git a/isolator.go b/isolator.go index 3b40072..92f794d 100644 --- a/isolator.go +++ b/isolator.go @@ -225,8 +225,7 @@ func newExecutorServerCommand(config Config) *exec.Cmd { unix.CLONE_NEWUSER | unix.CLONE_NEWIPC | unix.CLONE_NEWUTS | - unix.CLONE_NEWCGROUP | - unix.CLONE_NEWNET, + unix.CLONE_NEWCGROUP, AmbientCaps: []uintptr{ unix.CAP_SYS_ADMIN, // by adding CAP_SYS_ADMIN executor may mount /proc }, @@ -247,6 +246,10 @@ func newExecutorServerCommand(config Config) *exec.Cmd { }, } + if !config.Executor.UseHostNetwork { + cmd.SysProcAttr.Cloneflags |= unix.CLONE_NEWNET + } + return cmd } diff --git a/wire/wire.go b/wire/wire.go index 6eb8538..fdc1d78 100644 --- a/wire/wire.go +++ b/wire/wire.go @@ -28,6 +28,9 @@ type Config struct { // ConfigureSystem tells executor to mount standard mounts like /proc, /dev, /tmp ... and configure DNS inside new root. ConfigureSystem bool + // UseHostNetwork instructs isolator to use host's network and prevents network namespace from being isolated. + UseHostNetwork bool + // IP is the IP to assign executor to. IP *net.IPNet