[ Server ][ Linux ] CentOS 7 SELinux 설정 및 해제하기 > linux

본문 바로가기
사이트 내 전체검색

linux

[ Server ][ Linux ] CentOS 7 SELinux 설정 및 해제하기

페이지 정보

작성자 웹지기 댓글 0건 조회 23,215회 작성일 18-12-13 15:17

본문

SELinux 는 Linux의 보안을 강화해 주는 보안 강화 커널이고 zero-day 공격 및 buffer overflow 등 어플리케이션 취약점으로 인한 해킹을 방지해 주는 핵심 구성요소이다.

특정 서비스가 SELinux 때문에 동작하지 않는다면 SELinux 를 끄기 보다는 해당 서비스가 SELinux 하에서 잘 동작하도록 설정을 수정하는걸 권장한다.


SELinux 동작 모드

    enforce, permissive, disable 세 가지 모드가 있으며 RHEL/CentOS 를 설치하면 default 로 enforce mode 로 동작하며 SELinux 의 rule 에 어긋나는 operation 은 거부된다.

    현재 SELinux 의 동작 모드는 sestatus 명령어로 확인할 수 있다.

    SELinux 모드 확인

# sestatus

SELinux status: enabled

SELinuxfs mount: /selinux

Current mode: enforcing

Mode from config file: enforcing

Policy version: 24

Policy from config file: targeted


    Permissive mode 는 rule 에 어긋나는 동작이 있을 경우 audit log 를 남기고 해당 operation 은 허용된다.

    개발 서버일 경우 특정 daemon 이나 서비스에 문제가 있을 경우 setenforce 0 으로 Permissive mode 로 전환하여 문제 해결후 enforce mode 로 전환하는걸 추천한다.


# setenforce 0

# sestatus

     

SELinux status: enabled

SELinuxfs mount: /selinux

Current mode: permissive

Mode from config file: enforcing

Policy version: 24

Policy from config file: targeted


SELinux 해제

    인터넷에 연결된 리눅스 서버라면 SELinux 해제는 결코 추천하지 않는다.

    해제할 경우 다시 활성화 시키려면 재부팅이 필요하며 재부팅시 모든 자원에 대해 보안 레이블을 설정해야 하므로 부팅 시간이 매우 오래 걸릴 수 있다.

vi /etc/sysconfig/selinux

SELINUX=enforcing 을 SELINUX=disabled 로 변경후 저장한다.

reboot

    SELinux 를 해제후 다시 켤 경우 relabel 이 필요하며 이때 잘못된 설정이 있을 경우 부팅이 안 되거나 ssh 로 원격 접속이 불가능할 수 있으므로 enforcing 모드가 아닌 permissive 로 설정후 재부팅하는 것을 권장한다.


File Context 보기

semanage fcontext -l|grep mysql

 
-------------------------------------------------------------------------------------------------------------------
 
표준 리눅스 보안은 임의 접근 제어(Discretionary Access Control - DAC) 모델을 따릅니다.
SELinux는 Linux 커널에 내장된 보안 모듈로 강제적 접근 제어(Mandatory Access Control - MAC)를 수행합니다.
응용프로그램에서 불필요한 부분은 제외하고 오직 필요한 기능에 대해서만 사용 권한을 안전하게 부여하는 것이 가능합니다.
따라서 사용자는 한 응용 프로그램에게 그 프로그램이 제대로 작동하는데 필요한 권한만 안전하게 부여할 수 있습니다.

OS 설치 후 SELinux는 기본적으로 적용(Enforcing) 상태로 되어있습니다.
아래 명령들을 통해 현재 서비스 상태를 확인할 수 있습니다.

[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28
 
SELinux가 필요하지 않은 경우 /etc/selinux/config 또는 /etc/sysconfig/selinux를 수정하여 영구적으로 비활성화 시킬 수 있습니다.
(/etc/sysconfig/selinux -> /etc/selinux/config 심볼릭 링크되어 있어 어느 파일을 편집하든 /etc/selinux/config 파일이 수정됩니다.)
 

[root@localhost ~]# ls -alh /etc/selinux/config
-rw-r--r--. 1 root root 547 Apr  6 17:59 /etc/selinux/config
[root@localhost ~]# ls -alh /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 Apr  6 17:59 /etc/sysconfig/selinux -> ../selinux/config
[root@localhost ~]# stat /etc/sysconfig/selinux
  File: ‘/etc/sysconfig/selinux’ -> ‘../selinux/config’
  Size: 17              Blocks: 0          IO Block: 4096   symbolic link
Device: 803h/2051d      Inode: 201612989   Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2017-04-17 10:46:35.397430689 +0900
Modify: 2017-04-06 17:59:38.412377900 +0900
Change: 2017-04-06 17:59:38.412377900 +0900
 Birth: -

수정을 위해 /etc/selinux/config 파일을 vi 편집기로 편집하겠습니다.
[root@localhost ~]# vi /etc/selinux/config

SELINUX=enforcing을 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 three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
수정 후 시스템을 재시작해야 정상적으로 적용됩니다.

[root@localhost ~]# reboot
시스템을 바로 재시작하기 어려운 경우 setenforce 0 명령을 이용해 일시적으로 비활성화할 수 있습니다.(SELINUX=permissive)

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# 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:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28
다시 사용이 필요한 경우 setenforce 1 명령을 이용해 활성화할 수 있습니다.(SELINUX=enforcing)

(영구적으로 활성화가 필요한 경우 /etc/selinux/config 파일에 SELINUX=enforcing으로 수정하시기 바랍니다.)

[root@localhost ~]# setenforce 1
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28
각 옵션에 대한 설명은 아래를 참조하시기 바랍니다.

- When using SELINUX=enforcing,

SELinux policy is enforced, and SELinux denies access based on SELinux policy rules. Denial messages are logged.
- When using SELINUX=permissive,

SELinux policy is not enforced. SELinux does not deny access, but denials are logged for actions that would have been denied if running SELinux in enforcing mode.
- When using SELINUX=disabled,

SELinux is disabled, the SELinux module is not registered with the Linux kernel, and only DAC rules are used.

[원글링크]https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/SELinux_Users_and_Administrators_Guide/sect-Security-Enhanced_Linux-Working_with_SELinux-Main_Configuration_File.html


SELinux를 사용한다면 정책 설정이 필요합니다.

1. getsebool

getsebool BOOLEAN 또는 getsebool -a 명령을 통해 정의된 정책 및 정책 설정 상태를 확인할 수 있습니다.

[root@localhost ~]# getsebool ftpd_anon_write
ftpd_anon_write --> off
[root@localhost ~]# getsebool -a
abrt_anon_write --> off
abrt_handle_event --> off
abrt_upload_watch_anon_write --> on
antivirus_can_scan_system --> off
antivirus_use_jit --> off
 
......(중략)
 
zabbix_can_network --> off
zarafa_setrlimit --> off
zebra_write_config --> off
zoneminder_anon_write --> off
zoneminder_run_sudo --> off

2. setsebool

setsebool -P BOOLEAN on/off 명령을 통해 정책을 설정할 수 있습니다.
[root@localhost ~]# getsebool ftpd_anon_write
ftpd_anon_write --> off
[root@localhost ~]# setsebool -P ftpd_anon_write on
[root@localhost ~]# getsebool ftpd_anon_write
ftpd_anon_write --> on
SELinux는 보안 정책 설정이 복잡하고 방화벽을 통해 따로 접근제어를 하기 때문에
보통 서버 OS 설치 후 바로 비활성화를 합니다.
하지만 잘 알고 사용하면 보안 및 접근제어를 강화할 수 있습니다. 
추천0 비추천0

댓글목록

등록된 댓글이 없습니다.

Total 103건 1 페이지
  • 102 [ server ][ linux ][ CentOS7 ] nginx 설치 및 방화벽 설정
  • 1) yum 외부저장소에 nginx 추가(nginx 관련사항이 없으니 추가해줘야 함) >> vi /etc/yum.repos.d/nginx.repo nginx.repo 파일 내용( CentOS7 기준 - 버젼별로 다를 수 있으니 다른버젼은 공식사이트 이용 ) [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 2) nginx ...
  • 웹지기 02-04 5710 0 0 댓글 0
  • 101 [ server ][ linux ] cmd 이용 shell 접속 ( cmd ssh )방법 ( 윈도우에서 cm…
  • 쉘접속 프로그램이 있으면 좋은데, cmd에서 그냥 접속하고 싶다면, 윈도우라면 cmd를 이용해서 접속을 하면 되고, 리눅스라면 cmd라인에서 바로 명령을 입력하면 된다. # telnet 192.168.0.1 { port } 일반적으로 이런식으로 접속을 하면 된다. ssh로 접속을 하고 싶다면 # ssh -p { port } { 계정 }@192.168.0.1 이런식으로 접속을 하면 된다.
  • 웹지기 06-08 10867 0 0 댓글 0
  • 100 [ server ][ linux ][ gitlab ] 원격 저장소 url 변경
  • # git remote -v # origin http://gitlab.com/sample/sample.git (fetch) # origin http://gitlab.com/sample/sample.git (push) 확인을 해본 다음 다음의 명령어로 변경이 가능하다 # git remote set-url origin ssh://git@gitlab.com/sample/sample.git 다시 확인을 해보면 # git remo...
  • 웹지기 06-01 8083 0 0 댓글 0
  • 99 [ server ][ linux ] CentOS7 certbot certificates 오류 ttribute…
  • # certbot certificates 이런명령을 내렸는데 오류가 발생햇다 yum update하면서 무언가 문제가 발생한것 같다. An unexpected error occurred: AttributeError: 'module' object has no attribute 'TLSSNI01' Please see the logfile '/tmp/tmpV1KtqF/log' for more details. # yum update pyth...
  • 웹지기 03-12 7703 0 0 댓글 0
  • 96 [ Server ][ Linux ] CentOS7 firewall ( 방화벽 ) 관리
  • 방화벽 실행 여부 확인 # firewall-cmd --state #running 방화벽 다시 로드 # firewall-cmd --reload #success 존 ( zone ) 목록 출력 # firewall-cmd --get-zones #block dmz drop external home internal public trusted work 존 ( zone ) 기본존을 출력 # firewall...
  • 웹지기 12-24 6982 0 0 댓글 0
  • 95 [ Server ][ Linux ] CentOS7 라우팅 설정 ( vpn 연결 )
  • 장비의 구조도는 위와 같은 장비의 구조에서 한개의 회선은 기본인터넷(eno1)을 연결하는 회선이고 다른하나의 회선은 vpn연결(eno2)을 위한 회선이다 이러한 경우 default를 하나로 설정하고 다른 하나는 route를 통해 vpn회선을 연결한다. eno1번의 랜설정은 default로 설정되며 다음처럼 설정 ip 192.168.0.2 prefix 24 gw 192.168.0.1 eno2번의 랜설정은 ip 192.168.10.2 p...
  • 웹지기 12-18 6665 0 0 댓글 0
  • 94 [ Server ][ Linux ] CentOS7 네트워크 설정
  • 네트워크에 관련된 파일이 있는 곳으로 가서 확인해본다. # cd /etc/sysconfig/network-scripts # ll 현재 설정을 확인 할 수 있다. # route # ip address # netstat 네트워크 재시작 service network restart
  • 웹지기 12-17 5232 0 0 댓글 0
  • 93 [ Server ][ Linux ] CentOS7 telnet 설치 및 테스트
  • 설치 확인 # telnet #bash: telnet: command not found 이렇게 뜨면 텔넷이 설치가 안되어 있는 것이다. 설치해 주자 # yum -y install telnet # ....................................... #Installed: #telnet.x86_64 1:0.17-64.el7 #Complete! 정상 설치 되면 위처럼 뜬다. 실행해 보자 ...
  • 웹지기 12-17 9483 0 0 댓글 0
  • 92 [ Server ][ Linux ] CentOS7 콘쉘 ( ksh ) 설치
  • 현재 사용할 수 있는 쉘을 확인 chsh -l 명령을 통해 현재 사용가능한 쉘 목록 확인 # chsh -l #/bin/sh #/bin/bash #/usr/bin/sh #/usr/bin/bash 콘쉘 ( ksh )를 설치 #yum -y install ksh 사용할 수 있는 쉘을 다시 확인 # chsh -l #/bin/sh #/bin/bash #/usr/bin/sh #/usr/bin...
  • 웹지기 12-16 7118 0 0 댓글 0
  • 91 [ Server ][ Linux ] Gitlab 서버 도메인 변경
  • gitlab 서버의 도메인을 변경하고 싶다면 일단 검색을 한다. # find / -name gitlab.yml # /var/opt/gitlab/gitlab-rails/etc/gitlab.yml # /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml 이런 리스트에서 다음 파일에서 변경을 해준다. # vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml ...
  • 웹지기 12-12 8059 0 0 댓글 0
  • 90 [ Server ][ Linux ] CentOS7 Let's Encrypt 무료 SSL 인증서 와일드카드로 …
  • 입력시 일반 도메인(domain.com)과 와일드카드(*.domain.com) 도메인 두번 적는다 # certbot certonly --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory -d domain.com -d *.domain.com 이메일을 입력하라는 문구가 나오면 인증서 알림을 받을 이메일을 입력한다. # Saving debug log t...
  • 웹지기 12-12 5162 1 0 댓글 1
  • 89 [ Server ][ Linux ] CentOS7 htmlspecialchars 사용설정
  • htmlspecialchars 함수를 사용하기 위해서는 다음의 ini설정을 변경해 주어야 한다. php.ini filter.default, filter.default_flags 설정 AAI 멀티 버젼 같은 경우 각각의 PHP버젼별로 php.ini파일이 다르므로 검색을 해서 위치를 찾는다 # find / -name php.ini # /etc/opt/remi/php70/php.ini # /etc/opt/remi/php71/php.ini # /etc/opt/rem...
  • 웹지기 12-03 4849 0 0 댓글 0
게시물 검색

회원로그인

접속자집계

오늘
5,421
어제
6,915
최대
33,828
전체
8,110,115

그누보드5
Copyright © funyphp.com. All rights reserved.