test(secretengine): skip the host launch test where the kernel refuses namespaces

This commit is contained in:
sam committed 2026-10-24 21:54:04 +11:00
1 parent 96e27f634e
commit 5c05381db2
3 files changed
+34

No files matched your search

@@ -0,0 +1,26 @@
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)
}
}
@@ -0,0 +1,7 @@
//go:build !linux
package secretengine
import "testing"
func requireNamespaces(*testing.T) {}
@@ -130,6 +130,7 @@ func lanAddress(t *testing.T) string {
}
func TestHostLaunch(t *testing.T) {
requireNamespaces(t)
t.Setenv("ARCHIE_TEST_SECRET", "host-only")
t.Setenv("ARCHIE_TEST_PASSED", "granted")
good := selfDigest(t)