selinux.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package selinux
  14. // Note: the libcontainer SELinux package is only built for Linux, so it is
  15. // necessary to have a NOP wrapper which is built for non-Linux platforms to
  16. // allow code that links to this package not to differentiate its own methods
  17. // for Linux and non-Linux platforms.
  18. //
  19. // SELinuxRunner wraps certain libcontainer SELinux calls. For more
  20. // information, see:
  21. //
  22. // https://github.com/opencontainers/runc/blob/master/libcontainer/selinux/selinux.go
  23. type SELinuxRunner interface {
  24. // Getfilecon returns the SELinux context for the given path or returns an
  25. // error.
  26. Getfilecon(path string) (string, error)
  27. }
  28. // NewSELinuxRunner returns a new SELinuxRunner appropriate for the platform.
  29. // On Linux, all methods short-circuit and return NOP values if SELinux is
  30. // disabled. On non-Linux platforms, a NOP implementation is returned.
  31. func NewSELinuxRunner() SELinuxRunner {
  32. return &realSELinuxRunner{}
  33. }