This command searches the audit logs for the word passwd and then sends it to the audit2allow command and this builds a new security policy module. This allows the action to succeed.
semodule -X 300 -i my-passwd.pp
The security module is then inserted into the security policy and the action no longer fails.
Creating a new security policy is a last resort, as messing around with Security Policies can be complex.
AVC Denial Message:
Going through the above errors, we find AVC, which is Access Vector Cache. This tells us its an SELinux error.
We can see what was denied, which in this case was { create } for pid=202425. The command name is passwd. The context of the subject is passwd_t and the context of the object is etc_t
The second message has a security context of USER_CHAUTHTOK (Change, Auth, Token). The same process ID of pid=202425 is shown. The subject type is passwd_t again and the error message starts from msg=op'.
The operation was a PAM –> Pluggable Authentication Module that was trying to change the authentication token. It was ran by the user1 account. The command executed was /usr/bin/passwd. The host was rhhost1 and it was on a pts/2 terminal. The result was res=failed.
SELinux Solutions:
Change a boolean to allow an action to happen.
Booleans are easy to look for and you can use the sudo semanage boolean -l command to view them.
This then gives you a short description.
Service configuration files will often have comments in them.
To change the boolean, we use:
sudo setsebool -P <boolean> on
Can change a file’s type or directory.
Can use chcon or semanage
Context can be incorrect, if files are not copied correctly.
Using the chcon command, we can modify the context appropriately.
These changes only last until an admin performs a restorecon or a system-wide relabel occurs.
Use semanage to change the file’s context in the security database. This makes the change persistent.
Then use restorecon to change the context of the file.
A real-world example is if you want to place a MySQL DB into a non-standard location.
You would need to update the Security Context for the MySQL DB’s directory in the policy. Then run restorecon on the directory and files.
The last resort is to create a Security Policy Module.
We are modifying the policy, to allow something, when originally it was being denied.
It is better to find out why it was being denied first and then fix it.
In Summary with how to Troubleshoot SELinux Issues
Put SELinux into Permissive Mode.
Allows the application to run all the way through, generating all errors.
Run the application that was denied.
Search through the audit logs.
Look for SELinux Desktop Notifications.
Follow instructions in the SELinux Alert Browser.
Finally, to restore the context of the etc/shadow file, we can run sudo restorecon /etc/shadow
*