ㅁ working with selinux
주요 SELinux 패키지의 개요를 설명
패키지 설치 및 업데이트, 사용되는 로그파일, 주요 SELinux 설정, SELinux 활성화 미 비 활성화, SELinux 모드 설정파일 및 디렉토리 레이블 임시 및 영구 변경, mount 명령으로 파일 시스템 레이블 덮어 쓰기, NFS 볼륨 마운트, 파일 및 디렉토리의 복사 및 보관시 SELinux 설정 방법
ㅁ SELinux Packages
설치중 수동으로 제외하는 경우를 빼곤 기본으로 SELinux 패키지가 설치 됩니다.
Text 모드에서 최소 설치라도, 기본적으로 policycoreutils-python 과 policycoreutils-gui 설치되어 있음
기본적으로 SELinux 대상 정책이 적용, SELinux 가 enforcing 모드에서 실행
다음의 SELinux 패키지는 기본 설치
policycoreutils -> restorecon, secon, setfiles, semodule, load_policy, setsebool 제공
selinux-policy -> SELinux Reference 정책 설정을 제공
SELinux Reference 정책은 완전한 SELinux 정책에서 SELinux 대상 정책 등 다른 정책의 기반으로 사용되는 정책
해당 패키지는 selinux-policy.conf 파일과 RPM 매크로가 포함되어 있음
자세한 내용은 https://github.com/TresysTechnology/refpolicy/wiki 참조
selinux-policy-targeted -> SELinux 대상 정책을 제공
libselinux는 SELinux 응용 프로그램 API를 제공
libselinux-utils -> avcstat, getenforce, getsebool, matchpathcon, selinuxconlist, selinuxdefcon, selinuxenabled, setenforce 유틸리티를 제공
libselinux-python -> SELinux 응용 프로그램 개발 용 python 바인딩을 제공
기본으로 설치되지는 않지만 yum install <package-name> 명령을 실행하면 옵션으로 설치 가능
selinux-policy-devel -> 사용자 정의 SELinux 정책 및 정책 모듈 생성을 위한 유틸리티를 제공, SELinux와 다른 서비스를 맞게 설정하는 방법을 설명하는 MAN 페이지도 포함
selinux-policy-mls -> MLS SELinux 정책을 제공
setroubleshoot-server -> SELinux 액세스를 거부했을때 생성되는 거무 메시지를 sealert 유틸리티에서 볼수 있는 자세한 설명으로 변환, 패키지로 제공
setools-console -> 정책 분산 및 쿼리 감사 로그 모니터링 및 보고, 파일 컨텍스트 관리를 위한 다양한 유틸리티 및 라이브러리 Tresys Technology SETools distribution를 제공
setools 패키지는 SETools의 메타 패키지
setools-gui 패키지는 apol 및 seaudit의 각 유틸리티를 제공
setools-console 패키지는 sechecker, sediff, seinfo, sesearch, findcon 각 명령 줄 유틸리티를 제공
자세한 내용은 https://github.com/TresysTechnology/setools3/wiki 참조
setools 과 setools-gui의 각 패키지는 Redhat Network Optional 채널이 활성화 되어있을 때만 사용할수 있음
자세한 내용은 https://access.redhat.com/support/offerings/production/scope_moredetail 참조
mcstrans 는 s0-s0 : C0.c1023 같은 수준을 SystemLow-SystemHigh 등 읽기 쉬운 형식으로 변환
policycoreutils-python -> SELinux 의 조작 및 관리를 위한 semanage, audit2allow, audit2why, chcat 등 각종 유틸을 제공
policycoreutils-gui -> SELinux 관리 용 그래픽 유틸리티인 system-config-selinux를 제공
ㅁ which log file is used
dbus, audit 패키지는 기본 패키지 선택에서 제거하지 않으면 기본 설치
setroubleshoot-server 는 yum을 이용해서 설치, yum install setroubleshoot
auditd 가 실행중이면 다음과 같은 SELinux deny log는 /var/log/audit/audit.log에 기록
type=AVC msg=audit(1223024155.684:49): avc: denied { getattr } for pid=2000 comm="httpd" path="/var/www/html/file1" dev=dm-0 ino=399185 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:samba_share_t:s0 tclass=file
/var/log/message 에 기록되는 내용
May 7 18:55:56 localhost setroubleshoot: SELinux is preventing httpd (httpd_t) "getattr" to /var/www/html/file1 (samba_share_t). For complete SELinux messages. run sealert -l de7e30d6-5488-466d-a606-92c9f40d316d
setroubleshootd 는 서비스로 실행되지 않음
AVC 메시지 분석은 사용됨
필요에 따라 다음의 두가지 프로그램이 setroubleshoot 시작하는 방법으로 작동
sedispatch 유틸리티는 audit 서브 시스탬의 일부로 실행
AVC 거부 메시지가 반환되면 sedispatch는 dbus를 사용해서 메시지를 발송
setroubleshootd가 실행중이면 발송, 실행중이지 않으면 sedispatch가 자동으로 시작됨
seapplet 유틸리티는 시스템 도구 모음에서 실행
setroubleshootd의 dbus 메시지를 대기
알림 버블을 시작하여 사용자가 AVC 메시지를 확인 할수 있도록 지원
- daemon 자동 시작
auditd 및 rsyslog 데몬을 자동시작 하려면, root 다음의 명령어 실행
~]#
systemctl enable auditd.service
~]#
systemctl enable rsyslog.service
정확한 동작 확인
~]$
systemctl is-enabled auditd
enabled
~]$
systemctl is-enabled rsyslog
enabled
systemctl status service-name.service 명령을 사용해서 enabled 검색
~]$
systemctl status auditd.service | grep enabled
auditd.service - Security Auditing Service Loaded: loaded (/usr/lib/systemd/system/auditd.service; enabled)
systemd 데몬 시스템 서비스를 관리하는 방법은 다음 링크에서 확인
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/index.html
- 주요 설정 파일
/etc/selinux/config 주요 SELinux 설정 파일
SELinux 모드 및 SELinux 정책을 관리
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
SELINUX = enforcing
SELinux는 enforcing, permissive, disabled 세가지 모드
enforcing - SELinux 정책이 적용, SELinux 정책 규칙에 따라 SELinux는 액세스를 거부, 거부메시지가 기록
permissve - SELinux 정책이 적용되지 않음, ecforcing모드에서 거부되는 동작은 기록됨
disabled - SELinux 비활성화된 SELinux, 모듈이 Linux 커널에 등록되지 않음, DAC 규칙만 사용
SELINUXTYPE = targeted
SELINUXTYPE 옵션은 사용하는 SELinux 정책을 설정
대상 정책이 기본 정책
MLS 정책을 사용하는 경우에만 옵션을 변경
MLS 정책의 활성화에 대해선 https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/mls.html#enabling-mls-in-selinux 참조
중요!!!
SELinux 모드중 permissive, disabled 모드에서 시스탬이 실행하게되면, 파일에 잘못된 레이블을 하는 권한이 있음
SELinux를 사용하지 않는동안 생성된 파일에는 레이블이 없음
enforcing 모드로 변경하면 이것이 문제가 될수 있음
표시가 잘못된 파일과, 레이블이 없는 파일이 문제를 일으키지 않게하기위해 disabled모드에서 permissive 모드와 enforcing 모드로 변경하면 파일시스탬에서 자동으로 재 분류가 진행
- SELinux 활성화 및 비 활성화
SELinux 상태를 확인하려면, setenforce 또는 sestatus 명령을 사용, getenforce 명령은 enforcing, pemissive, disabled 중 하나를 반환
sestatus 명령은 SELinux 상태 및 사용된 SELinux 정책을 반환
~]$
sestatus
SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file: targeted
PS.
시스템을 처음 설치시 SELinux가 없을시, 특히 selinux-policy 패키지업이 설치된 경우 SELinux를 활성화 하려면 추가 작업이 필요
dracut 유틸리티를 실행, initramfs 파일 시스템에 SELinux를 기재해야 함
SELinux가 비활성화 되어있는경우 /etc/selinux/config 에 SELINUX = disabled 설정이 되어 있음
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
getenforce 명령을 하면 disabled을 반환
~]$
getenforce
Disabled
다음 단계에서 SELinux를 사용
- SELinux의 활성화
다음의 패키지가 설치되어 있다는것을 전제로 진행
selinux-policy-targeted, selinux-policy, libselinux, libselinux-python, libselinux-utils, policycoreutils, policycoreutils-python, setroubleshoot, setroubleshoot-server, setroubleshoot-plugins
rpm 명령어로 확인
~]$
rpm -qa | grep selinux
selinux-policy-3.12.1-136.el7.noarch libselinux-2.2.2-4.el7.x86_64 selinux-policy-targeted-3.12.1-136.el7.noarch libselinux-utils-2.2.2-4.el7.x86_64 libselinux-python-2.2.2-4.el7.x86_64
~]$
rpm -qa | grep policycoreutils
policycoreutils-2.2.5-6.el7.x86_64 policycoreutils-python-2.2.5-6.el7.x86_64
~]$
rpm -qa | grep setroubleshoot
setroubleshoot-server-3.2.17-2.el7.x86_64 setroubleshoot-3.2.17-2.el7.x86_64 setroubleshoot-plugins-3.0.58-2.el7.noarch
설치되어 있지 않다면 yum 으로 설치 진행
~]#
yum install package_name
policycoreutils-gui, setroubleshoot, mcstrans
SELinux를 사용하기전에 파일시스템에 있는 모든 파일을 SELinux 문맥으로 레이블 해야함, 위의 작업이 완료되지 않으면 제한된 도메인 액세스가 거부될수 있음, 시스탬의 정상 부팅을 방해
이를 방지하려면 /etc/selinux/config 파일에서 SELINUX = permissive 설정
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=permissive # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
시스탬을 다시시작, 이 과정에서 파일 시스템 레이블이 지정됨, 이 라벨 과정에서 모든 파일에 SELinux 문맥이 분류
~]#
reboot
*** Warning -- SELinux targeted policy relabel is required. *** Relabeling could take a very long time, depending on file *** system size and speed of hard drives. ****
* 는 1000을 의미함
ex) **** 로 분류된 파일은 4000 파일을 나타냄
모든 파일에 레이블을 지정하는 시간은 파일수, 하드드라이브 속도에 따라 달라짐, 최신의 범용적인 시스탬에서는 대략 10분정도 소요
1차로 permissive 모드에서 검증을 하고 해당 모드에서 거부관련 로그가 없을때에 enforcing 모드로 변경
시스탬 시작시 SELinux가 액세스를 거부한 경우
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/chap-Security-Enhanced_Linux-Troubleshooting.html
확인 필요
~]#
grep "SELinux is preventing" /var/log/messages
/var/log/messages 파일에 거부 메시지가 없다면 /etc/selinux/config 에서 enforcing으로 설정
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
시스탬을 다시 시작하여 getenforce 에서 enforcing이 반환되는것을 확인
~]$
getenforce
Enforcing
root 로 SELinux 및 Linux 사용자 사이의 매핑을 확인, 출력은 다음과 같이 확인가능
~]#
semanage login -l
Login Name SELinux User MLS/MCS Range Service __default__ unconfined_u s0-s0:c0.c1023 * root unconfined_u s0-s0:c0.c1023 * system_u system_u s0-s0:c0.c1023 *
이러한 출력이 되지 않는다면 root 다음과 같은 명령을 실행해서 사용자 매핑을 수정
SELinux-user username is already defined 경고는 무시
username은 unconfined_u, guest_u, xguest_u 중 하나임
- 사용자 매핑 변경
~]#
semanage user -a -S targeted -P user -R "unconfined_r system_r" -r s0-s0:c0.c1023 unconfined_u
~]#
semanage login -m -S targeted -s "unconfined_u" -r s0-s0:c0.c1023 __default__
~]#
semanage login -m -S targeted -s "unconfined_u" -r s0-s0:c0.c1023 root
~]#
semanage user -a -S targeted -P user -R guest_r guest_u
~]#
semanage user -a -S targeted -P user -R xguest_r xguest_u
- SELinux 의 비활성화
/etc/selinux/config 파일의 SELINUX=disabled 변경
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
시스탬을 다시 시작하여 getenforce 명령이 disabled 을 반환하는지 확인
~]$
getenforce
Disabled
ㅁ booleans
booleans 을 사용하면 SELinux 정책 기술의 지식이 없이도 런타임시에 SELinux 정책의 일부를 변경이 가능
SELinux 정책을 다시 로드하거나 다시 컴파일 하지 않고, NFS 볼륨에 서비스를 허용하는 액세스를 변경하는것등이 가능함
- booleans 목록
root 로 semanage boolean -l 명령을 실행, 다음의 예시는 모든 booleans 값이 표시되는것이 아니며, 출력은 생략되어 있음
~]#
semanage boolean -l
SELinux boolean State Default Description ftp_home_dir (off , off) Determine whether ftpd can read... smartmon_3ware (off , off) Determine whether smartmon can... mpd_enable_homedirs (off , off) Determine whether mpd can traverse...
SELinux boolean - boolean 이름을 표시
Description - boolean 이 활성화 인지 비 활성화 인지, 무엇을 할것인지에 대해 표시
다음의 예시는 ftp_home_dir boolean off 에서 ftp 데몬 (vsftpd)가 사용자의 홈디렉토리에 있는 파일에 읽기/쓰기를 하지 않도록 되어 있음
ftp_home_dir (off , off) Determine whether ftpd can read...
getsetbool -a 명령은 boolean 값을 나열하고, 선택 여보를 표시하지만 개별 설명은 나오지 않음
~]$
getsebool -a
cvs_read_shadow --> off daemons_dump_core --> on ftp_home_dir --> off
getsebool boolean-name 실행하면 boolean-name 상태만을 나열
~]$
getsebool cvs_read_shadow
cvs_read_shadow --> off
여러 boolean 값을 표시하려면 공백으로 목록을 구분
~]$
getsebool cvs_read_shadow daemons_dump_core ftp_home_dir
cvs_read_shadow --> off daemons_dump_core --> on ftp_home_dir --> off
- boolean 설정
setsebool 유틸리티로 setsebool boolean_name on/off 형식으로 실행
다음의 예시는 httpd_can_network_connect_db의 boolean 설정을 표시
httpd_can_network_connect_db boolean이 off이며, Apache http server 스크립트와 모듈이 데이터베이스 서버에 연결할 수 없도록 되어있음
~]$
getsebool httpd_can_network_connect_db
httpd_can_network_connect_db --> off
Apache http server 스크립트와 모듈이 일시적으로 데이터베이스 서버에 연결할 수 있도록 하려면 root 다음과 같은 명령어 실행
~]#
setsebool httpd_can_network_connect_db on
boolean 값이 설정되어 있는지 확인하려면 getsebool 유틸을 사용
~]$
getsebool httpd_can_network_connect_db
httpd_can_network_connect_db --> on
이제 apache http server 스크립트 및 모듈이 데이터베이스 서버에 연결이 가능
해당 변경 내용은 유지되는 내용이 아님, 재부팅 이후에도 변경을 유지하려면 root로 setsebool -P boolean-name on 명령을 실행
~]#
setsebool -P httpd_can_network_connect_db on
- shell의 자동 완성 기능
getsebool, setsebool, semanage는 shell의 자동완성 기능을 사용가능
getsebool 및 setsebool 에서는 명령줄 매개변수 및 boolean 값으로 자동완성 기능을 사용할수 있음
명령줄 매개 변수만 나열하려면 명령이름 뒤에 하이픈 기호를("-") 지정하고 tab을 사용
~]#
setsebool -[Tab]
-P
boolean 자동완성 기능을 사용하려면 boolean 이름을 입력을 시작하고 tab 키를 입력
~]$
getsebool samba_[Tab]
samba_create_home_dirs samba_export_all_ro samba_run_unconfined
samba_domain_controller samba_export_all_rw samba_share_fusefs
samba_enable_home_dirs samba_portmapper samba_share_nfs
~]#
setsebool -P virt_use_[Tab]
virt_use_comm virt_use_nfs virt_use_sanlock
virt_use_execmem virt_use_rawip virt_use_usb
virt_use_fusefs virt_use_samba virt_use_xserver
semanage 유틸리티는 여러 명령줄 인수로 사용되며, 이들은 하나씩 작섣됨
semanage 명령의 첫 번째 인수는 옵션에서 SELinux 정책의 어떤 부분을 관리하는 방법을 지정
~]#
semanage [Tab]
boolean export import login node port
dontaudit fcontext interface module permissive user
이후에 명령줄 매개 변수가 계속됨
~]#
semanage fcontext -[Tab]
-a -D --equal --help -m -o
--add --delete -f -l --modify -S
-C --deleteall --ftype --list -n -t
-d -e -h --locallist --noheading --type
~]#
semanage fcontext -a -t samba<tab> samba_etc_t samba_secrets_t sambagui_exec_t samba_share_t samba_initrc_exec_t samba_unconfined_script_exec_t samba_log_t samba_unit_file_t samba_net_exec_t
~]#
semanage port -a -t http_port_t -p tcp 81
- SELINUX 파일의 레이블 context
SELinux 실행중인 시스탬에서 모든 프로세스와, 파일에 라벨을 붙일수 있음
SELinux context 라고 지칭
ls -Z 명령어로 확인가능
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
SELinux 사용자의 unconfined_u -> role, object_r type, user_home_t의 level(s0) 을 확인
이 정보는 접근 제한 결정에 사용
DAC는 Linux UID, GID에 따라 제어됨
SELinux 정책 규칙은 DAC 규칙 이후에 확인
DAC 규칙이 먼저 액세스를 거부하면 SELinux 정책은 사용되지 않음
- note
기본적으로 파일 및 디렉토리는 부모 디렉토리의 SELinux 유형을 상속
/etc/ 디렉토리에 새파일을 작성하면 etc_t 유형의 레이블을 상속
~]$ ls -dZ - /etc/
drwxr-xr-x. root root system_u:object_r:etc_t:s0 /etc
~]# touch /etc/file1
~]# ls -lZ /etc/file1
-rw-r--r--. root root unconfined_u:object_r:etc_t:s0 /etc/file1
SELinux context를 관리하는 명령어에는 chcon, semanage fcontext, restorecon 등이 있음
- chmod 임시로 변경
chmod 로 SELinux context 를 수정, chcon 명령에 의한 변경 내용은 시스템 레이블 혹은 restorecon 명령이 실행될때에 유지되지 않음
SELinux 정책은 특정 파일의 SELinux context 를 사용자가 수정할수 있는지 여부를 제어
chcon을 사용하면 사용자는 변경된 SELinux context 일부 혹은 전부를 제공, SELinux 작업이 안되는경우 파일 형식이 잘못되어 있을수 있음
chcon -t type file-name -> file type
file-name은 파일이 될수도 있고 디렉토리도 될수 있음, file-name의 selinux type을 httpd_sys_content_t 로 변경하는 예
~]$
chcon -t httpd_sys_content_t file-name
~]$
chcon -R -t httpd_sys_content_t directory-name
4.6 파일과 디렉토리 type 변경
home 디렉토리에 들어가서 파일을 생성호 SELinux 를 확인
~]$
touch file1
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
file1 은 unconfined_u user, object_r role, user_home_t type으로 되어 있으며, s0의 level을 가지고 있음
chcon 명령어를 이용해서 samba_share_t type으로 type을 변경 옵션은 -t 를 사용
~]$
chcon -t samba_share_t file1
~]$
ls -Z file1
-rw-rw-r-- user1 group1 unconfined_u:object_r:samba_share_t:s0 file1
restorecon -v 를 이용해서 SELinux를 복구
~]$
restorecon -v file1
restorecon reset file1 context unconfined_u:object_r:samba_share_t:s0->system_u:object_r:user_home_t:s0
4.7 디렉토리 및 그 및의 contents type 변경
/web 디렉토리 생성후 file1, 2, 3을 /web/ 에 생성 files의 기본 label은 default_t type
~]#
mkdir /web
~]#
touch /web/file{1,2,3}
~]#
ls -dZ /web
drwxr-xr-x root root unconfined_u:object_r:default_t:s0 /web
~]#
ls -lZ /web
-rw-r--r-- root root unconfined_u:object_r:default_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:default_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:default_t:s0 file3
root 로 /web/ 디렉토리에 httpd_sys_content_t type으로 변경
~]#
chcon -R -t httpd_sys_content_t /web/
~]#
ls -dZ /web/
drwxr-xr-x root root unconfined_u:object_r:httpd_sys_content_t:s0 /web/
~]#
ls -lZ /web/
-rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file3
restorecon 으로 원상복구
~]#
restorecon -R -v /web/
restorecon reset /web context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:default_t:s0 restorecon reset /web/file2 context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:default_t:s0 restorecon reset /web/file3 context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:default_t:s0 restorecon reset /web/file1 context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:default_t:s0
semanage fcontext 명령어로 SELinux context를 수정 /etc/selinux/targeted/contexts/files/
semanage fcontext SELinux context of files을 수정
/etc/selinux/targeted/contexts/files/ directory에 생성
~]#
semanage fcontext -a options file-name|directory-name
~]#
restorecon -v file-name|directory-name
~]#
touch /etc/file1
~]$
ls -Z /etc/file1
-rw-r--r-- root root unconfined_u:object_r:etc_t:s0 /etc/file1
~]$
ls -dZ directory_name
~]#
semanage fcontext -a -t samba_share_t /etc/file1
~]#
ls -Z /etc/file1
-rw-r--r-- root root unconfined_u:object_r:etc_t:s0 /etc/file1
/etc/file1 unconfined_u:object_r:samba_share_t:s0
~]#
restorecon -v /etc/file1
restorecon reset /etc/file1 context unconfined_u:object_r:etc_t:s0->system_u:object_r:samba_share_t:s0
~]#
mkdir /web
~]#
touch /web/file{1,2,3}
~]#
ls -dZ /web
drwxr-xr-x root root unconfined_u:object_r:default_t:s0 /web
~]#
ls -lZ /web
-rw-r--r-- root root unconfined_u:object_r:default_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:default_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:default_t:s0 file3
~]#
semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?"
~]$
ls -dZ /web
drwxr-xr-x root root unconfined_u:object_r:default_t:s0 /web
~]$
ls -lZ /web
-rw-r--r-- root root unconfined_u:object_r:default_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:default_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:default_t:s0 file3
/web(/.*)? system_u:object_r:httpd_sys_content_t:s0
~]#
restorecon -R -v /web
restorecon reset /web context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /web/file2 context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /web/file3 context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0 restorecon reset /web/file1 context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
~]#
semanage fcontext -d "/web(/.*)?"
~]#
semanage fcontext -d file-name|directory-name
/test system_u:object_r:httpd_sys_content_t:s0
~]#
semanage fcontext -d /test
'Security > Linux - Selinux' 카테고리의 다른 글
selinux 03 (0) | 2016.08.01 |
---|---|
selinux 01, 02 (0) | 2016.06.30 |