SELinux policies and rpm distribution best practice
Apologies in advance if this has been answered or there is an obvious reference I can use, but I have been digging through piles of SELinux documentation dating back (up to) several years and I am yet to find a Red Hat 'best practice' for packaging SELinux policy files for custom deployed applications via rpm.
The documentation I have found appears to be on one of two topics (but I can't find much else):
- SELinux introduction, -> explain how it works, why it isn't scary and why you shouldn't turn it off.
- How to write an SELinux policy -> run your app, run audit2allow, update policy, repeat
The document I am interested in (if it exists) is:
How to include a custom SELinux module in your rpm for your custom application, including:
- Where the module should be deployed (directory structure), in which format and how the SELinux system should be notified of its addition (rpm post scripts?)
- How file contexts for files should be defined / deployed (ie. in a file defining file contexts, calling semanage?)
- How other resources should be defined
- What clean up tasks should be carried out when removing the rpm to ensure unnecessary defined types/policies don't 'hang around' on the system
I think an example rpm that does the above 'the Red Hat way' would be a great start if anyone can suggest an example package to reference. I would also be interested in any rpm 'boiler plate' code specifically related to SELinux that people can provide (ie. installation/cleanup scripts for pre/post).
Also interested to know where the SELinux training course went (RH429/EX429/RHCSS) and will it be returning? Is there any chance of the lab material from this course being opened up for wider consumption if the course has been cancelled for good?
Thanks!
Responses
Great questions. Some of which I had not considered (I guess I hope my environment does not require custom policies ;-)
Thomas Cameron always does a great job presenting topics and SElinux is no exception. It is likely not the depth you are looking for, but I'll leave this here for others:
http://people.redhat.com/tcameron/Summit2014/cameron_w_340_selinux_for_mere_mortals/cameron_w_340_selinux_for_mere_mortals.pdf
One item I was pondering after reading your questions was the contexts:
/etc/selinux/targeted/contexts/files/
I wonder if that directory structure is essentially static and any custom policy/context that you create is stored elsewhere (similar to the approach where /etc/security/limits.d/* files are applied after /etc/security/limits.conf)
I hope you get some momentum on this discussion.
This works for me (http://sourceforge.net/projects/sysconfcollect/):
The context of the web content is set and activated in the postinstall:
/usr/sbin/semanage fcontext --add --type httpd_sys_content_t "${SCC_WWW}(/.*)?"
/sbin/restorecon -R ${SCC_WWW}
The context is removed from the system in the preremove:
echo "fcontext -d ${SCC_WWW}(/.*)?" |
/usr/sbin/semanage -i - 2>/dev/null
PixelDrift,
Just one immediate note from me; Make sure any atypical selinux contexts you care about are cited/added into /etc/selinux/targeted/contexts/files/file_contexts .
If you are using MLS SELinux (and not targeted as the path above shows) then the location for 'file_contexts" I believe is different. We have some unique MLS SELinux systems and a unique path leading to our own file_contexts" file which differs from the above and I believe from a typical MLS SELinux system.
The importance of that: if for some reason you must relabel your file system, (this is important), if your atypical (and important) file contexts -are- -not- -in- -that- -file- then when you relabel, those files will receive a different file context and could have ... "Negative Consequences" (Understatement™).
If someone has to go into the rescue mode and reset a password, bingo, your SELinux system will suffer a full relabeling. I know of one procedure around this but I do not publish this 'at all|publically'.
I'll check some resources I have regarding documentation... just wanted to share the above for any atypical files etc that you have a custom label.
Good points Pixeldrift,
In the case I mentioned though, I was speaking about atypical files that for whatever reason are not in the file_contexts file (or other such file), yet are needed. This occurred in our case with a system we inherited. The previous owners or those who delivered the software had an apparent oversight. In that case, the file was not properly relabeled when we had to relabel the file system, and caused issues for a process. We fixed the issue by adding it after discovering this to the proper file_contexts file to avert this from occurring again.
I will check my notes later this week (busy with some things right now) on your bits above.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
