Wisdom’s Cloud

[Linux][CentOS] Failed to load SELinux policy, freezing. 본문

LINUX/Advanced

[Linux][CentOS] Failed to load SELinux policy, freezing.

지혜로운지혜쓰 2022. 8. 31. 11:24

리눅스를 부팅하다가 위와 같은 에러 메시지를 마주하게 된다면, 바로 /etc/selinux/config 파일 설정이 잘못된 경우다.

 

 

 

그렇다면 에러 메시지에 나오는 SELinux가 무엇일까? SELinux에 대해 먼저 알아보자.

SELinux(Security-Enhanced Linux)란?

 

SELinux는 말 그대로 보안이 향상된 리눅스이다.

원래는 사용자, 그룹 및 기타 권한을 기반으로 접근 권한을 부여하는 DAC(Discretionary Access Control)를 사용하여 세분화된 보안 정책을 생성할 수 없었다.

하지만 SELinux는 MAC(Mandatory Access Control)를 사용하여 모든 프로세스 및 시스템 리소스에 SELinux 컨텍스트라는 특수 보안 레이블을 통해 세분화된 보안 정책을 생성할 수 있다.

 

이러한 SELinux는 enforcing, permissive, disabled의 3가지 모드 중 하나로 실행된다.

 

  • SELINUX=enforcing을 사용하면 SELinux 정책이 적용되어 SELinux 정책 규칙을 기반으로 액세스를 거부한다.
  • SELINUX=permissive을 사용하면 SELinux 정책이 적용되지 않고 거부된 작업을 로깅만 한다.
  • SELINUX=disabled을 사용하면 SELinux가 완전히 비활성화된다.

 

아래와 같이 setenforce 명령어를 사용하여 SELinux 모드를 변경하고, getenforce 명령어로 확인할 수 있다. 그리고 더 자세한 정보를 얻으려면 sestatus 명령어를 사용하면 된다.

[root@test-node-1 ~]# setenforce 0
[root@test-node-1 ~]# getenforce
Permissive
[root@test-node-1 ~]# 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:      3

[root@test-node-1 ~]# setenforce 1
[root@test-node-1 ~]# getenforce
Enforcing
[root@test-node-1 ~]# 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:      31

 

하지만 SELinux 모드를 영구적으로 변경하기 위해서는 이 /etc/selinux/config 파일을 편집해야 한다.

/etc/selinux/config

 

/etc/selinux/config 파일은 기본 SELinux 구성 파일로, SELinux의 활성화 여부와 사용되는 SELinux 모드 및 정책을 제어한다.

SELINUX 옵션은 위에서 설명한 SELinux 모드를 설정하고, SELINUXTYPE 옵션은 사용할 SELinux 정책을 설정한다.

targeted가 기본 정책이고, mls 정책을 사용하면 단계별 보안 수준을 통해 더 세세하게 보안 정책을 적용할 수 있다.

# 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와 /etc/selinux/config 파일에 대해 알아봤으니, 다시 문제의 상황으로 돌아와보자.

일단 정상적으로 부팅이 되지 않기 때문에 아래와 같이 부팅 메뉴가 나오면 e 키를 눌러 부팅 옵션을 편집한다.

 

 

fi 부분의 맨 끝에 selinux=0 옵션을 추가한 후, Ctrl + x를 눌러 재부팅한다.

이 옵션은 설치 관리자 및 설치된 시스템에서 SELinux 사용을 완전히 비활성화하기 때문에 커널이 SELinux 인프라의 일부를 로드하지 않게 한다.

 

 

재부팅이 되었다면 문제의 /etc/selinux/config 파일을 확인해보자.

CentOS Linux 7 (Core)
Kernel 3.10.0-1160.el7.x86_64 on an x86_64

test-node-1 login: root
Password:
Last login: Wed Aug 31 11:29:13 on ttyS0
[root@test-node-1 ~]# vi /etc/selinux/config

 

 

바로 SELINUXTYPE 옵션의 오타 때문에 Failed to load SELinux policy, freezing. 에러가 발생한 것이다.

오타를 수정하고 다시 재부팅을 해보면 정상적으로 부팅되는 것을 확인할 수 있다 😃

 

 

 

[참고 문서]

https://access.redhat.com/documentation/ko-kr/red_hat_enterprise_linux/7/html/installation_guide/chap-anaconda-boot-options

 

23장. 부팅 옵션 Red Hat Enterprise Linux 7 | Red Hat Customer Portal

Access Red Hat’s knowledge, guidance, and support through your subscription.

access.redhat.com

https://access.redhat.com/documentation/ko-kr/red_hat_enterprise_linux/7/html-single/selinux_users_and_administrators_guide/index

 

SELinux 사용자 및 관리자 가이드 Red Hat Enterprise Linux 7 | Red Hat Customer Portal

이 문서는 다음 두 부분으로 구성되어 있습니다. SELinux및 제한된 서비스 관리. 전자는 SELinux 기능을 사용하는 기본 원리와 원칙을 설명하고, 후자는 다양한 서비스를 설정하고 구성하는 실용적

access.redhat.com