SELinux
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/SELinux_Users_and_Administrators_Guide/Red_Hat_Enterprise_Linux-7-SELinux_Users_and_Administrators_Guide-en-US.pdf
https://www.linux.co.kr/home2/board/subbs/board.php?bo_table=lecture&wr_id=1193
https://www.nsa.gov/what-we-do/research/selinux/documentation/assets/files/presentations/2003-ottawa-linux-symposium-bof-presentation.pdf
http://www.omnisecu.com/gnu-linux/redhat-certified-engineer-rhce/what-is-security-enhanced-linux-selinux.php
https://www.centos.org/docs/5/html/Deployment_Guide-en-US/selg-overview.html
SELinux를 정리한 블로그나, 개념들을 보면 아래의 개념들이 항상 나온다.
DAC (Discretionary Access Control)
ㄴ defines the basic access controls for objects in a filesystem (CentOS 문서)
ㄴ allows authorized users to change the access control attributes of objects, thereby specifying whether other users have access to the object. (RedHat에서 정의한 DAC)
표준 리눅스 보안정책은 DAC를 따름
DAC는 위험하고, 취약한 부분이 많아 MAC 기준의 구현방법이 생김 (SELinux)
The term DAC is commonly used in contexts that assume that every object has an owner that controls the permissions to access the object, probably because many systems do implement DAC using the concept of an owner.
ㄴ DAC는 모든 object에게 owner 및 permissions 기반으로 관리를함
ㄴ write, read, and execute in each of the 3 bits for each of User, Group and Others. (쓰고, 읽고, 실행 / 유저, 그룹, 전체)
ㄴ SetUID, SetGID, Skicky bit
DAC상에서는 파일, 디바이스, 디렉토리 등을 객체라 하며 사용자는 주체가됨, 주체가 객체를 제어하게 됩니다.
ex) thkim 이라는 user는 /home/thkim 디렉토리의 index.html 을 읽기, 쓰고, 실행을 할수있음
DAC의 권한 결정은 사용자 ID 및 소유권에의 기반으로 되어 있으며, 사용자의 역할과 프로그램의 기능 및 신뢰성, 데이터의 기밀성 및 무결성 등 기타 보안 관련 사항을 고려하지 않음
user는 일반적으로 자신의 파일에 대해 완전한 재량권을 가지고 있음, user가 실행하는 모든 프로그램은 user에게 부여 된 모든 권한을 상속받음
SELinux를 사용하지 않는 시스탬에서의 권한의 예
~]$
ls -l file1
-rwxrw-r-- 1 user1 group1 0 2009-08-30 11:03 file1
MAC (Mandatory Access Control)
https://en.wikipedia.org/wiki/Mandatory_access_control
관리 대상
ㄴ a process or thread (프로세스, 쓰레드)
ㄴ 객체 -> 파일, 디렉토리, TCP/UDP Port, 공유메모리 세그먼트, IO devices, etc 등의 객체에게 각각의 보안 속성을 가지고 있음
MAC는 Bell–LaPadula model 따릅니다.
ㄴ https://en.wikipedia.org/wiki/Bell%E2%80%93LaPadula_model
ㄴ http://blog.naver.com/nettier/220592764447
ㄴ http://themeat.tistory.com/70
http://selinuxproject.org/page/NB_MAC
ㅁ SELinux supports two forms of MAC:
- Type Enforcement - Where processes run in domains and the actions on objects are controlled by the policy. This is the implementation used for general purpose MAC within SELinux along with Role Based Access Control. The Type Enforcement and Role-Based Access Control (RBAC) sections covers these in more detail.
- Multi-Level Security - This is an implementation based on the Bell-La Padula (BLP) model, and used by organizations where different levels of access are required so that restricted information is separated from classified information to maintain confidentiality. This allows enforcement rules such as 'no write down' and 'no read up' to be implemented in a policy by extending the security context to include security levels. The Multi-Level Security and Multi-Category Security section covers this in more detail along with a variant called Multi-Category Security (MCS).
https://en.wikipedia.org/wiki/Mandatory_access_control
ㅁ RBAC (Role-Based Access Control)
ㅁ Type Enforcement (TE)
문법
user:role:type[:range]
user | The SELinux user identity. This can be associated to one or more roles that the SELinux user is allowed to use. |
role | The SELinux role. This can be associated to one or more types the SELinux user is allowed to access. |
type | When a type is associated with a process, it defines what processes (or domains) the SELinux user (the subject) can access. When a type is associated with an object, it defines what access permissions the SELinux user has to that object. |
range | This field can also be know as a level and is only present if the policy supports MCS or MLS. The entry can consist of:
These components are discussed in the Security Levels section. |
USER -> SELinux 식별자
ROLE -> TYPE 부여하는 역활
TYPE -> user 혹은 object 등등
RANGE -> Single 혹은 범위로 설정가능
개념
https://www.nsa.gov/what-we-do/research/selinux/documentation/assets/files/presentations/2003-ottawa-linux-symposium-bof-presentation.pdf
위의 내용들은 그냥 그런것들이 있구나 라고 넘어가도 되는 내용, 궁금한 사람들만 집중적으로 파고 들어가세요
실습 - https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/SELinux_Users_and_Administrators_Guide/Red_Hat_Enterprise_Linux-7-SELinux_Users_and_Administrators_Guide-en-US.pdf
위의 문서 기준으로 설명과 실습을 하고자 함
SELinux States and Models
SELinux는 enabled과 disabled 을 설정할수 있습니다. Disabled 상태에서는 Linux는 DAC Role에서 제어가 됩니다.
ㅁ Enabled 동작
ㄴ Enforcing -> SELinux denies access based on SELinux policy rules
ㄴ Pemissive -> Not deny access, Enforcing 기준으로 Deny 처리가되는 동작에 대해서 Log를 남긴다.
위의 동작설정은 setenforce 명령어로 진행
[root@t-control ~]# getenforce
Enforcing
ㅁ SELinux contexts follow the SELinux user:role:type:level syntax. The fields are as follows:
[root@t-control thkim]# touch file1
[root@t-control thkim]# ls -Z file1
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 file1
[root@t-control thkim]#
[root@t-control thkim]# semanage login -l
로그인 이름 SELinux 사용자 MLS/MCS 범위 서비스
__default__ unconfined_u s0-s0:c0.c1023 *
root unconfined_u s0-s0:c0.c1023 *
system_u system_u s0-s0:c0.c1023 *
[root@t-control thkim]#
Login Name - Linux 사용자를 나열합니다.
SELinux User - 칼럼에서는 어떤 SELinux 사용자 Linux 사용자가 매핑되어 있는지를 나열합니다. 프로세스에 액세스 할 수있는 역할과 수준을 SELinux 사용자가 제한합니다.
MLS/MCS Range - MLS (다중 레벨 보안) 및 MCS (여러 카테고리 보안)를 사용하는 수준입니다.
Service - Linux 사용자가 시스템에 로그인해야할 SELinux 문맥을 결정합니다. 기본적으로 별표 (*) 기호가 사용 된 모든 서비스를 나타냅니다
Role
ㄴ SELinux user Role에 대한 권한을 가짐, Role은 domain에 대한 권한을 가지고 있음
ㄴ domain 및 SELinux user에대한 중계자 역활을 수행
ㄴ 어떤 domain에 들어갈수 있는가, 어떤 object type이 access 가능한지 여부를 제어
ㄴ escalation attacks 감소에 도움이 됨
Type
ㄴ process의 domain을 정의, file type을 정의
ㄴ domain이 type에 접근, domain이 다른 도메인에 접근하는경우를 정의
ㄴ access를 허용하는 특정 SELinux role이 존제하는 경우에만 access가 허용됨
Level
ㄴ MLS 및 MCS 속성
ㄴ MLS Level이 다른경우 lowlevel-highlevl, level이 동일한경우 lowlevel-lowlevel = lowlevel (s0-s0 = s0)
ㄴ sensitivity-category pair 카테고리가 없는경우에는 sensitivity 표기
ㄴ category가 연속인 경우 단축이 가능 (c0.c3 = c0,c1,c2,d3)
ㄴ Redhat linux에서 지원하는 sensitivity,는 S0 하나이다. category는 0-1023까지 1024개를 지원한다. 모든 권한은 S0에서 가진다.
ㄴ MLS는 Bell-La Padula 강제하고, LSPP 환경에서 사용됨, MLS을 사용하려면 selinux-policymls package 설치해야함,
ㄴ X Windows system 에서는 지원하지 않음
ㅁ Domain Transitions
- user는 password를 변경하려고 한다.
- passwd utils을 실행
- /usr/bin/passwd은 passwd_exe_t type으로 분류되어 있음
[root@t-control thkim]# ls -Z /usr/bin/passwd
-rwsr-xr-x. root root system_u:object_r:passwd_exec_t:s0 /usr/bin/passwd
[root@t-control thkim]#
- passwd utils은 shadow_t type의 lebel이 붙어있는 /etc/shadow 파일에 접근
[root@t-control thkim]# ls -Z /etc/shadow
----------. root root system_u:object_r:shadow_t:s0 /etc/shadow
[root@t-control thkim]#
An SELinux policy rule states that processes running in the passwd_t domain are allowed to read and write to files labeled with the shadow_t type. The shadow_t type is only applied to files that are required for a password change. This includes /etc/gshadow, /etc/shadow, and their backup files.
ㄴ passwd_t 도메인에서 실행중인 process가 shadow_t type의 label을 가진 파일의 read 및 write를 허용하고 있음
ㄴ shadow_t type은 암호 변경이 필요한 파일에만 되어 있음
ㄴ /etc/gshadow, /etc/shadow 해당파일의 백업 파일
An SELinux policy rule states that the passwd_t domain has entrypoint permission to the passwd_exec_t type
ㄴ passwd_t 도메인에 passwd_exec_t type에 entrypoint 권한이 있음
When a user runs the passwd utility, the user's shell process transitions to the passwd_t domain. With SELinux, since the default action is to deny, and a rule exists that allows (among other things) applications running in the passwd_t domain to access files labeled with the shadow_t type, the passwd application is allowed to access /etc/shadow, and update the user's password.
ㄴ passwd util 실행 -> user shell process가 passwd_t 도메인으로 마이그레이션 -> SELinux 기본 동작은 deny로 되어 있지만 passwd_t 도메인으로 실행중인 응용프로그램이 shadow_t type의 lebel이 붙은 파일에 access하는것을 allow 하는 규칙이 존제 -> passwd 응용프로그램은 /etc/shadow에 허용된 사용자의 암호를 update 할수 있음
이 예제는 도메인 이전을 설명하는 기본적인 예제로 사용되고 있다.
passwd_t 도메인에서 실행중인 주체가 shadow_t type label 이 붙은 object에 access를 allow한다는 role은 실제로 있지만, 새로운 domain으로 마이그레이션 하기전에 다른 SELinux 규칙이 마련되어 있어야 한다.
passwd_t domain은 passwd_exec_t type의 label이 들어간 응용프로그램만 실행할수 있다, lib_t type과 같은 권한있는 공유 라이브러리에서만 실행 가능, 어떠한 다른 응용프로그램을 실행할수 없다.
passwd_t 같이 신뢰받는 domain만 shadow_t type의 label 이 붙은 파일에 write 할수 있습니다. 아무리 superuser 권한으로 실행이 되어 있어도 passwd_t domain에서 실행되는것이 아니라면 shadow_t type의 label이 붙은 파일에 write 할수 없습니다.
passwd_t domain으로 마이그레이션은 신뢰할수 있는 domain만 해야합니다. 예를 들어 sendmail_t domain에서 실행중인 sendmail process는 passwd을 실행해야할 이유가 없기에 passwd_t domain으로 마이그레이션 하면 안됩니다.
passwd_t domain에서 실행중인 process가 읽고, 쓰는 권한은 type은 etc_t 혹은 shadow_t 등의 label이 붙은 파일뿐입니다. 이렇게 하면 passwd 프로그램이 문제있는 파일을 읽거나 쓰는걸 방지할수 있습니다.
ㅁ SELinux Contexts for Process
[root@t-control thkim]# passwd
root 사용자의 비밀 번호 변경 중
새 암호:
passwd util은 passwd_t 도메인으로 실행,
[root@controller ~]# ps -eZ
...
system_u:system_r:NetworkManager_t:s0 683 ? 00:00:00 NetworkManager
system_u:system_r:policykit_t:s0 735 ? 00:00:00 polkitd
system_u:system_r:NetworkManager_t:s0 736 ? 00:00:00 wpa_supplicant
system_u:system_r:dhcpc_t:s0 1021 ? 00:00:00 dhclient
system_u:system_r:sshd_t:s0-s0:c0.c1023 1244 ? 00:00:00 sshd
system_u:system_r:tuned_t:s0 1246 ? 00:00:03 tuned
system_u:system_r:postfix_master_t:s0 1547 ? 00:00:00 master
'Security > Linux - Selinux' 카테고리의 다른 글
selinux 04 (0) | 2016.08.01 |
---|---|
selinux 03 (0) | 2016.08.01 |