Bookmark this page

Guided Exercise: Adjust SELinux Policy with Booleans

Configure Apache to publish web content from users' home directories.

Outcomes

  • Configure the Apache web service to publish web content from the user's home directory.

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-booleans

Instructions

  1. On the workstation machine, use the ssh command to log in to the servera machine as the student user and then switch to the root user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Edit the /etc/httpd/conf.d/userdir.conf configuration file to enable the Apache feature so that users can publish web content from their home directory. Comment out the line in the IfModule section that sets the UserDir variable to the disabled value, and uncomment the line that sets the UserDir variable to the public_html value.

    [root@servera ~]# vim /etc/httpd/conf.d/userdir.conf
    <IfModule mod_userdir.c>
    ...output omitted...
        # UserDir disabled
    
    ...output omitted...
        UserDir public_html
    
    ...output omitted...
    </IfModule>
  3. Start and enable the Apache web service.

    [root@servera ~]# systemctl enable --now httpd
  4. Open another terminal window, and use the ssh command to log in to the servera machine as the student user. Create the index.html web content file in the ~/public_html directory.

    1. In another terminal window, use the ssh command to log in to the servera machine as the student user.

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera ~]$
    2. Use the mkdir command to create the ~/public_html directory.

      [student@servera ~]$ mkdir ~/public_html
    3. Create the index.html file with the following content:

      [student@servera ~]$ echo 'This is student content on SERVERA.' > \
      ~/public_html/index.html
    4. For the Apache web service to serve the contents of the /home/student/public_html directory, it must be allowed to share files and subdirectories in the /home/student directory. When you created the /home/student/public_html directory, it was automatically configured to allow anyone with home directory permission to access its contents.

      Change the /home/student directory permissions to allow the Apache web service to access the public_html subdirectory.

      [student@servera ~]$ chmod 711 ~
      [student@servera ~]$ ls -ld ~
      drwx--x--x. 16 student student 4096 Nov  3 09:28 /home/student
  5. Open a web browser on the workstation machine and enter the http://servera/~student/index.html address. An error message states that you do not have permission to access the file.

  6. Switch to the other terminal, and use the getsebool command to see whether any Booleans restrict access to home directories for the httpd service.

    [root@servera ~]# getsebool -a | grep home
    ...output omitted...
    httpd_enable_homedirs --> off
    ...output omitted...
  7. Use the setsebool command to enable persistent access to the home directory for the httpd service.

    [root@servera ~]# setsebool -P httpd_enable_homedirs on
  8. Verify that you can now see the This is student content on SERVERA. message in the web browser after entering the http://servera/~student/index.html address. You might need to close and reopen your web browser to see the message.

  9. Return to the workstation machine as the student user.

    [root@servera ~]# exit
    logout
    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish selinux-booleans

Revision: rh199-9.3-8dd73db