Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Lab 22.2RHCSA 10, Chapter 22

Find and fix SELinux denials

Level
Hard
30 min
Machines
server1
Status
Not started

Goal

Break a service on purpose, find the SELinux denial in the logs, understand it, and fix it the right way.

Before you start

  • Finish lab 22.1. Work as root.

Tasks

  1. Install setroubleshoot-server and selinux-policy-doc.
  2. Run chcon -t user_home_t /web/index.html and request the page. Find the AVC message, name the source type, target type and class, and fix the problem.
  3. Change the sshd port to 2222 in a drop-in file without a SELinux change. Restart sshd, see it fail, find the denial, and fix it. Restore port 22 afterwards (or keep both ports).
  4. Set only httpd_t to permissive, check that SELinux is still enforcing for the rest, then undo it.
  5. Use the man page of httpd to find the boolean that allows Apache to connect to a database over the network.

Check your work

ausearch -m AVC -ts today | grep -c denied
ls -Z /web/index.html
semanage port -l | grep ssh_port_t
semanage permissive -l
  • The web page works again; index.html has httpd_sys_content_t.
  • sshd runs; ssh_port_t has 2222.
  • semanage permissive -l shows no httpd_t at the end.
  • Boolean: httpd_can_network_connect_db.

Hints

Show the hints

Solution

Show the solution
  1. Tools.
    dnf install -y setroubleshoot-server selinux-policy-doc
  2. Label problem.
    chcon -t user_home_t /web/index.html
    curl -s -o /dev/null -w '%{http_code}\n' http://localhost/
    403
    ausearch -m AVC -ts recent | grep index.html
    restorecon -v /web/index.html
  3. Port problem.
    echo "Port 2222" > /etc/ssh/sshd_config.d/05-port.conf
    systemctl restart sshd
    ausearch -m AVC -ts recent -c sshd
    semanage port -a -t ssh_port_t -p tcp 2222
    systemctl restart sshd
    rm /etc/ssh/sshd_config.d/05-port.conf; systemctl restart sshd
  4. Permissive domain.
    semanage permissive -a httpd_t
    getenforce
    semanage permissive -d httpd_t
  5. Find the boolean.
    man httpd_selinux | grep -B2 -A2 -i database
    getsebool httpd_can_network_connect_db

My notes

No notes yet.

Lessons for this lab

Commands in this lab