label.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package label
  2. import (
  3. "fmt"
  4. "github.com/opencontainers/selinux/go-selinux"
  5. )
  6. // Deprecated: use selinux.ROFileLabel
  7. var ROMountLabel = selinux.ROFileLabel
  8. // SetProcessLabel takes a process label and tells the kernel to assign the
  9. // label to the next program executed by the current process.
  10. // Deprecated: use selinux.SetExecLabel
  11. var SetProcessLabel = selinux.SetExecLabel
  12. // ProcessLabel returns the process label that the kernel will assign
  13. // to the next program executed by the current process. If "" is returned
  14. // this indicates that the default labeling will happen for the process.
  15. // Deprecated: use selinux.ExecLabel
  16. var ProcessLabel = selinux.ExecLabel
  17. // SetSocketLabel takes a process label and tells the kernel to assign the
  18. // label to the next socket that gets created
  19. // Deprecated: use selinux.SetSocketLabel
  20. var SetSocketLabel = selinux.SetSocketLabel
  21. // SocketLabel retrieves the current default socket label setting
  22. // Deprecated: use selinux.SocketLabel
  23. var SocketLabel = selinux.SocketLabel
  24. // SetKeyLabel takes a process label and tells the kernel to assign the
  25. // label to the next kernel keyring that gets created
  26. // Deprecated: use selinux.SetKeyLabel
  27. var SetKeyLabel = selinux.SetKeyLabel
  28. // KeyLabel retrieves the current default kernel keyring label setting
  29. // Deprecated: use selinux.KeyLabel
  30. var KeyLabel = selinux.KeyLabel
  31. // FileLabel returns the label for specified path
  32. // Deprecated: use selinux.FileLabel
  33. var FileLabel = selinux.FileLabel
  34. // PidLabel will return the label of the process running with the specified pid
  35. // Deprecated: use selinux.PidLabel
  36. var PidLabel = selinux.PidLabel
  37. // Init initialises the labeling system
  38. func Init() {
  39. _ = selinux.GetEnabled()
  40. }
  41. // ClearLabels will clear all reserved labels
  42. // Deprecated: use selinux.ClearLabels
  43. var ClearLabels = selinux.ClearLabels
  44. // ReserveLabel will record the fact that the MCS label has already been used.
  45. // This will prevent InitLabels from using the MCS label in a newly created
  46. // container
  47. // Deprecated: use selinux.ReserveLabel
  48. func ReserveLabel(label string) error {
  49. selinux.ReserveLabel(label)
  50. return nil
  51. }
  52. // ReleaseLabel will remove the reservation of the MCS label.
  53. // This will allow InitLabels to use the MCS label in a newly created
  54. // containers
  55. // Deprecated: use selinux.ReleaseLabel
  56. func ReleaseLabel(label string) error {
  57. selinux.ReleaseLabel(label)
  58. return nil
  59. }
  60. // DupSecOpt takes a process label and returns security options that
  61. // can be used to set duplicate labels on future container processes
  62. // Deprecated: use selinux.DupSecOpt
  63. var DupSecOpt = selinux.DupSecOpt
  64. // FormatMountLabel returns a string to be used by the mount command.
  65. // The format of this string will be used to alter the labeling of the mountpoint.
  66. // The string returned is suitable to be used as the options field of the mount command.
  67. // If you need to have additional mount point options, you can pass them in as
  68. // the first parameter. Second parameter is the label that you wish to apply
  69. // to all content in the mount point.
  70. func FormatMountLabel(src, mountLabel string) string {
  71. if mountLabel != "" {
  72. switch src {
  73. case "":
  74. src = fmt.Sprintf("context=%q", mountLabel)
  75. default:
  76. src = fmt.Sprintf("%s,context=%q", src, mountLabel)
  77. }
  78. }
  79. return src
  80. }