SELinuxports — различия между версиями

Материал из pNp Wiki
Перейти к: навигация, поиск
(Конфигурирование SELinux для поддержки сервиса. Манипуляция портами)
(Применение SELinux на примере Apache)
Строка 20: Строка 20:
 
Listen 8888
 
Listen 8888
 
[root@vm-01 ~]#
 
[root@vm-01 ~]#
 +
</syntaxhighlight>
 +
После перезапуска вебсервера, он войдет в <code>failed state</code>, а поглядев в системный журнал, можно извлечь и полезную информацию:
 +
<syntaxhighlight lang="bash">
 +
[root@vm-01 ~]# journalctl -xe
 +
</syntaxhighlight>
 +
Получим текст следующего содержания:
 +
<syntaxhighlight lang="bash">
 +
Jan 22 12:50:55 vm-01 setroubleshoot[9510]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 8888. For complete SELinux messages. run sealert -l d97a7d35-1491-4a0c-97ed-7aa2db7e294b
 +
Jan 22 12:50:55 vm-01 python[9510]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 8888.
 +
                                   
 +
                                    *****  Plugin bind_ports (92.2 confidence) suggests  ************************
 +
                                   
 +
                                    If you want to allow /usr/sbin/httpd to bind to network port 8888
 +
                                    Then you need to modify the port type.
 +
                                    Do
 +
                                    # semanage port -a -t PORT_TYPE -p tcp 8888
 +
                                        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.
 +
                                   
 +
                                    *****  Plugin catchall_boolean (7.83 confidence) suggests  ******************
 +
                                   
 +
                                    If you want to allow system to run with NIS
 +
                                    Then you must tell SELinux about this by enabling the 'nis_enabled' boolean.
 +
                                   
 +
                                    Do
 +
                                    setsebool -P nis_enabled 1
 +
                                   
 +
                                    *****  Plugin catchall (1.41 confidence) suggests  **************************
 +
                                   
 +
                                    If you believe that httpd should be allowed name_bind access on the port 8888 tcp_socket by default.
 +
                                    Then you should report this as a bug.
 +
                                    You can generate a local policy module to allow this access.
 +
                                    Do
 +
                                    allow this access for now by executing:
 +
                                    # ausearch -c 'httpd' --raw | audit2allow -M my-httpd
 +
                                    # semodule -i my-httpd.pp
 
</syntaxhighlight>
 
</syntaxhighlight>

Версия 12:57, 22 января 2018

Конфигурирование SELinux для поддержки сервиса. Манипуляция портами

Предварительные требования

  • Виртуальная машина с двумя сетевыми интерфейсами
  • Установленные пакеты: bash-completion, policycoreutils, policycoreutils-python, policycoreutils-devel, setroubleshoot-server

Применение SELinux на примере Apache

Изменение порта вебсервера

По-умолчанию, вебсервер слушает порт 80. Необходимо изменить настройки таким образом, что бы Apache стал ожидать соединений на другом порту. Прежде чем изменить номер порта, следует убедиться в том, что данный порт не используется в другом контексте:

[root@vm-01 ~]# semanage port -l | grep 8888
[root@vm-01 ~]#

Теперь, изменим конфигурационный файл /etc/httpd/conf/httpd.conf

[root@vm-01 ~]# grep ^Listen /etc/httpd/conf/httpd.conf
Listen 80
[root@vm-01 ~]# sed -in 's#Listen 80#Listen 8888#g' /etc/httpd/conf/httpd.conf
[root@vm-01 ~]# grep ^Listen /etc/httpd/conf/httpd.conf
Listen 8888
[root@vm-01 ~]#

После перезапуска вебсервера, он войдет в failed state, а поглядев в системный журнал, можно извлечь и полезную информацию:

[root@vm-01 ~]# journalctl -xe

Получим текст следующего содержания:

Jan 22 12:50:55 vm-01 setroubleshoot[9510]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 8888. For complete SELinux messages. run sealert -l d97a7d35-1491-4a0c-97ed-7aa2db7e294b
Jan 22 12:50:55 vm-01 python[9510]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 8888.
                                    
                                    *****  Plugin bind_ports (92.2 confidence) suggests   ************************
                                    
                                    If you want to allow /usr/sbin/httpd to bind to network port 8888
                                    Then you need to modify the port type.
                                    Do
                                    # semanage port -a -t PORT_TYPE -p tcp 8888
                                        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.
                                    
                                    *****  Plugin catchall_boolean (7.83 confidence) suggests   ******************
                                    
                                    If you want to allow system to run with NIS
                                    Then you must tell SELinux about this by enabling the 'nis_enabled' boolean.
                                    
                                    Do
                                    setsebool -P nis_enabled 1
                                    
                                    *****  Plugin catchall (1.41 confidence) suggests   **************************
                                    
                                    If you believe that httpd should be allowed name_bind access on the port 8888 tcp_socket by default.
                                    Then you should report this as a bug.
                                    You can generate a local policy module to allow this access.
                                    Do
                                    allow this access for now by executing:
                                    # ausearch -c 'httpd' --raw | audit2allow -M my-httpd
                                    # semodule -i my-httpd.pp