В этой лабораторной работе вы измените контекст SELinux для каталога и его содержимого.
Результаты
Вы сможете настроить HTTP-сервер Apache для публикации веб-содержимого из нестандартного корневого каталога документа.
Войдите на workstation как пользователь student с паролем student.
workstation
student
На workstation выполните команду lab selinux-filecontexts start. Эта команда запускает подготовительный сценарий, который проверяет доступность машины servera в сети. Сценарий также устанавливает службу httpd и разрешает HTTP-подключения в брандмауэре на servera.
lab selinux-filecontexts start
servera
httpd
[student@workstation ~]$ lab selinux-filecontexts start
[student@workstation ~]$
С помощью команды ssh войдите на машину servera как пользователь student. Системы настроены на использование ключей SSH для аутентификации, поэтому пароль не требуется.
ssh
[student@workstation ~]$ ssh student@servera ...output omitted... [student@servera ~]$
ssh student@servera
[student@servera ~]$
Выполните команду sudo -i, чтобы переключиться на пользователя root. Пароль для пользователя student — student.
sudo -i
root
[student@servera ~]$ sudo -i [sudo] password for student: student [root@servera ~]#
[sudo] password for student:
[root@servera ~]#
Настройте Apache на использование нестандартной корневой папки документов.
С помощью команды mkdir создайте новую корневую папку документов /custom.
mkdir
/custom
[root@servera ~]# mkdir /custom
mkdir /custom
С помощью команды echo создайте файл index.html в корневой папке документов /custom.
echo
index.html
[root@servera ~]# echo 'This is SERVERA.' > /custom/index.html
echo 'This is SERVERA.' > /custom/index.html
Настройте Apache на использование нового расположения корневой папки документов. Для этого отредактируйте файл конфигурации Apache /etc/httpd/conf/httpd.conf, заменив два экземпляра /var/www/html на /custom.
/etc/httpd/conf/httpd.conf
/var/www/html
...output omitted... DocumentRoot "/custom" ...output omitted... <Directory "/custom"> ...output omitted...
DocumentRoot
Directory
Запустите и включите веб-службу Apache и убедитесь, что она работает.
С помощью команды systemctl запустите и включите веб-службу Apache.
systemctl
[root@servera ~]# systemctl enable --now httpd
systemctl enable --now httpd
Выполните команду systemctl, чтобы убедиться, что служба работает.
[root@servera ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2019-03-25 19:16:48 CET; 15h ago Docs: man:httpd.service(8) Main PID: 6565 (httpd) Status: "Total requests: 16; Idle/Busy workers 100/0;Requests/sec: 0.000285; Bytes served/sec: 0 B/sec" Tasks: 213 (limit: 11406) Memory: 37.3M CGroup: /system.slice/httpd.service ├─6565 /usr/sbin/httpd -DFOREGROUND ├─6566 /usr/sbin/httpd -DFOREGROUND ├─6567 /usr/sbin/httpd -DFOREGROUND ├─6568 /usr/sbin/httpd -DFOREGROUND └─6569 /usr/sbin/httpd -DFOREGROUND Mar 25 19:16:48 servera.lab.example.com systemd[1]: Starting The Apache HTTP Server... Mar 25 19:16:48 servera.lab.example.com httpd[6565]: Server configured, listening on: port 80 Mar 25 19:16:48 servera.lab.example.com systemd[1]: Started The Apache HTTP Server.
systemctl status httpd
httpd.service
active (running)
Starting The Apache HTTP Server...
Started The Apache HTTP Server.
В веб-браузере на workstation попробуйте открыть http://servera/index.html. Вы увидите сообщение о том, что у вас нет разрешения на доступ к файлу.
http://servera/index.html
Чтобы разрешить доступ к файлу index.html на servera, необходимо настроить SELinux. Создайте правило SELinux, которое задает тип контекста httpd_sys_content_t для каталога /custom и всех файлов в нем.
httpd_sys_content_t
[root@servera ~]# semanage fcontext -a \ -t httpd_sys_content_t '/custom(/.*)?'
semanage fcontext -a \
-t httpd_sys_content_t '/custom(/.*)?'
Выполните команду restorecon, чтобы изменить контекст файлов.
restorecon
[root@servera ~]# restorecon -Rv /custom Relabeled /custom from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 Relabeled /custom/index.html from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
restorecon -Rv /custom
Снова попробуйте открыть http://servera/index.html. Вы увидите сообщение This is SERVERA.
This is SERVERA.
Выйдите с servera.
[root@servera ~]# exit logout [student@servera ~]$ exit logout Connection to servera closed. [student@workstation ~]$
exit
Конец
На workstation запустите сценарий lab selinux-filecontexts finish, чтобы закончить упражнение.
lab selinux-filecontexts finish
[student@workstation ~]$ lab selinux-filecontexts finish
Упражнение завершено.