defaults.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. const defaultUnixPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  9. // DefaultPathEnv is unix style list of directories to search for
  10. // executables. Each directory is separated from the next by a colon
  11. // ':' character .
  12. // For Windows containers, an empty string is returned as the default
  13. // path will be set by the container, and Docker has no context of what the
  14. // default path should be.
  15. //
  16. // TODO(thaJeztah) align Windows default with BuildKit; see https://github.com/moby/buildkit/pull/1747
  17. // TODO(thaJeztah) use defaults from containerd (but align it with BuildKit; see https://github.com/moby/buildkit/pull/1747)
  18. func DefaultPathEnv(os string) string {
  19. if os == "windows" {
  20. return ""
  21. }
  22. return defaultUnixPathEnv
  23. }
  24. // DefaultSpec returns the default spec used by docker for the current Platform
  25. func DefaultSpec() specs.Spec {
  26. if runtime.GOOS == "windows" {
  27. return DefaultWindowsSpec()
  28. }
  29. return DefaultLinuxSpec()
  30. }
  31. // DefaultWindowsSpec create a default spec for running Windows containers
  32. func DefaultWindowsSpec() specs.Spec {
  33. return specs.Spec{
  34. Version: specs.Version,
  35. Windows: &specs.Windows{},
  36. Process: &specs.Process{},
  37. Root: &specs.Root{},
  38. }
  39. }
  40. // DefaultLinuxSpec create a default spec for running Linux containers
  41. func DefaultLinuxSpec() specs.Spec {
  42. return specs.Spec{
  43. Version: specs.Version,
  44. Process: &specs.Process{
  45. Capabilities: &specs.LinuxCapabilities{
  46. Bounding: caps.DefaultCapabilities(),
  47. Permitted: caps.DefaultCapabilities(),
  48. Effective: caps.DefaultCapabilities(),
  49. },
  50. },
  51. Root: &specs.Root{},
  52. Mounts: []specs.Mount{
  53. {
  54. Destination: "/proc",
  55. Type: "proc",
  56. Source: "proc",
  57. Options: []string{"nosuid", "noexec", "nodev"},
  58. },
  59. {
  60. Destination: "/dev",
  61. Type: "tmpfs",
  62. Source: "tmpfs",
  63. Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"},
  64. },
  65. {
  66. Destination: "/dev/pts",
  67. Type: "devpts",
  68. Source: "devpts",
  69. Options: []string{"nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620", "gid=5"},
  70. },
  71. {
  72. Destination: "/sys",
  73. Type: "sysfs",
  74. Source: "sysfs",
  75. Options: []string{"nosuid", "noexec", "nodev", "ro"},
  76. },
  77. {
  78. Destination: "/sys/fs/cgroup",
  79. Type: "cgroup",
  80. Source: "cgroup",
  81. Options: []string{"ro", "nosuid", "noexec", "nodev"},
  82. },
  83. {
  84. Destination: "/dev/mqueue",
  85. Type: "mqueue",
  86. Source: "mqueue",
  87. Options: []string{"nosuid", "noexec", "nodev"},
  88. },
  89. {
  90. Destination: "/dev/shm",
  91. Type: "tmpfs",
  92. Source: "shm",
  93. Options: []string{"nosuid", "noexec", "nodev", "mode=1777"},
  94. },
  95. },
  96. Linux: &specs.Linux{
  97. MaskedPaths: []string{
  98. "/proc/asound",
  99. "/proc/acpi",
  100. "/proc/kcore",
  101. "/proc/keys",
  102. "/proc/latency_stats",
  103. "/proc/timer_list",
  104. "/proc/timer_stats",
  105. "/proc/sched_debug",
  106. "/proc/scsi",
  107. "/sys/firmware",
  108. "/sys/devices/virtual/powercap",
  109. },
  110. ReadonlyPaths: []string{
  111. "/proc/bus",
  112. "/proc/fs",
  113. "/proc/irq",
  114. "/proc/sys",
  115. "/proc/sysrq-trigger",
  116. },
  117. Namespaces: []specs.LinuxNamespace{
  118. {Type: specs.MountNamespace},
  119. {Type: specs.NetworkNamespace},
  120. {Type: specs.UTSNamespace},
  121. {Type: specs.PIDNamespace},
  122. {Type: specs.IPCNamespace},
  123. },
  124. // Devices implicitly contains the following devices:
  125. // null, zero, full, random, urandom, tty, console, and ptmx.
  126. // ptmx is a bind mount or symlink of the container's ptmx.
  127. // See also: https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#default-devices
  128. Devices: []specs.LinuxDevice{},
  129. Resources: &specs.LinuxResources{
  130. Devices: []specs.LinuxDeviceCgroup{
  131. {
  132. Allow: false,
  133. Access: "rwm",
  134. },
  135. {
  136. Allow: true,
  137. Type: "c",
  138. Major: iPtr(1),
  139. Minor: iPtr(5),
  140. Access: "rwm",
  141. },
  142. {
  143. Allow: true,
  144. Type: "c",
  145. Major: iPtr(1),
  146. Minor: iPtr(3),
  147. Access: "rwm",
  148. },
  149. {
  150. Allow: true,
  151. Type: "c",
  152. Major: iPtr(1),
  153. Minor: iPtr(9),
  154. Access: "rwm",
  155. },
  156. {
  157. Allow: true,
  158. Type: "c",
  159. Major: iPtr(1),
  160. Minor: iPtr(8),
  161. Access: "rwm",
  162. },
  163. {
  164. Allow: true,
  165. Type: "c",
  166. Major: iPtr(5),
  167. Minor: iPtr(0),
  168. Access: "rwm",
  169. },
  170. {
  171. Allow: true,
  172. Type: "c",
  173. Major: iPtr(5),
  174. Minor: iPtr(1),
  175. Access: "rwm",
  176. },
  177. {
  178. Allow: false,
  179. Type: "c",
  180. Major: iPtr(10),
  181. Minor: iPtr(229),
  182. Access: "rwm",
  183. },
  184. },
  185. },
  186. },
  187. }
  188. }