defaults_linux.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package oci
  2. import (
  3. "os"
  4. "runtime"
  5. "github.com/opencontainers/runtime-spec/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_list",
  79. "/proc/timer_stats",
  80. "/proc/sched_debug",
  81. "/sys/firmware",
  82. },
  83. ReadonlyPaths: []string{
  84. "/proc/asound",
  85. "/proc/bus",
  86. "/proc/fs",
  87. "/proc/irq",
  88. "/proc/sys",
  89. "/proc/sysrq-trigger",
  90. },
  91. Namespaces: []specs.Namespace{
  92. {Type: "mount"},
  93. {Type: "network"},
  94. {Type: "uts"},
  95. {Type: "pid"},
  96. {Type: "ipc"},
  97. },
  98. // Devices implicitly contains the following devices:
  99. // null, zero, full, random, urandom, tty, console, and ptmx.
  100. // ptmx is a bind-mount or symlink of the container's ptmx.
  101. // See also: https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#default-devices
  102. Devices: []specs.Device{},
  103. Resources: &specs.Resources{
  104. Devices: []specs.DeviceCgroup{
  105. {
  106. Allow: false,
  107. Access: sPtr("rwm"),
  108. },
  109. {
  110. Allow: true,
  111. Type: sPtr("c"),
  112. Major: iPtr(1),
  113. Minor: iPtr(5),
  114. Access: sPtr("rwm"),
  115. },
  116. {
  117. Allow: true,
  118. Type: sPtr("c"),
  119. Major: iPtr(1),
  120. Minor: iPtr(3),
  121. Access: sPtr("rwm"),
  122. },
  123. {
  124. Allow: true,
  125. Type: sPtr("c"),
  126. Major: iPtr(1),
  127. Minor: iPtr(9),
  128. Access: sPtr("rwm"),
  129. },
  130. {
  131. Allow: true,
  132. Type: sPtr("c"),
  133. Major: iPtr(1),
  134. Minor: iPtr(8),
  135. Access: sPtr("rwm"),
  136. },
  137. {
  138. Allow: true,
  139. Type: sPtr("c"),
  140. Major: iPtr(5),
  141. Minor: iPtr(0),
  142. Access: sPtr("rwm"),
  143. },
  144. {
  145. Allow: true,
  146. Type: sPtr("c"),
  147. Major: iPtr(5),
  148. Minor: iPtr(1),
  149. Access: sPtr("rwm"),
  150. },
  151. {
  152. Allow: false,
  153. Type: sPtr("c"),
  154. Major: iPtr(10),
  155. Minor: iPtr(229),
  156. Access: sPtr("rwm"),
  157. },
  158. },
  159. },
  160. }
  161. return s
  162. }