Security-Enhanced Linux (SELinux) - (3)



So We are entering the last session of SELinux in RHCSA level. So before entering you have to remember followings.

Installing a service

  • yum install httpd
  • systemctl enable httpd.service
  • systemctl start httpd.service
  • systemctl status httpd 
  • rpm -qa | grep httpd

SELinux mode

  • sestatus
  • vim /etc/sysconfig/selinux 
  • reboot
After installing httpd service, open firefox and type localhost. Then Welcome page will be loaded.
Root directory is /var/www/html. In here you need to create a file named index.html. You can use touch or vim commands. For an example,
  • cd /var/www/html
  • vim index.html
Then you will get a index.html file to edit. Reason for selecting /var/www/html file path because it was defined as the root directory in /etc/httpd/conf/httpd.conf path
After you creating a index.html file save it and restart the httpd service.
  • systemctl restart httpd.service
------------------------------------------------------------------------------------------------------------------
First check the SELinux status. If it is disabled you can make changes in /etc/sysconfig/selinux to enable SELinux . rpm -qa | grep httpd is used for check whether httpd related services are installed.
Then install httpd service using yum install httpd 
 If it successfully installed, you can see above details.  Now httpd service is successfully installed.
Then check the status of httpd service. Currently it is in inactive state. So wee need to covert it to active state.
Use systemctl enable httpd.service to enable the service. if not you need to start it manually after rebooting every time.
Then start the httpd service using systemctl start httpd.service. 
 So type systemctl status httpd.service to check its status. Now it is in active (running) state.
Then type firefox to open firefox browser. 
 Then type localhost in the search bar. After that you receive this test page. But this page is load because of there are no file in default file path. There are no file called index.html in /var/www/html . It is define in /etc/httpd/conf/httpd.conf file.
  Then you receive this.
These is how document root is set to /var/www/html
 Then change your directory path to /var/www/html and create a file called index.html

 Write some html in this folder and save it. (press i to switch to insert mode and press ESC and type :WQ to save and quit)
Again open a browser and type localhost. It will load our html in /var/www/html/index.html

In here this /var/www/html path is labeled in selinux content type. Thats why index.html load after typing localhost. It inherit to index.html file.


If we not label it lets see what happen. Let assume we are in enforce mode. It only allows to access the file label in SELInux content type and file path should be in /etc/httpd/conf/httpd.conf as Document Root. But this will not effect when the SELinux in permissive mode or disabled mode.

You can use following command to check whether given file path or directory path is labeled with SELinux content type.
  • For files
  • For directories

How to label a file with SELinux?

It is not that much hard. Use semanage fcontext manual page.

Then manual page will open.
Go to example and copy 1 line and replace your new path with /web. 
In there (/.*) used to inherit SELinux content type to files which are going to be created in given path.
After that copy 2 line and replace /web with your path.
Then restart the httpd service. 
So you can access the index.html in different path. 


 Create a file in /var/www/index. Then it will be automatically labeled with SELinux context type.
Move it to the folder that want to. Change /etc/httpd/conf/httpd.conf file. 
Restart the service and type firefox. Then type localhost. It should be worked. 



Comments

Popular posts from this blog

Basic Configurations in Windows Server 2016 (2)

Interrupt the kernel to change the fstab - RHCSA

Controlling the boot process - RHCSA