SELinux 를 제대로 지원하지 않게 개발된 프로그램을 사용해야할 경우가 있다. 해결책은 프로그램을 SELinux 에서 문제없게 수정해야 하는 것이지만

당장 프로그램을 사용해야 하는 경우 수정은 얼마나 걸릴지 모르므로 당장의 해결책은 아니다.

 

이런 경우 SElinux 를 끄거나 permissive mode 로 전환하는 것 보다는 문제가 되는 프로그램만 SELinux 에서 제한하지 않게 설정하는 방법을 권장한다.

chcon 으로 unconfined_exec_t   보안 컨텍스트를 부여하면 구동시 SELinux 의 confined domain 으로 transition 되지 않는다.

 

Example

httpd 는 httpd_exec_t 를 갖고 있지만 구동되는 경우 httpd_t 로 domain 이 전이된다.

# ls -lZ /usr/sbin/httpd

-rwxr-xr-x. root root system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd
 
#  ps -eaZ|grep httpd            
unconfined_u:system_r:httpd_t:s0 7107 ?        00:00:02 httpd
CODE

httpd_t 컨텍스트는 httpd_sys_content_t 인 파일을 읽을 수 있으므로 /var/www/html/ 에 있다고 해도 다른 컨텍스트가 설정된 파일은 읽을 수가 없다.

 

# touch /var/www/html/test.html
# chcon -t ftpd_var_run_t /var/www/html/test.html
 
CODE

이제 curl 로 test.html 을 다운받아 보면 403 Forbidden 에러가 발생하는 것을 확인할 수 있다. 아래의 curl 명령어는 http response code 만 출력한다.

# curl -s -o /dev/null -w "%{http_code}\n" http://localhost/test.html

403
CODE

 

이제 httpd 에 unconfined_exec_t 보안 컨텍스트를 부여하면 SELinux 가 제한하지 않으므로 실행시 httpd_t 로 전이되지 않는다.

# service httpd stop
# chcon -t unconfined_exec_t /usr/sbin/httpd
# service httpd start
# ps -eaZ|grep httpd           

unconfined_u:unconfined_r:unconfined_t:s0 26771 ? 00:00:00 httpd
CODE

이제 httpd 는 httpd_sys_content_t 가 아닌 파일도 읽을 수 있다. 

# curl -s -o /dev/null -w "%{http_code}\n" http://localhost/test.html
 
200
CODE

보안에는 취약해지지만 이와 같이 프로세스별로 unconfined 설정을 하면 SELinux 를 끄지 않고도 문제가 되는 프로세스만 구동할 수 있다.

Ref