SELinux

오픈소스 비즈니스 컨설팅
둘러보기로 가기 검색하러 가기

SELinux (Security-Enhanced Lunux)를 정리 한다.

SELinux 개요

SELinux (Security-Enhanced Lunux)은 NSA (National Security Agency, 미국 국가 안보국)에서 개발한 MAC 기안의 보안 커널을 Linux에 이식한 커널 레벨의 보안 모듈 이다.


d187db34-c134-11e5-85e3-76a71fd3ea9a.png


Access Control (접근 통제)

Object (객체) 시스템 자원
Subject (주체) 사용자나 프로세스


DAC (Discretionary Access Control, 임의 접근 통제)

시스템 객체에 대한 접근을 사용자 또는 그룹을 기준으로 제한 한다.

setuid : 일반 사용자가 root 권한으로 프로그램을 실행할 수 있도록 허용 한다.

ls -alF /usr/bin/passwd

find /bin /usr/bin /sbin -perm -4000 -exec ls -ldb {} \;


MAC (Mandatory Access Control, 강제 접근 통제)

미리 정해진 정책과 보안 등급에 의거하여 주체에게 허용된 접근 권한과 객체에게 보여된 허용 등급을 비교하여 접근을 통제 한다.


Security Context (보안 컨텍스트)

User (사용자) 시스템과는 별도로 SELinx 사용자
Role (역할) 하나 이상의 Type과 연결
Type TE (Type Enforcement)
프로세스의 도메인이나 파일의 타입을 기반으로 접근 통제를 수행 한다.
Level MLS (Multi Level System)
강제 접근 통제보다 더 강력한 보안이 필요할 때 사용 한다.

보안 정책은 /etc/selinux/targeted/ 폴더에 정의되어 있다.


로그 파일

/var/log/audit/audit.log
  • avc : 오류 유형
  • comm : 오류를 발생시킨 프로그램
  • path : 객체 경로
  • scontext : 소스 컨텍스트
  • tcontext : 타겟 컨텍스트

SELinux 설정

SELinux 관리 도구 설치

yum -y install setools-console
yum -y install policycoreutils-python  


Context 정보 조회

seinfo
seinfo -adomain -x

#--- httpd_sys_content_t 객체에 접근할 수 있는 role 표시
sesearch --role_allow -t httpd_sys_content_t

#--- Context에 허용된 action
sesearch --allow -s httpd_t

조회 및 상태 확인

-Z 옵션

#--- Security Context 확인 : httpd_t
[root@cloud-web data] ps -efZ | grep http
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 root 1582 1555  0 23:39 pts/0 00:00:00 grep --color=auto http
system_u:system_r:httpd_t:s0    root      5895     1  0  5월20 ?      00:00:13 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache   26481  5895  0 03:19 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache   26482  5895  0 03:19 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache   26483  5895  0 03:19 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache   26484  5895  0 03:19 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache   26485  5895  0 03:19 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
system_u:system_r:httpd_t:s0    apache   30046  5895  0 12:54 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND

#--- TE (Type Enforcement) 확인 : httpd_sys_content_t
[root@cloud-web www] ls -Z /var/www drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 cgi-bin drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 html



User (system_u), Role (object_r), Type (httpd_sys_script_exec_t, httpd_sys_content_t), Level (s0)


port 확인

semanage port -l | grep http


sestatus

[root@manage001 selinux] sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          disabled
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

SELinux 동작 모드

SELinux Mode

Mode int Description
enforce 1 기본 설정
위반시 차안
permissive 0 위반시 경고 메시지를 표시하지만 차단하지 않음
disable
SELinux를 사용하지 않음


setenforce 명령으로 설정 변경

setenforce 0       #--- permissive mode로 전환
setenforce 1       #--- enforce mode로 전환


vi /etc/selinux/config

SELINUX=disabled

SELinux Boolean

미리 설정된 보안 정책

getsebool -a
getsebool httpd_can_sendmail
setsebool httpd_can_sendmail true
setsebool -P httpd_can_sendmail true     #--- 영구 설정

SELinux Utility

restorerecon -R 파일/폴더 : 잘못 설정된 보안 컨텍스트를 복구


chcon : 보안 컨텍스트를 지정

chcon -R -t httpd_sys_content_t  /var/www/html/zztemp.html


matchpathcon ~ : 폴더별로 필요한 보안 컨텍스트 표시


semanage

semanage port -l | grep http_port_t
semanage port -a -p tcp -t http_port_t 8080
semanage port -d -p tcp 800

semanage fcontext -l | grep httpd_sys_content_t
semanage fcontext -a -t httpd_sys_content_t "/data/www(/.*)?"
semanage fcontext -d "/data/www(/.*)?" 


audit2why : 로그를 보기 좋게 만들어 줌

참고 문헌