I have the following code mnt.go
package main
import (
"fmt"
"log"
"os"
"os/exec"
"syscall"
)
func main() {
fmt.Println("Entering go program")
cmd := exec.Command("/bin/bash")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWNS,
}
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
fmt.Println("Exiting go program")
}
I want to run the above code to spawn a bash shell, and run the following commands:
./mnt
mkdir /tmp/testmount
mount -n -o size=1m -t tmpfs tmpfs /tmp/testmount
cd /tmp/testmount
touch 1.txt 2.txt 3.txt
Now when I launch another shell and run the command
ls /tmp/testmount
I should not be able to see the files 1.txt
, 2.txt
and 3.txt
. Since the temp file system has been mounted inside a mount namespace, it should not be visible from the outside.
But that is not how it works for me. Why is the syscall.CLONE_NEWNS
not working as expected? What should I do differently?
One of the comments mentions that this code works fine for them. FWIW, I am running a "bento/centos-7" Vagrant box with golang installed and no other customizations.