diff options
Diffstat (limited to 'testutil/environment/environment.go')
-rw-r--r-- | testutil/environment/environment.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/testutil/environment/environment.go b/testutil/environment/environment.go index f8df37049d..23ab20451b 100644 --- a/testutil/environment/environment.go +++ b/testutil/environment/environment.go @@ -167,6 +167,27 @@ func (e *Execution) IsRootless() bool { return os.Getenv("DOCKER_ROOTLESS") != "" } +// IsUserNamespaceInKernel returns whether the kernel supports user namespaces +func (e *Execution) IsUserNamespaceInKernel() bool { + if _, err := os.Stat("/proc/self/uid_map"); os.IsNotExist(err) { + /* + * This kernel-provided file only exists if user namespaces are + * supported + */ + return false + } + + // We need extra check on redhat based distributions + if f, err := os.Open("/sys/module/user_namespace/parameters/enable"); err == nil { + defer f.Close() + b := make([]byte, 1) + _, _ = f.Read(b) + return string(b) != "N" + } + + return true +} + // HasExistingImage checks whether there is an image with the given reference. // Note that this is done by filtering and then checking whether there were any // results -- so ambiguous references might result in false-positives. |