I’m not an SELinux expert, but when I read many tutorials on the subject and saw dozens of tips that all said in one voice: turn off SELinux, because it causes problems, I thought it was time to challenge this thesis and prove that SELinux could be easy to use.
In a situation where a service does not run because of problems with permissions, creating a process ID (PID) file, you should update SELinux’s policy on enforcing the rules against the application, which by default is not included in SELinux’s Type Enforcement (TE) policies.
A known fact about SELinux: „The target policy of SELinux of Fedora is currently distributed as 1271 files containing 118815 configuration lines. The recommended practice is not to change these files, but rather to add more configurations to change the behavior of SELinux.”
First of all, you need the audit2why tool to explain what has been blocked and why.
To check in CentOS, Red Hat, whether Fedora, what package it provides, follow the command:
|
|
You need to install the policycoreutils-python package (and dependencies):
CentOS 7 section
|
|
CentOS 8 section
|
|
Subsequently, perform the audit using the audit2why tool and the audit log:
|
|
A corresponding message will be displayed, which contains, for example, this information:
|
|
A little hint about the first two lines:
|
|
The source and target contexts are identical, so it seems to me that the command should be allowed to work. But let’s try audit2allow and see what it says:
|
|
It’s not clear to me what the first rule allows: does it allow naked (nagios_t) access to all initrc_var_run_t files? If so, it’s probably too high a level of permission. As the man page warns:
Care must be exercised while acting on the output of this utility to
ensure that the operations being permitted do not pose a security
threat. Often it is better to define new domains and/or types, or make
other structural changes to narrowly allow an optimal set of operations
to succeed, as opposed to blindly implementing the sometimes broad
changes recommended by this utility.
In Free Translation: Be careful and know how the program behaves and whether the allowed output operations do not pose a threat. It is often better to define new domains and/or types, or to create other structural changes that allow only a limited set of operations that will allow the application to run, than to blindly implement too high a level of permissions recommended by the audit2allow tool.
Pretty unfriendly behavior. Although if the alternative is to completely disable SELinux, too much power implemented in the SELinux policy is not the worst thing in the world.
So audit2allow provided some rules. What now? Fortunately, the audit2why and audit2allow man pages contain details on how to incorporate the principles into the SELinux policy. First of all, you should generate a new type of policy:
|
|
This includes some additional information in addition to the default output:
|
|
The next page of the man says about:
|
|
But my system didn’t have a directory /usr/share/selinux/devel:
|
|
I had to install the policycoreutils-devel package and dependencies.
|
|
Now compile a policy file to a binary file:
|
|
Then install the policy from the pp file that was previously generated using the make -f command. I use the semodule tool.
|
|
Did it solve the problem?
|
|
It worked! The licensing issues were resolved without resorting to the exclusion of SELinux. Every problem of this type in SELinux can be solved by analogy. At the very end it is worth to install the sealert tool:
|
|
And check the status of alerts with a command:
|
|