My ambition was to run a Linux namespace (in Go) inside of a remote container which I can run isolated process without affecting to the host.
cmd := exec.Command("/bin/bash")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWUTS,
}
err := cmd.Run()
if err != nil {
fmt.Printf(err.Error())
os.Exit(1)
}
Let's imagine I wanted to run bash
inside this isolated space. So I run a new UTS namespace for it. So when I ran the code I got this error.
fork/exec /bin/bash: operation not permitted
I did some investigation on this error and realized error cause due to unprivilaged namepsace issue. So when I comment out these lines
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWUTS,
}
code works. But it does not serve the purpose. Also I tried --privilaged
but didn't work. Is there any other way to overcome this?