defaults.go 4.0 KB

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