123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package oci
- import (
- "os"
- "runtime"
- "github.com/opencontainers/runtime-spec/specs-go"
- )
- func iPtr(i int64) *int64 { return &i }
- func u32Ptr(i int64) *uint32 { u := uint32(i); return &u }
- func fmPtr(i int64) *os.FileMode { fm := os.FileMode(i); return &fm }
- func defaultCapabilities() []string {
- return []string{
- "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",
- }
- }
- // DefaultSpec returns default oci spec used by docker.
- func DefaultSpec() specs.Spec {
- s := specs.Spec{
- Version: specs.Version,
- Platform: specs.Platform{
- OS: runtime.GOOS,
- Arch: runtime.GOARCH,
- },
- }
- s.Mounts = []specs.Mount{
- {
- Destination: "/proc",
- Type: "proc",
- Source: "proc",
- Options: []string{"nosuid", "noexec", "nodev"},
- },
- {
- Destination: "/dev",
- Type: "tmpfs",
- Source: "tmpfs",
- Options: []string{"nosuid", "strictatime", "mode=755"},
- },
- {
- Destination: "/dev/pts",
- Type: "devpts",
- Source: "devpts",
- Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"},
- },
- {
- Destination: "/sys",
- Type: "sysfs",
- Source: "sysfs",
- Options: []string{"nosuid", "noexec", "nodev", "ro"},
- },
- {
- Destination: "/sys/fs/cgroup",
- Type: "cgroup",
- Source: "cgroup",
- Options: []string{"ro", "nosuid", "noexec", "nodev"},
- },
- {
- Destination: "/dev/mqueue",
- Type: "mqueue",
- Source: "mqueue",
- Options: []string{"nosuid", "noexec", "nodev"},
- },
- }
- s.Process.Capabilities = &specs.LinuxCapabilities{
- Bounding: defaultCapabilities(),
- Permitted: defaultCapabilities(),
- Inheritable: defaultCapabilities(),
- Effective: defaultCapabilities(),
- }
- s.Linux = &specs.Linux{
- MaskedPaths: []string{
- "/proc/kcore",
- "/proc/latency_stats",
- "/proc/timer_list",
- "/proc/timer_stats",
- "/proc/sched_debug",
- "/sys/firmware",
- },
- ReadonlyPaths: []string{
- "/proc/asound",
- "/proc/bus",
- "/proc/fs",
- "/proc/irq",
- "/proc/sys",
- "/proc/sysrq-trigger",
- },
- Namespaces: []specs.LinuxNamespace{
- {Type: "mount"},
- {Type: "network"},
- {Type: "uts"},
- {Type: "pid"},
- {Type: "ipc"},
- },
- // Devices implicitly contains the following devices:
- // null, zero, full, random, urandom, tty, console, and ptmx.
- // ptmx is a bind-mount or symlink of the container's ptmx.
- // See also: https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#default-devices
- Devices: []specs.LinuxDevice{},
- Resources: &specs.LinuxResources{
- Devices: []specs.LinuxDeviceCgroup{
- {
- Allow: false,
- Access: "rwm",
- },
- {
- Allow: true,
- Type: "c",
- Major: iPtr(1),
- Minor: iPtr(5),
- Access: "rwm",
- },
- {
- Allow: true,
- Type: "c",
- Major: iPtr(1),
- Minor: iPtr(3),
- Access: "rwm",
- },
- {
- Allow: true,
- Type: "c",
- Major: iPtr(1),
- Minor: iPtr(9),
- Access: "rwm",
- },
- {
- Allow: true,
- Type: "c",
- Major: iPtr(1),
- Minor: iPtr(8),
- Access: "rwm",
- },
- {
- Allow: true,
- Type: "c",
- Major: iPtr(5),
- Minor: iPtr(0),
- Access: "rwm",
- },
- {
- Allow: true,
- Type: "c",
- Major: iPtr(5),
- Minor: iPtr(1),
- Access: "rwm",
- },
- {
- Allow: false,
- Type: "c",
- Major: iPtr(10),
- Minor: iPtr(229),
- Access: "rwm",
- },
- },
- },
- }
- return s
- }
|