2.1 KiB
2.1 KiB
EX294 9.7: Security
Serve a web page from an unusual directory and port with SELinux enforcing, using the SELinux modules: a file context rule and a relabel, a boolean and a port label.
Before you start
SELinux doesn't work inside the lab's managed-node containers, so this
VM, the control node, is also the web server: localhost ansible_connection=local, in the inventory group webservers. The lab
creates the user greg (password Lab-Pass-1, sudo without a password)
and installs ansible-core and policycoreutils-python-utils (for
semanage). Work as greg, in /home/greg/ansible: its ansible.cfg
reads the inventory inventory and becomes root. The ansible.posix and
community.general collections aren't installed yet, and neither is
Apache. SELinux is enforcing; keep it that way.
Tasks
- Serve a page from
/srv/wwwon the web servers: install Apache, put anindex.htmlin/srv/www, add a file context rule and relabel, and configure Apache to use/srv/wwwas its document root. Open the firewall for HTTP if it's running.ls -Z /srv/www/index.htmlshowshttpd_sys_content_tandcurl http://localhost/gets the page. - Turn on
httpd_can_network_connectpersistently.getseboolshowson, also after a reboot. - Label port 8888/tcp as
http_port_tand make Apache listen on it too, with the firewall open for it if it's running.ss -tlnp | grep 8888shows httpd, and the AVC log (ausearch -m avc -ts recent) is quiet.
Hints
ansible-galaxy collection install ansible.posix 'community.general:>=11,<12': community.general 12 and later need a newer ansible-core than this one.community.general.sefcontextwithtarget: '/srv/www(/.*)?', and a handler runningrestorecon -Rv /srv/www.- A file in
/etc/httpd/conf.d/can setDocumentRoot /srv/www, a<Directory /srv/www>withRequire all granted, andListen 8888. ansible.posix.sebooleanwithpersistent: true;community.general.seport.ansible.posix.firewalld, only wherefirewalld.serviceis running (service_facts).