"unsafe"
)
+func isDocker() bool {
+ _, err := os.Stat("/.dockerenv")
+ return err == nil
+}
+
+func isLXC() bool {
+ return os.Getenv("container") == "lxc"
+}
+
+func skipInContainer(t *testing.T) {
+ if isDocker() {
+ t.Skip("skip this test in Docker container")
+ }
+ if isLXC() {
+ t.Skip("skip this test in LXC container")
+ }
+}
+
// Check if we are in a chroot by checking if the inode of / is
// different from 2 (there is no better test available to non-root on
// linux).
}
func checkUserNS(t *testing.T) {
+ skipInContainer(t)
if _, err := os.Stat("/proc/self/ns/user"); err != nil {
if os.IsNotExist(err) {
t.Skip("kernel doesn't support user namespaces")
}
func TestUnshare(t *testing.T) {
+ skipInContainer(t)
// Make sure we are running as root so we have permissions to use unshare
// and create a network namespace.
if os.Getuid() != 0 {
// Test for Issue 38471: unshare fails because systemd has forced / to be shared
func TestUnshareMountNameSpace(t *testing.T) {
+ skipInContainer(t)
// Make sure we are running as root so we have permissions to use unshare
// and create a network namespace.
if os.Getuid() != 0 {
// Test for Issue 20103: unshare fails when chroot is used
func TestUnshareMountNameSpaceChroot(t *testing.T) {
+ skipInContainer(t)
// Make sure we are running as root so we have permissions to use unshare
// and create a network namespace.
if os.Getuid() != 0 {
}
func TestAmbientCaps(t *testing.T) {
+ skipInContainer(t)
// Make sure we are running as root so we have permissions to use unshare
// and create a network namespace.
if os.Getuid() != 0 {