2024_0213_SELinux 관리

이기태·2024년 2월 13일

리눅스

목록 보기
12/27

1. SELinux

  • Trusted OS(DAC -> MAC)

왜, 어떻게 사용하는것인가?

  • (Why? 보안) 손상된 시스템 서비스로 부터 사용자 데이터를 보호하는 기능
  • (How? 보안): 프로세스가 건드릴 수 있는 파일, 디렉토리, 포트에 대한 보안 레이블을 설정하여 엑세스 제어할 수 있는 보안 규칙을 설정한다.

SELinux Mode

  • disabled(비활성화): SELinux 위반이 거부되거나 기록되지 않음.
  • permissive(허용): 로깅
  • enforcing(강제): 엑세스 제어 + 로깅

Disabled <--> Permissive <--> Enforcing
| enforcing/permissive | disabled |
|<--- setenforce ----> |
|<---------------- reboot ------->|

# getenforce -> 현재 상태 확인
# sestatus -> 상태 확인
Current mode: permissive //현재
Mode from config file: permissive // 부팅시

# vi /etc/selinux/config -> SELINUX=enforcing // 부팅 설정
# setenforce 1|0 -> enforcing | permissive // 현재 설정

2. SELinux 기능

1) SELinux Context 설정

# ls -Zd /etc/www/html
system_u:object_r:httpd_sys_content_t:s0 /var/www/html
# touch /var/www/html/index.html
# ls -Z /var/www/html/index.html
system_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html

# touch /tmp/file{1,2}
# ls -Z /tmp/file*
unconfined_u:object_r:user_tmp_t:s0 /tmp/file1
unconfined_u:object_r:user_tmp_t:s0 /tmp/file2

# mv /tmp/file1 /var/www/html
# cp /tmp/file2 /var/www/html
# ls -Z /var/www/html/file*
unconfined_u:object_r:user_tmp_t:s0 /var/www/html/file1
unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/file2

파일의 SELinux 컨텍스트 변경

  • (ㄱ) semanage fcontext CMD
    [확인]
    # semanage fcontext -l | grep /var/www | head
    [설정]
    # mkdir -p /virtual
    => 잘못된 SELinux 설정을 처리하기 위해서는 다음과 같이 2가지 방법이 있다.
    # semange fcontext -a -t httpd_sys_content_t '/virtual(/.*)?'
    -a: add, -t : type
    # restorecon -R /virtual
  • (ㄴ) restorecon CMD: restorecon /virtual
    -> /etc/selinux/targeted/contexts/files/*
    -> 이 파일에 값이 저장 되어있음. 위 저장된 값으로 불러오기.
  • (ㄷ) chcon CMD : chcon -t httpd_sys_content_t /virtual

2) SELinux Boolean 설정

  • SELinux 정책의 동작을 변경(on|off)하는 스위치

[확인]
# semanage boolean -l | grep homedirs

[설정]
# setsebool -P httpd_enable_homedirs on|off
-P: 현재상태, 부팅시 상태 모두 설정.

  • p.15 실습 해보기

3) SELinux Port 설정

[확인]
# semanage port -l | grep http
[추가/변경]
# semanage port -a -t http_port_t -p tcp 8888
[삭제]
# semanage port -d -t http_port_t -p tcp 8888

3. Troubleshooting

1) SELinux 문제인가를 판별

# setenforce 0
# setenforce 1

2) 문제 해결 방법

# cat /var/log/messages | grep -i preventing
# sealert -l UUID

# semanage fcontext –a –t httpd_sys_content_t‘/web’
# restorecon –Rv /web/index.html
# curl localhost/web/index.html

3) 문제 해결 방법 2

# cat /var/log/audit/audit.log | grep -i 'avd: denied'
# sealert -a /var/log/audit/audit.log


;;;;

0개의 댓글