defaults_linux.go 3.6 KB

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