강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

SELINUX에 대하여 - 2편-

작성자 정보

  • 웹관리자 작성
  • 작성일

컨텐츠 정보

본문

SELINUX에 대하여 - 2편-


작성자 : (주)수퍼유저코리아, http://www.superuser.co.kr 서버팀



차례(전체목차)

1. SELInux(Security-Enhanced Linux) 란?

2. SELinux 정책이란 무엇인가?

3. SELinux 설치여부 확인

4. SELinux 기본설정 - /etc/sysconfig/selinux

5. SELinux 서비스 설정 - setenforce

6. SELinux 서비스 설정 - chcon

7. SELinux 서비스 설정 - setsebool

8. 사용중인 정책을 교체하는 방법은?

9. SELinux LOG

10. Audit2allow

11. avc : denied

12. 참고문헌 또는 URL


5. SELinux 서비스 설정 - setenforce

top


SELinux의 서비스 상태를 변경해야 하는 필요가 있을때는 직접 /etc/sysconfig/selinux 파일에서 SELINUX=enforcing , 또는 SELINUX=permissive 처럼 수정해서 변경하는 방법도 있지만 setenforce 라는 명령어를 이용할수 있다.

"setenforce 0" 이라고 명령을 내리는것은 SELINUX=permissive 와 동일한 결과이며, "setenforce 1" 은 enforcing 모드를 의미한다. 시스템에서 SELinux 를 완전히 사용하지 않으려면 /etc/sysconfig/selinux 파일에서 SELINUX=disabled 처럼 설정하거나 시스템 부팅시에 부트로더의 파라미터로 selinux=0 이라고 주고 부팅하면 된다. (grub 을 사용하는 경우라면 grub 화면에서 e 를 누르고 편집모드로 들어간뒤에 kernel 줄의 맨 뒤에 selinux=0 을 적어주고 ESC, 그리고 b 를 눌러서 부팅하면 된다.)

sentenforce 명령은 sysadm_r 권한을 갖고 수행해야 한다; 그러기 위해, newrole 명령을 사용하거나, 아니면, su -를 사용하여 root 로 사용자 전환을 하면, 자동으로 sysadm_r 권한을 얻을 수 있다.


6. SELinux 서비스 설정 - chcon

top


SELinux 의 보안문맥을 변경해야 하는 경우에는 chcon 이라는 명령을 사용할수 있다.

아파치를 사용중에 분명히 디렉토리를 생성했는데도 에러가 난다면 아래처럼 http_user_content_t 를 해당 DocumentRoot 에 적용해줌으로 해결해 줄수있다.

chcon -R -t httpd_user_content_t /home/사용자계정/public_html


7. SELinux 서비스 설정 - setsebool

top


S[root@ns ~]# cat /etc/selinux/targeted/booleans

allow_ypbind=1

dhcpd_disable_trans=0

httpd_disable_trans=1

httpd_enable_cgi=1

httpd_enable_homedirs=1

httpd_ssi_exec=1

httpd_tty_comm=0

httpd_unified=1

mysqld_disable_trans=0

named_disable_trans=1

named_write_master_zones=1

nscd_disable_trans=1

ntpd_disable_trans=0

portmap_disable_trans=0

postgresql_disable_trans=0

snmpd_disable_trans=0

squid_disable_trans=0

syslogd_disable_trans=0

winbind_disable_trans=0

ypbind_disable_trans=0

RHEL4의 경우 전환가능한 시스템의 SELinux 설정값들을 나타내는 파일은 /etc/selinux/targeted/booleans 파일이다. 파일안의 각 항목은 system-config-securitylevel 이라는 어플리케이션이나 setsebool 이라는 명령을 이용해서 변경시킬수 있으며 setsebools 을 이용하는 경우 -P 옵션을 사용하지 않으면 설정파일은 변경되지 않고 현재의 설정만 바뀌지만 -P 옵션을 같이 사용하면 /etc/selinux/targeted/booleans 파일의 내용까지 같이 변경되어 시스템 리부팅후에도 적용된다.


8. 사용중인 정책을 교체하는 방법은?

top


배정책 교체는 가볍게 취할 사안이 아니다.

연구 목적으로 시험 장비(test machine)에서 새 정책을 시도하는 이외, 생산 시스템(production system)에서는 다른 정책으로 교체하기 전에 현황을 심각하게 고려해야 한다.

교체 작업은 간단하다. 이는 매우 안전한 방법이지만, 우선 시험 시스템에서 일차 시도해 보는 것이 바람직하다.

한 가지 방법은 system-config-securitylevel을 사용하여 정책을 바꾸고 재명명(relabel)하도록 파일 시스템을 설정하는 것이다.

수작업 절차는 다음과 같다:

1. /etc/selinux/config을 편집하고 SELINUXTYPE=policyname으로 정책 유형을 바꾼다.

2. 재부팅하여 돌아올 수 있는 지 확인하기위해, SELINUX=permissive모드로 설정한다. 이렇게 하면, SELinux는 정확한 정책하에서 가동될 것이지만, 만일 부정확한 파일 문맥 명명(labeling)과 같은 문제가 있으면 로그인하도록 할 것이다.

3. sysadm_r 역할을 갖춘 root로 파일 시스템을 재명명한다(relabel):

id -Z

root:sysadm_r:sysadm_t

fixfiles relabel

옵션 -l /path/to/logfile을 사용하여 표준 출력으로 로그를 볼 수 있고, 옵션 -o /path/to/file을 사용하여 검토(checked)되거나 재명명(relabel ed)된 모든 파일 리스트를 저장할 수 있다.

4. 시스템을 재부팅한다. 새 정책하에서의 재시작은 모든 시스템 프로세스가 적절한 문맥에서 시작되고 정책 변경으로 인한 모든 문제가 드러나게 한다.

5. sestatus -v 명령으로 발효된 변경사항을 확인한다. Permissive 모드로 가동된 새 시스템에서, avc: denied 메시지를 /var/log/messages에서 확인한다. 이들은 새 정책하에 문제없이 시스템이 가동되도록 해결해야 할 문제들을 표시해 준다.

6. 새 정책하에서 시스템이 만족스럽게 돌아갈 때, SELINUX=enforcing 으로 바꿔 실행 권한을 부여한다. 실시간에 enforcing을 활성화 시키기 위해 재부팅하거나 setenforce 1 을 실행한다.


9. SELinux LOG

top


SSELinux 의 로그는 /var/log/messages 파일에 아래처럼 나타난다.

kernel: audit(1114070701.193:0): avc: denied { read } for pid=24216

exe=/usr/libexec/mysqld name=mysql dev=cciss/c0d0p6 ino=16408

scontext=user_u:system_r:mysqld_t tcontext=root:object_r:var_lib_t

tclass=dir

이 로그는 아래와 같이 해석할수 있다.

- 읽기 요청이 거부되었다.

- PID 24216을 가진 프로세스가 read를 시도한다

- 해당프로세스는 /usr/libexec/mysqld 이다

- /dev/cciss/c0d0p6 에서 작동되고 있다

- inode 는 16408이다.

- 프로세스의 SELinux 문맥은 user_u:system_r:mysqld_t 이다.

- tcontext=root:object_r:var_lib_t : 이파일이 읽기를 시도하는 파일은 var_lib_t 타입의 root 소유파일이다.

SELinux LOG 각 항목의 의미

audit(timestamp) - This field states that it's an audit message from SELinux and that it was logged at timestamp time (in seconds since Jan. 1st, 1970).

avc - This message was from the SELinux access vector cache. Pretty much every message you are likely to see is from this cache.

denied | accepted - This field indicates whether the action was denied or accepted. You may see logs of accepted messages in some cases (like reloading the policy).

{ read | write | unlink | ... } - This field shows the type of action that was attempted, such as reading a file, writing, unlinking, loading policy, etc.

for pid=<pid> - This is the process ID that attempted the action.

exe=<executable>- This is the path to the executable that started the process.

name=<name> - This is the name of the target on which the action was attempted.

dev=<device> - This is the device on which the target file is located.

ino=<inode-number> - This is the inode of the target of the action.

scontext=<security context> - This is the process's security context. This contains user, role, and type.

tcontext=<target context> - This is the security context of the target of this action, for example, the file, directory, etc.

tclass=<target class> - This is the class of the target object, such as directory, file, device node, or something else.


10. Audit2allow

top


정책 작성자에게 유용한 도구는 /usr/bin/audit2allow 인데 이것은 /var/log/messages의 avc 메시지를 SELinux에 의해 사용될 수 있는 규칙으로 번역해준다. 사용이 불가능하다면 policycoreutils 패키지에 속해있으므로 yum install policycoreutils 처럼 설치 가능하다.

audit2allow명령은 세가지 방법으로 입력을 받을 수 있다. 기본은 표준입력 (stdin)이다. -i 옵션을 사용하면 /var/log/messages 로부터 입력을 읽을 수 있고 -d옵션을 사용하면 dmesg 출력으로부터 입력을 읽을 수 있다.


11. avc: denied

top


이 메시지는 현재 실행된 SELinux 정책이 그 응용프로그램의 동작을 허락하지 않기 때문이다. 이러한 일에는 여러 가지 사유가 존재한다.

첫째, 응용프로그램이 접근하려는 파일중 하나가 잘못 명명되어있을 수 있다. 만일 AVC 메시지가 특정 파일을 참조한다면, ls -alZ /path/to/file 을 수행하여 현재 참조하는 파일명(current label)을 조사해 보라. 만일 그것이 잘못되어 보이면, restorecon -v /path/to/file 을 시도해보라. 만일 파일과 관련된 매우 많 은 거부(denials) 상황이 존재하면, fixfiles relabel 을 수행하거나, 반복적으로 디렉토리 경로를 재명명하기 위해서 -R옵션과 함께 restorecon 을 수행하고 싶을 수 있다.

다른 때에는, 거부(denials) 현상은 정책에 의해 거부되도록 프로그램에 설정을 바꿔서 발생될 수 있다. 예를 들면, 만일 Apache를 8800포트로 바꾸면, 보안 정책, apache.te,도 관련하여 바꿔야 할 필요가 생긴다. 정책 작성에 관한 상세한 정보가 필요하면, 외부연결 리스트(External Link List)를 보라.


12. 참고문헌 또는 URL

top


Home of the SELinux project - http://www.nsa.gov/selinux/

The Un-Official SELinux FAQ - http://www.crypt.gen.nz/selinux/faq.html

SELinux link zoo - http://www.crypt.gen.nz/selinux/links.html

Ubuntu Linux SELinux pages - https://www.ubuntulinux.org/wiki/SELinux

2005.8 Sys Admin Magazine - http://www.samag.com/documents/s=9820/sam0508a/0508a.htm

NSA SELinux FAQ - http://www.nsa.gov/selinux/info/faq.cfm

SELinux community page - http://selinux.sourceforge.net

UnOfficial FAQ - http://www.crypt.gen.nz/selinux/faq.html

Writing SE Linux policy HOWTO - https://sourceforge.net/docman/display_doc.php?docid=21959&group_id=21266

Getting Started with SE Linux HOWTO: the new SE Linux (Debian) - https://sourceforge.net/docman/display_doc.php?docid=20372&group_id=21266

 
copyright.gif

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,043 명
  • 현재 강좌수 :  35,850 개
  • 현재 접속자 :  111 명