securitycontext.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package pod
  15. import "yunion.io/x/onecloud/pkg/apis"
  16. // https://github.com/kubernetes/kubernetes/blob/release-1.26/pkg/securitycontext/util.go#L213-L236
  17. var (
  18. // These *must* be kept in sync with moby/moby.
  19. // https://github.com/moby/moby/blob/master/oci/defaults.go#L116-L134
  20. // @jessfraz will watch changes to those files upstream.
  21. defaultMaskedPaths = []string{
  22. "/proc/acpi",
  23. "/proc/kcore",
  24. "/proc/keys",
  25. "/proc/latency_stats",
  26. "/proc/timer_list",
  27. "/proc/timer_stats",
  28. "/proc/sched_debug",
  29. "/proc/scsi",
  30. "/sys/firmware",
  31. }
  32. defaultReadonlyPaths = []string{
  33. "/proc/asound",
  34. "/proc/bus",
  35. "/proc/fs",
  36. "/proc/irq",
  37. "/proc/sys",
  38. "/proc/sysrq-trigger",
  39. }
  40. )
  41. func GetDefaultMaskedPaths(unmasks apis.ContainerProcMountType) []string {
  42. if unmasks == apis.ContainerUnmaskedProcMount {
  43. return []string{}
  44. }
  45. return defaultMaskedPaths
  46. }
  47. func GetReadonlyPaths(unmasks apis.ContainerProcMountType) []string {
  48. if unmasks == apis.ContainerUnmaskedProcMount {
  49. return []string{}
  50. }
  51. return defaultReadonlyPaths
  52. }