SELinux file context expressions
When we think that the context of a file is wrong, we need to correct the context. SELinux offers several methods to do so, and some distributions even add in more. We can use tools such as chcon
, restorecon
(together with semanage
), setfiles
, rlpkg
(Gentoo), and fixfiles
. Of course, we could also use the setfattr
command, but that would be the least user-friendly approach for setting contexts.
Let's see how we can set context expressions in a more manageable way.
Using context expressions
In the SELinux policy, a list of regular expressions is kept that informs the SELinux utilities and libraries what the context of a file (or other filesystem resource) should be. Though this expression list is not enforced on the system directly, administrators and SELinux utilities use it to see whether a context is correct, and to reset contexts to what they are supposed to be. You can find the list itself in /etc/selinux/targeted/contexts/files
in...