LPIC-3 333.2: Mandatory access control
SELinux on a web server: a non-standard port and directory, the trouble
with mv, a boolean, a permissive domain, a policy module, and a confined
user.
Before you start
SELinux must be enforcing. The lab creates the user confined (password
Lab-Pass-1) for task 5. Work as root; keep the policy module files of
task 4 in /root/selinux.
Tasks
- Install Apache (
httpd),policycoreutils-python-utilsandsetools-console. Make Apache serve/srv/webon port 8089, with anindex.htmlthat sayshello from /srv/web, starting at boot, with SELinux enforcing. Fix each denial the narrow way: label the one port, and add a file-context rule for/srv/webthat survivesrestorecon. - Create a page
moved.htmlthat saysmoved pagein your home directory andmvit into/srv/web. See it fail and why, then fix its label so that Apache serves it. - Put a CGI script
/var/www/cgi-bin/lab.shthat printsCGI running asand its SELinux context (id -Z), and make it work athttp://127.0.0.1/cgi-bin/lab.sh. Turn thehttpd_enable_cgiboolean off for a moment and see it fail, then leave it on. - Make
/srv/web/secret.txtwith the typeadmin_home_tand see that Apache can't read it. Makehttpd_ta permissive domain, fetch it again, and build a policy modulelabwebfrom the logged denials withaudit2allowin/root/selinux. Install it, fetch the file, then remove the module and the permissive domain again, so that the file is refused once more. - Map
confinedto the SELinux useruser_u, and log in asconfined(with a key, over SSH) to see the context the session gets.
Hints
sestatus,id -Z,ls -Z,ps -eZ;ausearch -m AVC -ts recent,audit2why.semanage port -a -t http_port_t -p tcp 8089;semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?",restorecon -Rv,matchpathcon,semanage fcontext -l -C.restorecon -v FILE;curl -s -o /dev/null -w '%{http_code}\n' URL.getsebool,setsebool(with-Pit lasts),semanage boolean -l.chcon -t admin_home_t;semanage permissive -a httpd_tand-d;ausearch -m AVC -ts recent -f secret.txt | audit2allow -M labweb;semodule -i labweb.pp,semodule -l,semodule -r labweb.semanage login -a -s user_u confined,semanage login -l;ssh-keygen, the user's~/.ssh/authorized_keys,restorecon -R.