RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
In this lab, you identify issues in system log files and adjust the SELinux configuration.
Outcomes
Identify issues in system log files.
Adjust the SELinux configuration.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start selinux-review
Instructions
Log in to the
serverbmachine as thestudentuser and switch to therootuser.From a web browser on the
workstationmachine, view thehttp://serverb/lab.htmlweb page. You see the error message:You do not have permission to access this resource.Research and identify the SELinux issue that prevents the Apache service from serving web content.
View the contents of the
/var/log/messagesfile. Use the / key and search for thesealertstring. Use the q key to quit thelesscommand.[root@serverb ~]#
less /var/log/messages...output omitted... Apr 7 06:16:15 serverb setroubleshoot[26509]: failed to retrieve rpm info for /lab-content/la b.html Apr 7 06:16:17 serverb setroubleshoot[26509]:SELinux is preventing /usr/sbin/httpd from getattr access on the file /lab-content/lab.html.For complete SELinux messages run: sealert -lApr 7 06:16:17 serverb setroubleshoot[26509]: SELinux is preventing /usr/sbin/httpd from getattr access on the file /lab-content/lab.html ...output omitted...35c9e452-2552-4ca3-8217-493b72ba6d0bRun the suggested
sealertcommand. Note the source context, the target objects, the policy, and the enforcing mode.[root@serverb ~]#
sealert -l35c9e452-2552-4ca3-8217-493b72ba6d0bSELinux is preventing /usr/sbin/httpd from getattr access on the file /lab-content/lab.html. ***** Plugin catchall_labels (83.8 confidence) suggests ******************* If you want to allow httpd to have getattr access on the lab.html file Then you need to change the label on /lab-content/lab.html Do # semanage fcontext -a -t FILE_TYPE '/lab-content/lab.html' where FILE_TYPE is one of the following: ...output omitted... 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 httpd-2.4.51-7.el9_0.x86_64 Target RPM Packages SELinux Policy RPM selinux-policy-targeted-34.1.27-1.el9.noarch Local Policy RPM selinux-policy-targeted-34.1.27-1.el9.noarch Selinux Enabled True Policy Type targeted Enforcing ModeEnforcingHost Name serverb.lab.example.com Platform Linux serverb.lab.example.com 5.14.0-70.2.1.el9_0.x86_64 #1 SMP PREEMPT Wed Mar 16 18:15:38 EDT 2022 x86_64 x86_64 Alert Count 8 First Seen 2022-04-07 06:14:45 EDT Last Seen 2022-04-07 06:16:12 EDT Local ID35c9e452-2552-4ca3-8217-493b72ba6d0bRaw Audit Messages type=AVC msg=audit(1649326572.86:407): avc: denied { getattr } for pid=10731 comm="httpd" path="/lab-content/lab.html" dev="vda4" ino=18192752 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0 type=SYSCALL msg=audit(1649326572.86:407): arch=x86_64 syscall=newfstatat success=no exit=EACCES a0=ffffff9c a1=7f7c8c0457c0 a2=7f7c887f7830 a3=100 items=0 ppid=10641 pid=10731 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) Hash: httpd,httpd_t,default_t,file,getattrThe
Raw Audit Messagessection of thesealertcommand contains information from the/var/log/audit/audit.logfile. Search the/var/log/audit/audit.logfile. The-moption searches on the message type. Thetsoption searches based on time. The following entry identifies the relevant process and file that cause 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 recent...output omitted... ---- time->Thu Apr 7 06:16:12 2022 type=PROCTITLE msg=audit(1649326572.086:407): proctitle=2F7573722F7362696E2F6874747064002D44464F524547524F554E44 type=SYSCALL msg=audit(1649326572.086:407): arch=c000003e syscall=262 success=no exit=-13 a0=ffffff9c a1=7f7c8c0457c0 a2=7f7c887f7830 a3=100 items=0 ppid=10641 pid=10731 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(1649326572.086:407): avc: denied { getattr } for pid=10731comm="httpd"path="/lab-content/lab.html"dev="vda4" ino=18192752 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 directory and the original HTTP document directory. Resolve the SELinux issue that prevents the Apache server from serving web content.
Compare the SELinux context for the
/lab-contentand/var/www/htmldirectories.[root@serverb ~]#
ls -dZ /lab-content /var/www/htmlunconfined_u:object_r:default_t:s0/lab-contentsystem_u:object_r:httpd_sys_content_t:s0/var/www/htmlCreate a file context rule that sets the default type to
httpd_sys_content_for the/lab-contentdirectory and all the files in it.[root@serverb ~]#
semanage fcontext -a \-t httpd_sys_content_t '/lab-content(/.*)?'Correct the SELinux context for the files in the
/lab-contentdirectory.[root@serverb ~]#
restorecon -R /lab-content/
Verify that the Apache server can now serve web content.
Return to the
workstationmachine as thestudentuser.
This concludes the section.