RHCSA Rapid Track
Performance Checklist
In this lab, you will solve an SELinux access denial problem. System administrators are having trouble getting a new web server to deliver content to clients when SELinux is in enforcing mode.
Outcomes
You should be able to:
Identify issues in system log files.
Adjust the SELinux configuration.
Log in to workstation as student using student as the password.
On workstation, run the lab selinux-review start command.
This command runs a start script that determines whether the serverb machine is reachable on the network.
It also installs the httpd Apache server, creates a new DocumentRoot for Apache, and updates the configuration file.
[student@workstation ~]$lab selinux-review start
Log in to
serverbas the root user.Use the
sshcommand to log in toserverbas thestudentuser. The systems are configured to use SSH keys for authentication, so a password is not required.[student@workstation ~]$ssh student@serverb...output omitted... [student@serverb ~]$Use the
sudo -icommand to switch to therootuser. The password for thestudentuser isstudent.[student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#
Launch a web browser on
workstationand browse tohttp://serverb/lab.html. You will see the error message:You do not have permission to access /lab.html on this server.Research and identify the SELinux issue that is preventing Apache from serving web content.
Using the
lesscommand, view the contents of/var/log/messages. Use the / key and search forsealert. Use the q key to quit thelesscommand.[root@serverb ~]#less /var/log/messagesMar 28 10:19:51serverb setroubleshoot[27387]:SELinux is preventing /usr/sbin/httpd from getattr access on the file /lab-content/lab.html. For complete SELinux messages run:sealert -l 8824e73d-3ab0-4caf-8258-86e8792fee2dMar 28 10:19:51 serverb platform-python[27387]: SELinux is preventing /usr/sbin/httpd from getattr access on the file /lab-content/lab.html.#012#012***** Plugin catchall (100. confidence) suggests **************************#012#012If you believe that httpd should be allowed getattr access on the lab.html file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'httpd' --raw | audit2allow -M my-httpd#012# semodule -X 300 -i my-httpd.pp#012Run the suggested
sealertcommand. Note the source context, the target objects, the policy, and the enforcing mode.[root@serverb ~]#sealert -l 8824e73d-3ab0-4caf-8258-86e8792fee2dSELinux is preventing /usr/sbin/httpd from getattr access on the file /lab-content/lab.html.***** Plugin catchall (100. confidence) suggests ************************** If you believe that httpd should be allowed getattr access on the lab.html file by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # ausearch -c 'httpd' --raw | audit2allow -M my-httpd # semodule -X 300 -i my-httpd.pp Additional Information: Source Contextsystem_u:system_r:httpd_t:s0Target Contextunconfined_u:object_r:default_t:s0Target Objects/lab-content/lab.html [ file ]Source httpd Source Path /usr/sbin/httpd Port <Unknown> Hostserverb.lab.example.comSource RPM Packages Target RPM Packages Policy RPM selinux-policy-3.14.1-59.el8.noarch Selinux Enabled True Policy Type targeted Enforcing ModeEnforcingHost Name serverb.lab.example.com Platform Linux serverb.lab.example.com 4.18.0-67.el8.x86_64 #1 SMP Sat Feb 9 12:44:00 UTC 2019 x86_64 x86_64 Alert Count 2 First Seen 2019-03-28 15:19:46 CET Last Seen 2019-03-28 15:19:46 CET Local ID 8824e73d-3ab0-4caf-8258-86e8792fee2d Raw Audit Messages type=AVC msg=audit(1553782786.213:864): avc: denied { getattr } for pid=15606 comm="httpd" path="/lab-content/lab.html" dev="vda1" ino=8763212 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0 Hash: httpd,httpd_t,default_t,file,getattrThe
Raw Audit Messagessection of thesealertcommand contains information from the/var/log/audit/audit.log. Use theausearchcommand to search the/var/log/audit/audit.logfile. The-moption searches on the message type. Thetsoption searches based on time. This entry identifies the relevant process and file causing the alert. The process is thehttpdApache web server, the file is/lab-content/lab.html, and the context issystem_r:httpd_t.[root@serverb ~]#ausearch -m AVC -ts recenttime->Thu Mar 28 15:19:46 2019 type=PROCTITLE msg=audit(1553782786.213:864): proctitle=2F7573722F7362696E2F6874747064002D44464F524547524F554E44 type=SYSCALL msg=audit(1553782786.213:864): arch=c000003e syscall=6 success=no exit=-13 a0=7fb900004930 a1=7fb92dfca8e0 a2=7fb92dfca8e0 a3=1 items=0 ppid=15491 pid=15606 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)type=AVCmsg=audit(1553782786.213:864): avc:denied{ getattr } for pid=15606comm="httpd"path="/lab-content/lab.html"dev="vda1" ino=8763212 scontext=system_u:system_r:httpd_t:s0tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
Display the SELinux context of the new HTTP document root and the original HTTP document root. Resolve the SELinux issue preventing Apache from serving web content.
Use the
ls -dZto compare the document root of/lab-contentand/var/www/html.[root@serverb ~]#ls -dZ /lab-content /var/www/htmlunconfined_u:object_r:default_t:s0/lab-content/system_u:object_r:httpd_sys_content_t:s0/var/www/html/Create a file context rule that sets the default type to
httpd_sys_content_for/lab-contentand all the files below it.[root@serverb ~]#semanage fcontext -a \-t httpd_sys_content_t '/lab-content(/.*)?'Use the
restoreconcommand to set the SELinux context for the files in/lab-content.[root@serverb ~]#restorecon -R /lab-content/
Verify that the SELinux issue has been resolved and Apache is able to serve web content.
Exit from
serverb.