Skip to content

unix_selinux

Andrea Paolini edited this page Dec 15, 2022 · 3 revisions

SELinux cheatsheet

List policy modules

semodule --list-modules=full

Generate new policy modules

Look at /var/log/audit/audit.log . Are you getting any deny?

grep " denied " /var/log/audit/audit.log

Based on audit.log, you can generate the rules for a custom policy modules.

See why it is failing:

grep "mydaemon" /var/log/audit/audit.log | audit2why

See the proposed rules:

grep "mydaemon" /var/log/audit/audit.log | audit2allow -m my-daemon

Does it seem OK? Generate the module. If you prefix your custom rules with "my-" those will be easier to find.

grep "mydaemon" /var/log/audit/audit.log | audit2allow -M my-daemon

This will generate a my-daemon.pp and a my-daemon.te files

Install the new module with priority 300

semodule -X 300 -i my-daemon.pp

Now you can remove the *.te and the *.pp file

Install a policy module from a .te file

If you have the module file in text format in ''my-daemon.te'' :

checkmodule -M -m -o my-daemon.mod my-daemon.te
semodule_package -o my-daemon.pp -m my-daemon.mod
semodule -X 300 -i my-daemon.pp
rm my-daemon.mod  my-daemon.pp  my-daemon.te

Restore

Restore labels for a file

restorecon -v myfile

Relabel filesystem

touch /.autorelabel and reboot

Clone this wiki locally