Red Hat Training

A Red Hat training course is available for RHEL 8

4장. 비표준 구성을 사용하여 애플리케이션 및 서비스에 대한 SELinux 구성

SELinux가 강제 모드인 경우 기본 정책은 타겟 정책입니다. 다음 섹션에서는 프로세스에 대한 구성 기본값(예: 포트, 데이터베이스 위치 또는 파일 시스템 권한)을 변경한 후 다양한 서비스에 대한 SELinux 정책 설정 및 구성에 대한 정보를 제공합니다.

비표준 포트에 대한 SELinux 유형을 변경하고, 기본 디렉터리 변경의 잘못된 레이블을 식별 및 수정하고, SELinux 부울을 사용하여 정책을 조정하는 방법을 학습합니다.

4.1. 비표준 구성에서 Apache HTTP 서버에 대한 SELinux 정책 사용자 정의

다른 포트에서 수신 대기하고 기본이 아닌 디렉터리에 콘텐츠를 제공하도록 Apache HTTP 서버를 구성할 수 있습니다. 이에 상응하는 SELinux 거부를 방지하려면 다음 절차의 단계에 따라 시스템의 SELinux 정책을 조정하십시오.

사전 요구 사항

  • httpd 패키지가 설치되고 Apache HTTP 서버는 TCP 포트 3131에서 수신 대기하고 기본 /var/www / 디렉터리 대신 /var/test_www / 디렉터리를 사용하도록 구성되어 있습니다.
  • policycoreutils-python-utilssetroubleshoot-server 패키지가 시스템에 설치됩니다.

절차

  1. httpd 서비스를 시작하고 상태를 확인합니다.

    # systemctl start httpd
    # systemctl status httpd
    ...
    httpd[14523]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:3131
    ...
    systemd[1]: Failed to start The Apache HTTP Server.
    ...
  2. SELinux 정책은 httpd 가 포트 80에서 실행된다고 가정합니다.

    # 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
  3. 포트 3131의 SELinux 유형을 포트 80과 일치하도록 변경합니다.

    # semanage port -a -t http_port_t -p tcp 3131
  4. httpd 를 다시 시작하십시오.

    # systemctl start httpd
  5. 그러나 컨텐츠는 액세스할 수 없습니다.

    # wget localhost:3131/index.html
    ...
    HTTP request sent, awaiting response... 403 Forbidden
    ...

    sealert 도구를 사용하여 이유를 찾습니다.

    # sealert -l "*"
    ...
    SELinux is preventing httpd from getattr access on the file /var/test_www/html/index.html.
    ...
  6. matchpathcon 도구를 사용하여 표준 및 새 경로에 대한 SELinux 유형을 비교합니다.

    # matchpathcon /var/www/html /var/test_www/html
    /var/www/html       system_u:object_r:httpd_sys_content_t:s0
    /var/test_www/html  system_u:object_r:var_t:s0
  7. 새로운 /var/test_www/html/ 콘텐츠 디렉터리의 SELinux 유형을 기본 /var/www/html 디렉터리의 유형으로 변경합니다.

    # semanage fcontext -a -e /var/www /var/test_www
  8. /var 디렉토리의 레이블을 재귀적으로 다시 지정합니다.

    # restorecon -Rv /var/
    ...
    Relabeled /var/test_www/html from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0
    Relabeled /var/test_www/html/index.html from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0

검증

  1. httpd 서비스가 실행 중인지 확인합니다.

    # systemctl status httpd
    ...
    Active: active (running)
    ...
    systemd[1]: Started The Apache HTTP Server.
    httpd[14888]: Server configured, listening on: port 3131
    ...
  2. Apache HTTP 서버에서 제공하는 콘텐츠에 액세스할 수 있는지 확인합니다.

    # wget localhost:3131/index.html
    ...
    HTTP request sent, awaiting response... 200 OK
    Length: 0 [text/html]
    Saving to: ‘index.html’
    ...

추가 리소스

  • semanage(8), matchpathcon(8)sealert(8) 도움말 페이지.