27 lines
968 B
Go
27 lines
968 B
Go
package secretengine
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
"testing"
|
|
)
|
|
|
|
// requireNamespaces skips when the kernel refuses the user and network
|
|
// namespaces extension confinement needs, as a default Docker seccomp profile
|
|
// does. Confinement has no fallback, so such a host cannot launch extensions
|
|
// at all and there is nothing here to test.
|
|
func requireNamespaces(t *testing.T) {
|
|
t.Helper()
|
|
cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=^$")
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
Cloneflags: syscall.CLONE_NEWUSER | syscall.CLONE_NEWNET,
|
|
UidMappings: []syscall.SysProcIDMap{{ContainerID: os.Getuid(), HostID: os.Getuid(), Size: 1}},
|
|
GidMappings: []syscall.SysProcIDMap{{ContainerID: os.Getgid(), HostID: os.Getgid(), Size: 1}},
|
|
}
|
|
if err := cmd.Run(); errors.Is(err, syscall.EPERM) || errors.Is(err, syscall.EINVAL) || errors.Is(err, syscall.ENOSPC) {
|
|
t.Skipf("kernel refuses user and network namespaces: %v", err)
|
|
}
|
|
}
|