В этой лабораторной работе вы настроите систему servera, чтобы разрешить доступ к нестандартному порту через HTTP.
servera
Результаты
Вы настроите веб-сервер, работающий на servera, чтобы он раздавал контент через нестандартный порт.
Войдите на workstation как пользователь student с паролем student.
workstation
student
На workstation выполните команду lab netsecurity-ports start. Эта команда запускает подготовительный сценарий, который проверяет доступность машины servera в сети. Сценарий также устанавливает службу httpd и разрешает http-подключения в брандмауэре на servera.
httpd
[student@workstation ~]$ lab netsecurity-ports start
[student@workstation ~]$
lab netsecurity-ports start
Ваша организация развертывает новое веб-приложение. Это веб-приложение работает на нестандартном порту, в данном случае это 82/TCP.
82/TCP
Один из младших администраторов уже настроил приложение на servera. Однако контент веб-сервера недоступен.
С помощью команды ssh войдите на servera как пользователь student. Системы настроены на использование ключей SSH для аутентификации, поэтому пароль не требуется.
[student@workstation ~]$ ssh student@servera ...output omitted... [student@servera ~]$
ssh student@servera
Выполните команду sudo -i, чтобы переключиться на пользователя root. Пароль для пользователя student — student.
root
[student@servera ~]$ sudo -i [sudo] password for student: student [root@servera ~]#
[student@servera ~]$
sudo -i
Попытайтесь исправить проблему с веб-контентом, перезапустив службу httpd.
Выполните команду systemctl, чтобы перезапустить службу httpd.service. Выполнение этой команды должно завершиться неудачей.
httpd.service
[root@servera ~]# systemctl restart httpd.service Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
[root@servera ~]#
systemctl restart httpd.service
Выполните команду systemctl status -l, чтобы просмотреть статус службы httpd. Обратите внимание на ошибку Permission denied (в разрешении отказано).
Permission denied
[root@servera ~]# systemctl status -l httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Mon 2019-04-08 14:23:29 CEST; 3min 33s ago Docs: man:httpd.service(8) Process: 28078 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE) Main PID: 28078 (code=exited, status=1/FAILURE) Status: "Reading configuration..." Apr 08 14:23:29 servera.lab.example.com systemd[1]: Starting The Apache HTTP Server... Apr 08 14:23:29 servera.lab.example.com httpd[28078]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:82 Apr 08 14:23:29 servera.lab.example.com httpd[28078]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:82 Apr 08 14:23:29 servera.lab.example.com httpd[28078]: no listening sockets available, shutting down Apr 08 14:23:29 servera.lab.example.com httpd[28078]: AH00015: Unable to open logs Apr 08 14:23:29 servera.lab.example.com systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE Apr 08 14:23:29 servera.lab.example.com systemd[1]: httpd.service: Failed with result 'exit-code'. Apr 08 14:23:29 servera.lab.example.com systemd[1]: Failed to start The Apache HTTP Server.
systemctl status -l httpd.service
failed
Permission denied: AH00072: make_sock: could not bind to address [::]:82
Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:82
no listening sockets available, shutting down
Failed to start The Apache HTTP Server.
Выполните команду sealert, чтобы проверить, не блокирует ли SELinux привязку httpd к порту 82/TCP.
[root@servera ~]# sudo sealert -a /var/log/audit/audit.log 100% done found 1 alerts in /var/log/audit/audit.log -------------------------------------------------------------------------------- SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 82. ***** Plugin bind_ports (99.5 confidence) suggests ************************ If you want to allow /usr/sbin/httpd to bind to network port 82 Then you need to modify the port type. Do # semanage port -a -t PORT_TYPE -p tcp 82 where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t. ...output omitted... Raw Audit Messages type=AVC msg=audit(1554726569.188:852): avc: denied { name_bind } for pid=28393 comm="httpd" src=82 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket permissive=0 ...output omitted...
sudo sealert -a /var/log/audit/audit.log
SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 82.
# semanage port -a -t PORT_TYPE -p tcp 82 where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t.
Настройте SELinux, чтобы разрешить привязку httpd к порту 82/TCP, а затем перезапустите службу httpd.service.
Выполните команду semanage, чтобы найти подходящий тип порта для порта 82/TCP.
[root@servera ~]# semanage port -l | grep http http_cache_port_t tcp 8080, 8118, 8123, 10001-10010 http_cache_port_t udp 3130 http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000 pegasus_http_port_t tcp 5988 pegasus_https_port_t tcp 5989
semanage port -l | grep http
http_port_t
http_port_t содержит стандартные HTTP-порты ― 80/TCP и 443/TCP. Это правильный тип порта для веб-сервера.
80/TCP
443/TCP
С помощью команды semanage назначьте порту 82/TCP тип http_port_t.
[root@servera ~]# semanage port -a -t http_port_t -p tcp 82
semanage port -a -t http_port_t -p tcp 82
Выполните команду systemctl, чтобы перезапустить службу httpd.service. Эта команда должна выполниться успешно.
[root@servera ~]# systemctl restart httpd.service
Проверьте, доступен ли теперь веб-сервер через порт 82/TCP. С помощью команды curl откройте веб-службу с servera.
[root@servera ~]# curl http://servera.lab.example.com:82 Hello
curl http://servera.lab.example.com:82
В другом окне терминала проверьте, есть ли у вас доступ к новой веб-службе с машины workstation. С помощью команды curl откройте веб-службу с workstation.
[student@workstation ~]$ curl http://servera.lab.example.com:82 curl: (7) Failed to connect to servera.example.com:82; No route to host
Эта ошибка означает, что вы все еще не можете подключиться к веб-службе с машины workstation.
На servera откройте порт 82/TCP в брандмауэре.
С помощью команды firewall-cmd откройте порт 82/TCP в постоянной конфигурации для зоны по умолчанию в брандмауэре на servera.
[root@servera ~]# firewall-cmd --permanent --add-port=82/tcp success
firewall-cmd --permanent --add-port=82/tcp
Активируйте изменения брандмауэра на servera.
[root@servera ~]# firewall-cmd --reload success
firewall-cmd --reload
С помощью команды curl откройте веб-службу с workstation.
[student@workstation ~]$ curl http://servera.lab.example.com:82 Hello
Выйдите с servera.
[root@servera ~]# exit logout [student@servera ~]$ exit logout Connection to servera closed. [student@workstation ~]$
exit
Конец
На workstation запустите сценарий lab netsecurity-ports finish, чтобы закончить упражнение.
[student@workstation ~]$ lab netsecurity-ports finish
lab netsecurity-ports finish
Упражнение завершено.