SELinux 란?
- Security Enhanced Linux
- 과거 linux의 보안을 강화하고 보완한 것
- 커널(Kernel)을 보호하기 위한 '도구'이고 리눅스 커널에 내장된 보안모듈
- 강제적 접근 제어(Mandantory Access Control Mac)을 수행 , 오직 필요한 기능에 대해서 사용권한을 안전하게 부여하는 것이 가능
SELinux 동작모드
- enforcing : 강제
- permissive : 허용
- disabled : 비활성화
setenforce 0 // permissive
setenforce 1 // enforcing
getenforce // SeLinux 설정값을 출력하는 명령어
* disabled는 vi 편집기로 /etc/sysconfig/selinux 파일을 편집으로 설정 가능함.
$ sed 's/SEL.*/SELINUX=disabled
* ps명령어 (OPTION : -ef )
- grep 명령 활용하여 ssh 프로세스 출력
ps [option] [ps name/number]
// option
-e // 모든 프로세스를 출력
-f // 풀 포맷으로 출력(UID, PID)
-l // 긴 포맷으로 출력
p, -p // 특정 PID의 프로세스 출력
-u // 특정 사용자의 프로세스 출력
// selinux 보안옵션이 적용되어 있는 지 확인 (프로세스)
docker ps -ef | grep docker | grep selinux-enabled
// selinux 보안옵션이 적용되어 있는지 확인 (명령어)
docker ps --quiet --all | xargs docker inspect --format "{{ .Id }}: SecurityOpt={{ .HostConfig.SecurityOpt }}"
// pkg 현행화
sudo apt update
// apparmor 정지 & 비활성화 & 제거
systemctl status apparmor
sudo systemctl stop apparmor
sudo systemctl disable apparmor
// SELinux 설치
sudo apt install policycoreutils selinux-basics selinux-utils -y
// SELinux enable
sudo selinux-activate
// reboot
sudo reboot
(여기서 재부팅 시 오랜 시간이 소요됨)
// config 파일 접근
cat /etc/selinux/config
# 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 <--------------------- permissive를 enforcing 으로 변경해야함 *selinux를 끌 경우 disabled로 저장 후, sudo reboot 하면 됨
# SELINUXTYPE= can take one of these two values:
# default - equivalent to the old strict and targeted policies
# mls - Multi-Level Security (for military and educational use)
# src - Custom policy built from source
SELINUXTYPE=default
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0
// permissive를 enforcing 으로 변경하기 위해선 config 파일이 읽기전용인지라 권한변경을 해야함
// root 계정으로 변경후 권한변경진행
sudo su - root
chmod 755 config
// 편집모드에서 변경해줌
vi config
// sestatus 명령어로 enabled 확인
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: default
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: requested (insecure)
Max kernel policy version: 31
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9e7fb156b01 redis:7.0.7 "docker-entrypoint.s…" 7 weeks ago Exited (0) 2 hours ago cg-dev-redis
c35ea4c77285 mariadb:10.3.31 "docker-entrypoint.s…" 7 months ago Exited (0) 2 hours ago mariadb-demo
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ docker ^C
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ docker start d9e7fb156b01
d9e7fb156b01
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d9e7fb156b01 redis:7.0.7 "docker-entrypoint.s…" 7 weeks ago Up 3 seconds 0.0.0.0:6379->6379/tcp cg-dev-redis
c35ea4c77285 mariadb:10.3.31 "docker-entrypoint.s…" 7 months ago Exited (0) 2 hours ago mariadb-demo
ncloud@org-insight-cg-dev-ssd-c4-m8:~$ sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: default
Current mode: permissive
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: requested (insecure)
Max kernel policy version: 31
ncloud@org-insight-cg-dev-ssd-c4-m8:~$
참고사이트
https://www.linode.com/docs/guides/how-to-install-selinux-on-ubuntu-22-04/
https://linuxconfig.org/how-to-disable-enable-selinux-on-ubuntu-20-04-focal-fossa-linux
'IT Infra' 카테고리의 다른 글
[Docker] 기초정리 (2) (0) | 2023.06.16 |
---|---|
[Docker] command 입력방법 (0) | 2023.06.16 |
리눅스(Linux), 커널(Kernel), 우분투(Ubuntu) (0) | 2023.06.15 |
[Docker] 기초 정리 (1) | 2023.06.14 |
PUTTY (0) | 2023.03.31 |