2014-10-17 08:00:59 +08:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2014-11-27 02:16:53 +08:00
|
|
|
"syscall"
|
|
|
|
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
2014-10-17 08:00:59 +08:00
|
|
|
)
|
|
|
|
|
2015-02-07 11:16:11 +08:00
|
|
|
var standardEnvironment = []string{
|
|
|
|
"HOME=/root",
|
|
|
|
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
|
|
|
"HOSTNAME=integration",
|
|
|
|
"TERM=xterm",
|
|
|
|
}
|
|
|
|
|
2015-02-13 08:23:05 +08:00
|
|
|
const defaultMountFlags = syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NODEV
|
|
|
|
|
2014-10-17 08:00:59 +08:00
|
|
|
// newTemplateConfig returns a base template for running a container
|
|
|
|
//
|
|
|
|
// it uses a network strategy of just setting a loopback interface
|
|
|
|
// and the default setup for devices
|
2014-12-17 17:12:23 +08:00
|
|
|
func newTemplateConfig(rootfs string) *configs.Config {
|
|
|
|
return &configs.Config{
|
2015-02-04 09:44:58 +08:00
|
|
|
Rootfs: rootfs,
|
2014-10-17 08:00:59 +08:00
|
|
|
Capabilities: []string{
|
2015-09-10 07:25:43 +08:00
|
|
|
"CAP_CHOWN",
|
|
|
|
"CAP_DAC_OVERRIDE",
|
|
|
|
"CAP_FSETID",
|
|
|
|
"CAP_FOWNER",
|
|
|
|
"CAP_MKNOD",
|
|
|
|
"CAP_NET_RAW",
|
|
|
|
"CAP_SETGID",
|
|
|
|
"CAP_SETUID",
|
|
|
|
"CAP_SETFCAP",
|
|
|
|
"CAP_SETPCAP",
|
|
|
|
"CAP_NET_BIND_SERVICE",
|
|
|
|
"CAP_SYS_CHROOT",
|
|
|
|
"CAP_KILL",
|
|
|
|
"CAP_AUDIT_WRITE",
|
2014-10-17 08:00:59 +08:00
|
|
|
},
|
2015-01-27 20:54:19 +08:00
|
|
|
Namespaces: configs.Namespaces([]configs.Namespace{
|
|
|
|
{Type: configs.NEWNS},
|
|
|
|
{Type: configs.NEWUTS},
|
|
|
|
{Type: configs.NEWIPC},
|
|
|
|
{Type: configs.NEWPID},
|
|
|
|
{Type: configs.NEWNET},
|
|
|
|
}),
|
2015-02-03 18:53:31 +08:00
|
|
|
Cgroups: &configs.Cgroup{
|
2015-12-15 08:26:29 +08:00
|
|
|
Name: "test",
|
|
|
|
Parent: "integration",
|
|
|
|
Resources: &configs.Resources{
|
|
|
|
MemorySwappiness: -1,
|
|
|
|
AllowAllDevices: false,
|
|
|
|
AllowedDevices: configs.DefaultAllowedDevices,
|
|
|
|
},
|
2014-10-17 08:00:59 +08:00
|
|
|
},
|
2015-02-13 08:23:05 +08:00
|
|
|
MaskPaths: []string{
|
|
|
|
"/proc/kcore",
|
|
|
|
},
|
|
|
|
ReadonlyPaths: []string{
|
|
|
|
"/proc/sys", "/proc/sysrq-trigger", "/proc/irq", "/proc/bus",
|
|
|
|
},
|
2015-02-07 11:16:11 +08:00
|
|
|
Devices: configs.DefaultAutoCreatedDevices,
|
|
|
|
Hostname: "integration",
|
2015-02-13 08:23:05 +08:00
|
|
|
Mounts: []*configs.Mount{
|
2015-03-18 02:09:33 +08:00
|
|
|
{
|
|
|
|
Source: "proc",
|
|
|
|
Destination: "/proc",
|
|
|
|
Device: "proc",
|
|
|
|
Flags: defaultMountFlags,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "tmpfs",
|
|
|
|
Destination: "/dev",
|
|
|
|
Device: "tmpfs",
|
|
|
|
Flags: syscall.MS_NOSUID | syscall.MS_STRICTATIME,
|
|
|
|
Data: "mode=755",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "devpts",
|
|
|
|
Destination: "/dev/pts",
|
|
|
|
Device: "devpts",
|
|
|
|
Flags: syscall.MS_NOSUID | syscall.MS_NOEXEC,
|
|
|
|
Data: "newinstance,ptmxmode=0666,mode=0620,gid=5",
|
|
|
|
},
|
2015-02-13 08:23:05 +08:00
|
|
|
{
|
|
|
|
Device: "tmpfs",
|
|
|
|
Source: "shm",
|
|
|
|
Destination: "/dev/shm",
|
|
|
|
Data: "mode=1777,size=65536k",
|
|
|
|
Flags: defaultMountFlags,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "mqueue",
|
|
|
|
Destination: "/dev/mqueue",
|
|
|
|
Device: "mqueue",
|
|
|
|
Flags: defaultMountFlags,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: "sysfs",
|
|
|
|
Destination: "/sys",
|
|
|
|
Device: "sysfs",
|
|
|
|
Flags: defaultMountFlags | syscall.MS_RDONLY,
|
|
|
|
},
|
|
|
|
},
|
2014-12-17 17:12:23 +08:00
|
|
|
Networks: []*configs.Network{
|
2014-10-17 08:00:59 +08:00
|
|
|
{
|
|
|
|
Type: "loopback",
|
|
|
|
Address: "127.0.0.1/0",
|
|
|
|
Gateway: "localhost",
|
|
|
|
},
|
|
|
|
},
|
2014-12-17 17:12:23 +08:00
|
|
|
Rlimits: []configs.Rlimit{
|
2014-11-27 02:16:53 +08:00
|
|
|
{
|
|
|
|
Type: syscall.RLIMIT_NOFILE,
|
2015-03-04 17:10:53 +08:00
|
|
|
Hard: uint64(1025),
|
|
|
|
Soft: uint64(1025),
|
2014-11-27 02:16:53 +08:00
|
|
|
},
|
|
|
|
},
|
2014-10-17 08:00:59 +08:00
|
|
|
}
|
|
|
|
}
|