Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to use host's network without network namespace #145

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions isolator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -247,6 +246,10 @@ func newExecutorServerCommand(config Config) *exec.Cmd {
},
}

if !config.Executor.UseHostNetwork {
cmd.SysProcAttr.Cloneflags |= unix.CLONE_NEWNET
}

return cmd
}

Expand Down
3 changes: 3 additions & 0 deletions wire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down