Documentation
¶
Overview ¶
Package selinux provides generic code for managing SELinux.
Index ¶
- Variables
- func FGetLabel(root xfs.Root, filename string) (string, error)
- func FSetLabel(root xfs.Root, filename string, label string, excludeLabels ...string) error
- func GetLabel(filename string) (string, error)
- func Init() error
- func SetLabel(filename string, label string, excludeLabels ...string) error
- func SetLabelRecursive(dir string, label string, excludeLabels ...string) error
Constants ¶
This section is empty.
Variables ¶
var IsEnabled = sync.OnceValue(func() bool { if containermode.InContainer() { return false } val := procfs.ProcCmdline().Get(constants.KernelParamSELinux).First() var selinuxFSPresent bool if _, err := os.Stat("/sys/fs/selinux"); err == nil { selinuxFSPresent = true } return val != nil && *val == "1" && selinuxFSPresent })
IsEnabled checks if SELinux is enabled on the system by reading the kernel command line. It returns true if SELinux is enabled, otherwise it returns false. It also ensures we're not in a container. By default SELinux is disabled.
var IsEnforcing = sync.OnceValue(func() bool { if !IsEnabled() { return false } val := procfs.ProcCmdline().Get(constants.KernelParamSELinuxEnforcing).First() return val != nil && *val == "1" })
IsEnforcing checks if SELinux is enabled and the mode should be enforcing. By default if SELinux is enabled we consider it to be permissive.
Functions ¶
func FGetLabel ¶
FGetLabel gets label for file, directory or symlink (not following symlinks) using provided root. It does not perform the operation in case SELinux is disabled.
func FSetLabel ¶
FSetLabel sets label for file, directory or symlink (not following symlinks) using provided root. It does not perform the operation in case SELinux is disabled, provided label is empty or already set.
func GetLabel ¶
GetLabel gets label for file, directory or symlink (not following symlinks) It does not perform the operation in case SELinux is disabled.
func Init ¶
func Init() error
Init initializes SELinux based on the configured mode. It loads the policy and enforces it if necessary.
Types ¶
This section is empty.