github.com/stevegt/moby@v1.13.1/oci/defaults_linux.go (about) 1 package oci 2 3 import ( 4 "os" 5 "runtime" 6 7 "github.com/opencontainers/runtime-spec/specs-go" 8 ) 9 10 func sPtr(s string) *string { return &s } 11 func iPtr(i int64) *int64 { return &i } 12 func u32Ptr(i int64) *uint32 { u := uint32(i); return &u } 13 func fmPtr(i int64) *os.FileMode { fm := os.FileMode(i); return &fm } 14 15 // DefaultSpec returns default oci spec used by docker. 16 func DefaultSpec() specs.Spec { 17 s := specs.Spec{ 18 Version: specs.Version, 19 Platform: specs.Platform{ 20 OS: runtime.GOOS, 21 Arch: runtime.GOARCH, 22 }, 23 } 24 s.Mounts = []specs.Mount{ 25 { 26 Destination: "/proc", 27 Type: "proc", 28 Source: "proc", 29 Options: []string{"nosuid", "noexec", "nodev"}, 30 }, 31 { 32 Destination: "/dev", 33 Type: "tmpfs", 34 Source: "tmpfs", 35 Options: []string{"nosuid", "strictatime", "mode=755"}, 36 }, 37 { 38 Destination: "/dev/pts", 39 Type: "devpts", 40 Source: "devpts", 41 Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"}, 42 }, 43 { 44 Destination: "/sys", 45 Type: "sysfs", 46 Source: "sysfs", 47 Options: []string{"nosuid", "noexec", "nodev", "ro"}, 48 }, 49 { 50 Destination: "/sys/fs/cgroup", 51 Type: "cgroup", 52 Source: "cgroup", 53 Options: []string{"ro", "nosuid", "noexec", "nodev"}, 54 }, 55 { 56 Destination: "/dev/mqueue", 57 Type: "mqueue", 58 Source: "mqueue", 59 Options: []string{"nosuid", "noexec", "nodev"}, 60 }, 61 } 62 s.Process.Capabilities = []string{ 63 "CAP_CHOWN", 64 "CAP_DAC_OVERRIDE", 65 "CAP_FSETID", 66 "CAP_FOWNER", 67 "CAP_MKNOD", 68 "CAP_NET_RAW", 69 "CAP_SETGID", 70 "CAP_SETUID", 71 "CAP_SETFCAP", 72 "CAP_SETPCAP", 73 "CAP_NET_BIND_SERVICE", 74 "CAP_SYS_CHROOT", 75 "CAP_KILL", 76 "CAP_AUDIT_WRITE", 77 } 78 79 s.Linux = &specs.Linux{ 80 MaskedPaths: []string{ 81 "/proc/kcore", 82 "/proc/latency_stats", 83 "/proc/timer_list", 84 "/proc/timer_stats", 85 "/proc/sched_debug", 86 "/sys/firmware", 87 }, 88 ReadonlyPaths: []string{ 89 "/proc/asound", 90 "/proc/bus", 91 "/proc/fs", 92 "/proc/irq", 93 "/proc/sys", 94 "/proc/sysrq-trigger", 95 }, 96 Namespaces: []specs.Namespace{ 97 {Type: "mount"}, 98 {Type: "network"}, 99 {Type: "uts"}, 100 {Type: "pid"}, 101 {Type: "ipc"}, 102 }, 103 // Devices implicitly contains the following devices: 104 // null, zero, full, random, urandom, tty, console, and ptmx. 105 // ptmx is a bind-mount or symlink of the container's ptmx. 106 // See also: https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#default-devices 107 Devices: []specs.Device{}, 108 Resources: &specs.Resources{ 109 Devices: []specs.DeviceCgroup{ 110 { 111 Allow: false, 112 Access: sPtr("rwm"), 113 }, 114 { 115 Allow: true, 116 Type: sPtr("c"), 117 Major: iPtr(1), 118 Minor: iPtr(5), 119 Access: sPtr("rwm"), 120 }, 121 { 122 Allow: true, 123 Type: sPtr("c"), 124 Major: iPtr(1), 125 Minor: iPtr(3), 126 Access: sPtr("rwm"), 127 }, 128 { 129 Allow: true, 130 Type: sPtr("c"), 131 Major: iPtr(1), 132 Minor: iPtr(9), 133 Access: sPtr("rwm"), 134 }, 135 { 136 Allow: true, 137 Type: sPtr("c"), 138 Major: iPtr(1), 139 Minor: iPtr(8), 140 Access: sPtr("rwm"), 141 }, 142 { 143 Allow: true, 144 Type: sPtr("c"), 145 Major: iPtr(5), 146 Minor: iPtr(0), 147 Access: sPtr("rwm"), 148 }, 149 { 150 Allow: true, 151 Type: sPtr("c"), 152 Major: iPtr(5), 153 Minor: iPtr(1), 154 Access: sPtr("rwm"), 155 }, 156 { 157 Allow: false, 158 Type: sPtr("c"), 159 Major: iPtr(10), 160 Minor: iPtr(229), 161 Access: sPtr("rwm"), 162 }, 163 }, 164 }, 165 } 166 167 return s 168 }