RHCSA Rapid Track
In this lab, you will persistently change the SELinux context of a directory and its contents.
| Resources | |
|---|---|
| Files: | /etc/httpd/conf/httpd.conf |
| Machines: | serverX |
Outcomes
You will have a web server that publishes web content from a non-standard document root.
You should have a working RHEL 7 system with SELinux in enforcing mode.
Log in as
rootonserverX. Use yum to install the Apache web server.[root@serverX ~]#yum install -y httpdConfigure Apache to use a document root in a non-standard location.
Create the new document root,
/custom.[root@serverX ~]#mkdir /customCreate the
index.htmlwith some recognizable content.[root@serverX ~]#echo 'This is serverX.' > /custom/index.htmlConfigure Apache to use the new location. You need to replace the two occurrences of “/var/www/html” with “/custom” in the Apache configuration file,
/etc/httpd/conf/httpd.conf.[root@serverX ~]#vi /etc/httpd/conf/httpd.conf[root@serverX ~]#grep custom /etc/httpd/conf/httpd.confDocumentRoot "/custom" <Directory "/custom">
Start the Apache web service.
[root@serverX ~]#systemctl start httpdOpen a web browser on
serverXand try to view the following URL:http://localhost/index.html. You will get an error message that says you do not have permission to access the file.Define a SELinux file context rule that sets the context type to
httpd_sys_content_tfor/customand all the files below it.[root@serverX ~]#semanage fcontext -a -t httpd_sys_content_t '/custom(/.*)?'Use restorecon to change their contexts.
[root@serverX ~]#restorecon -Rv /customrestorecon reset /custom context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0 restorecon reset /custom/index.html context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0Try to view
http://localhost/index.htmlagain. You should see the message “This is serverX.” displayed.