5.2. 명령줄 도우미를 사용하여 SELinux 문제 해결
다음 예제에서는 명령줄 도우미를 사용하여 SELinux 문제를 해결하는 단계를 제공합니다.
사전 요구 사항
- 명령줄 도우미를 활성화했습니다.
- 시스템에 대한 root 액세스 권한이 있습니다.
프로세스
터미널에서 다음 명령을 입력하여 시스템에 설치된
httpd패키지 버전을 나열합니다.$ sudo rpm -qa httpd httpd-2.4.62-2.fc40.x86_64httpd.conf파일 내용을 표시합니다.$ sudo cat /etc/httpd/conf/httpd.conf # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see<URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive.모든
httpdq패키지를 쿼리합니다.$ sudo rpm -qa httpdq웹 서버가 들어오는 요청을 수락하는 포트를 식별합니다.
$ cat /etc/httpd/conf/httpd.conf | grep Listen # Listen: Allows you to bind Apache to specific IP addresses and/or # Change this to Listen on a specific IP address, but note that if #Listen 12.34.56.78:80 Listen 80httpd서비스를 다시 시작합니다.$ systemctl restart httpd Job for httpd. Service failed because the control process exited with error code. See “systemctl status httpd.service" and “journalctl -xeu httpd.service" for details.실패한 서비스에 대한 자세한 내용은
journalctl명령을 실행합니다.$ sudo journalctl -xeu httpd.service
명령줄 도우미를 사용하여 문제를 해결하고 서비스가 실패하는 이유를 확인합니다.
$ sudo c “why did httpd fail to start"도우미의 제안 사항 중 하나는
ausearch툴을 사용하여 감사 로그를 쿼리하고 메시지 유형 매개 변수에AVC및USER_AVC값을 사용하는 것입니다. 이를 위해 다음 명령을 실행합니다.$ sudo ausearch -m AVC,USER_AVC -ts recentselinux httpd포트에 대한 명령행 도우미에게 문의하십시오.$ c “selinux httpd port"길잡이는 다음 명령으로
sestatus명령을 사용하여 현재 SELinux 상태 및 httpd 서비스의 콘텐츠를 확인하는 것이 좋습니다.$ sudo sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Memory protection checking: actual (secure) Max kernel policy version: 33다음 명령을 실행하여 httpd 서비스에 대한 특정 SELinux 정책을 확인합니다.
$ sudo cat /usr/share/selinux/targeted/contexts/httpd_var_run_t No such file or directory컨텍스트에 대해 명령줄 도우미에 문의하십시오.
$ c “i don't have a httpd_var_run_t contexts"명령줄 도우미는 요청을 처리하는 데 약간의 시간이 소요되고 가능한 몇 가지 제안을 제공합니다.
길잡이는 컨텍스트가 없을 수 있으며 다음 명령을 사용하여 설정할 필요가 있다고 합니다.
$ sudo chcon -R -t httpd_var_run_t포트에 대해 CLA에게 문의하십시오.
$ c “selinux won't let httpd listen on port 12345"다음 제안을 시도하고 명령을 실행합니다.
$ sudo semage port -a -t httpd_port_t -p tcp 12345 ValueError: Type httpd_port_t is invalid, must be a port type출력에 표시되는 오류에 대해 CLA에 문의하십시오.
$ c “how do I fix ValueError: Type httpd_port_t is invalid, must be a port type"
CLA에서 제공하는 단계를 실행합니다.
$ sudo getenforce Enforcing $ setenforce 0 $ sudo systemctl restart httpd $ sudo systemctl status httpd $ sudo ls -Z /usr/sbin/httpd system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd $ chcon -t httpd_exec_t /usr/sbin/httpd $ sudo setenforce 1httpd서비스를 다시 시작하고httpd.service의 상태를 확인합니다.$ sudo systemctl restart httpd Job failed $ sudo systemctl status httpd.service Failed to start the Apache Server
CLA에
httpd가 12345포트에서수신 대기하도록 설정하는 방법을 질문하십시오.$ c “how do I enable httpd to listen on port 12345 selinux"CLA에서 권고한 명령을 실행합니다.
$ sudo setsebool -P httpd_can_network_connect=1
httpd서비스를 다시 시작하고httpd.service의 상태를 다시 확인합니다.$ sudo systemctl status htppd $ sudo systemctl restart httpd Job failed, see journalctljournalctl서비스를 확인합니다.$ journalctl -xeu httpd Output: An ExecStart= process belonging to unit httpd.service has exited.출력을 사용하여 CLA에 문제를 해결하도록 요청합니다.
$ c “An ExecStart= process belonging to unit httpd.service has exited."CLA가 응답하는 명령을 실행합니다.
$ sudo ausearch -m AVC,USER_AVC -ts recent Output: “avc: denied {name_bind} for pid=7184 comm="httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0"이전 명령의 출력을 복사합니다.
$ sudo c ““avc: denied {name_bind} for pid=7184 comm="httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0”다음 명령을 실행하여 "SELinux가 Apache Server(httpd)로 인해 포트 12345에 바인딩되지 않음 오류를 해결합니다.
$ sudo semage port -a -t http_port_t -p tcp 12345
httpd 서비스를 다시 시작하고
httpd.service의 상태를 확인합니다.$ sudo systemctl restart httpd No error $ sudo systemctl status httpd.service서버가 구성 및 실행 중이고
포트 443,12345에서 수신 대기 중입니다.