설치 및 구성 > ThingWorx Docker 사용 > ThingWorx Docker에 대해 보안 강화 Linux 사용
ThingWorx Docker에 대해 보안 강화 Linux 사용
보안 강화 Linux(SELinux)는 다양한 Linux 배포에 추가된 커널 수정 및 사용자 공간 도구 집합입니다. SELinux 아키텍처를 사용하면 보안 결정의 적용을 보안 정책과 분리할 수 있어 보안 정책 적용과 관련된 소프트웨어의 수를 간소화할 수 있습니다. SELinux의 기본 개념은 미국 NSA(National Security Agency)의 몇 가지 이전 프로젝트로 거슬러 올라갈 수 있습니다.
SELinux 사용자 및 역할을 실제 시스템 사용자 및 역할과 연결할 필요는 없습니다. 모든 현재 사용자 또는 프로세스에 대해 SELinux는 사용자 이름, 역할 및 도메인(또는 유형)이 포함된 세 개의 문자열로 구성된 컨텍스트를 지정합니다. 이 시스템은 일반적으로 필요한 것보다 더 유연합니다. 일반적으로 대부분의 실제 사용자는 동일한 SELinux 사용자 이름을 공유하고 모든 액세스 제어는 세 번째 태그인 도메인을 통해 관리됩니다. 정책에서 특정 도메인으로의 프로세스를 허용하도록 환경을 구성해야 합니다. runcon 명령을 사용하여 명시적으로 지정된 컨텍스트(사용자, 역할 및 도메인)에서 프로세스를 시작할 수 있지만 정책에서 승인하지 않을 경우 SELinux가 전환을 거부할 수 있습니다.
파일, 네트워크 포트 및 기타 하드웨어에도 이름, 역할(거의 사용되지 않음) 및 유형이 포함된 SELinux 컨텍스트가 있습니다. 파일 시스템의 경우 파일과 보안 컨텍스트 간 매핑을 레이블 지정이라고 합니다. 레이블 지정은 정책 파일에 정의되지만 정책을 변경하지 않고 수동으로 조정할 수도 있습니다. 하드웨어 유형도 세부적으로 지정됩니다(예: bin_t(/bin 폴더의 모든 파일) 또는 postgresql_port_t(PostgreSQL 포트, 5432)). 마운트 시점에 원격 파일 시스템에 대한 SELinux 컨텍스트를 명시적으로 지정할 수 있습니다.
SELinux는 -Z 스위치를 셸 명령 ls, ps 및 기타 명령에 추가하여 파일 또는 프로세스의 보안 컨텍스트가 표시될 수 있도록 합니다.
일반적으로 정책 규칙은 사용자가 제공된 대상에 대해 특정 작업을 수행할 수 있으려면 소유해야 할 도메인과 같은 명시적 권한으로 구성됩니다. 이러한 작업의 예로는 읽기, 실행이 있으며 네트워크 포트의 경우 바인딩 또는 연결이 있습니다. 역할 및 보안 수준이 포함된 더 복잡한 매핑도 가능합니다.
일반 정책은 매핑(레이블 지정) 파일, 규칙 파일, 도메인 전환을 정의하는 인터페이스 파일로 구성됩니다. 단일 정책 파일을 생성하려면 SELinux 도구를 사용하여 이 세 파일을 컴파일해야 합니다. 결과 정책 파일을 커널에 로드하여 활성화할 수 있습니다. 정책 로드 및 언로드에는 재부팅이 필요하지 않습니다. 정책 파일은 수동으로 개발하거나 더 사용자 친화적인 SELinux 관리 도구에서 생성할 수 있습니다. 이러한 파일은 일반적으로 승인 모드에서 먼저 테스트됩니다. 이러한 모드에서는 위반이 로깅되지만 허용되지는 않습니다. 나중에 audit2allow 도구를 사용하여 제한된 응용 프로그램의 모든 적법한 작업을 허용하도록 정책을 확장하는 추가 규칙을 생성할 수 있습니다.
일반적인 SELinux 문제
SELinux의 가장 일반적인 문제는 SELinux가 작동하지 않음을 나타내는 권한 거부 문제입니다. 객체에 액세스하는 데 사용하는 사용자 자격 증명 또는 프로그램과 연관되지 않은 시스템 객체에 액세스하려고 하면 권한 거부 오류 메시지가 나타납니다. 이러한 오류는 해결하기 어렵지만 문제를 해결하는 데 도움을 주는 도구가 있습니다.
Setool 및 Setroubleshoot 설치
시스템에 이러한 도구를 설치하려면 다음을 수행하십시오.
1. 관리자 권한이 부여된 계정을 사용하여 서버 또는 데스크톱에 로그인합니다.
2. 명령 셸을 엽니다.
3. Yum을 사용하여 setroubleshoot 패키지를 설치합니다.
yum install setroubleshoot setools
SELinux 경고
sealert 도구를 사용하여 SELinux에 사용되는 감사 로그를 분석합니다. 이 도구는 로그 파일 및 보고서를 검색한 다음 검색된 모든 SELinux 문제가 포함된 보고서를 생성합니다.
명령줄에서 sealert를 실행하려면 SELinux 감사 로그를 가리키도록 지정합니다. 다음 예제를 참조하십시오.
sealert -a /var/log/audit/audit.log
보고서는 각 문제 및 문제를 해결하는 방법에 대해 설명합니다. 다음은 sealert가 생성한 출력 예제의 일부입니다.
100% done found 1 alerts in /var/log/audit/audit.log
--------------------------------------------------------------------------------
SELinux is preventing /usr/sbin/httpd from getattr access on the file
/myapps/app1/html/index.html.
***** Plugin catchall_labels (83.8 confidence) suggests ********************
If you want to allow httpd to have getattr access on the index.html file
Then you need to change the label on /myapps/app1/html/index.html
Do
# semanage fcontext -a -t FILE_TYPE '/myapps/app1/html/index.html'
where FILE_TYPE is one of the following: sssd_var_lib_t, public_content_t, anon_inodefs_t,
[..truncated..]
httpd_sys_ra_content_t, httpd_sys_rw_content_t, httpd_sys_rw_content_t,
httpd_w3c_validator_content_t.
Then execute:
restorecon -v '/myapps/app1/html/index.html'
***** Plugin catchall (17.1 confidence) suggests ***************************
If you believe that httpd should be allowed getattr access on the index.html file by
default. Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
문제를 해결하는 방법을 설명하는 보고서의 가장 중요한 부분은 각 경고의 끝에 나옵니다. 예를 들어, 위 보고서는 다음 솔루션을 보여줍니다.
If you believe that httpd should be allowed getattr access on the index.html file by
default. Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
제안된 솔루션은 문제가 되는 파일에 적용될 SELinux 정책을 만듭니다. 이 예제에서는 HTML 파일에 잘못된 SELinux 파일 컨텍스트가 지정되었습니다.
다음은 ThingWorx Docker 컨테이너에서 발생할 수 있는 잠재적인 문제를 보여주는 추가 예제입니다.
이 예제에서는 PostgreSQL과 관련된 문제를 보여줍니다. 이 경우 sealert가 다음 경고를 생성합니다.
found 1 alerts in /var/log/audit/audit.log
--------------------------------------------------------------------------------
SELinux is preventing /bin/chown from setattr access on the directory data.
***** Plugin catchall_labels (83.8 confidence) suggests *******************
If you want to allow chown to have setattr access on the data directory
Then you need to change the label on data
Do
# semanage fcontext -a -t FILE_TYPE 'data'
where FILE_TYPE is one of the following: cgroup_t, nfs_t, svirt_home_t,
svirt_sandbox_file_t.
Then execute:
restorecon -v 'data'

***** Plugin catchall (17.1 confidence) suggests **************************
If you believe that chown should be allowed setattr access on the data directory by
default. Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'chown' --raw | audit2allow -M my-chown
# semodule -i my-chown.pp

Additional Information:
Source Context system_u:system_r:svirt_lxc_net_t:s0:c459,c1008
Target Context unconfined_u:object_r:usr_t:s0
Target Objects data [ dir ]
Source chown
Source Path /bin/chown
Port <Unknown>
Host <Unknown>
Source RPM Packages
Target RPM Packages
Policy RPM selinux-policy-3.13.1-166.el7_4.9.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name ip-10-99-0-109.ec2.internal
Platform Linux ip-10-99-0-109.ec2.internal
3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20
20:32:50 UTC 2017 x86_64 x86_64
Alert Count 9
First Seen 2018-04-02 17:08:08 UTC
Last Seen 2018-04-02 17:08:27 UTC
Local ID 65bb52e5-bde9-4ec5-ba44-f0752ffef319
Raw Audit Messages
type=AVC msg=audit(1522688907.927:619): avc: denied { setattr } for pid=12142
comm="initdb" name="data" dev="nvme0n1p1" ino=826278009 scontext=system_u:system_r:
svirt_lxc_net_t:s0:c459,c1008 tcontext=unconfined_u:object_r:usr_t:s0 tclass=dir

type=SYSCALL msg=audit(1522688907.927:619): arch=x86_64 syscall=chmod success=no
exit=EACCES a0=5633eefb7310 a1=1c0 a2=0 a3=7f3c78d1d6a0 items=0 ppid=12116 pid=12142
auid=4294967295 uid=1001 gid=0 euid=1001 suid=1001 fsuid=1001 egid=0 sgid=0 fsgid=0
tty=(none) ses=4294967295 comm=initdb exe=/usr/lib/postgresql/9.4/bin/initdb
subj=system_u:system_r:svirt_lxc_net_t:s0:c459,c1008 key=(null)
Hash: chown,svirt_lxc_net_t,usr_t,dir,setattr
이 보고서는 다음과 같은 제안된 솔루션을 보여줍니다.
If you want to allow chown to have setattr access on the data directory
Then you need to change the label on data
Do
# semanage fcontext -a -t FILE_TYPE 'data'
where FILE_TYPE is one of the following: cgroup_t, nfs_t, svirt_home_t,
svirt_sandbox_file_t.
Then execute:
restorecon -v 'data'
다음은 이 솔루션을 구현하기 위해 입력할 명령입니다.
semanage fcontext -a -t svirt_sandbox_file_t "/opt/postgresql-storage(/.*)?" restorecon -R /opt/postgresql-storage
제안된 솔루션은 PostgreSQL용 데이터 폴더에만 권한을 적용하는 것입니다. 그러나 ThingWorx 테이블 공간에 대한 쓰기 권한이 필요하므로 해당 폴더의 모든 항목에 동일한 권한을 부여해야 합니다.
이 예제에서는 ThingWorx Platform과 관련된 문제를 보여줍니다. 이 경우 sealert가 다음 경고를 생성합니다.
found 1 alerts in /var/log/audit/audit.log
--------------------------------------------------------------------------------
SELinux is preventing /bin/mv from write access on the directory ThingworxStorage.
***** Plugin catchall_labels (83.8 confidence) suggests *******************
If you want to allow mv to have write access on the ThingworxStorage directory
Then you need to change the label on ThingworxStorage
Do
# semanage fcontext -a -t FILE_TYPE 'ThingworxStorage'
where FILE_TYPE is one of the following: cgroup_t, container_var_lib_t, nfs_t,
svirt_home_t, svirt_sandbox_file_t, tmpfs_t, virt_home_t.
Then execute:
restorecon -v 'ThingworxStorage'

***** Plugin catchall (17.1 confidence) suggests **************************
If you believe that mv should be allowed write access on the ThingworxStorage
directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'mv' --raw | audit2allow -M my-mv
# semodule -i my-mv.pp

Additional Information:
Source Context system_u:system_r:svirt_lxc_net_t:s0:c320,c876
Target Context unconfined_u:object_r:usr_t:s0
Target Objects ThingworxStorage [ dir ]
Source mv
Source Path /bin/mv
Port <Unknown>
Host <Unknown>
Source RPM Packages
Target RPM Packages
Policy RPM selinux-policy-3.13.1-166.el7_4.9.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name ip-10-99-0-109.ec2.internal
Platform Linux ip-10-99-0-109.ec2.internal
3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20
20:32:50 UTC 2017 x86_64 x86_64
Alert Count 13
First Seen 2018-04-02 17:13:18 UTC
Last Seen 2018-04-02 17:13:23 UTC
Local ID 1759a007-f347-4d80-99e8-ee414eae7602
Raw Audit Messages
type=AVC msg=audit(1522689203.86:708): avc: denied { write } forpid=14905
comm="java" name="ThingworxStorage" dev="nvme0n1p1" ino=864027929
scontext=system_u:system_r:svirt_lxc_net_t:s0:c320,c876
tcontext=unconfined_u:object_r:usr_t:s0 tclass=dir

type=SYSCALL msg=audit(1522689203.86:708): arch=x86_64 syscall=mkdir success=no
exit=EACCES a0=7f6480f76e80 a1=1ff a2=7f6480f76e80 a3=b items=0 ppid=14734
pid=14905 auid=4294967295 uid=1337 gid=1337 euid=1337 suid=1337 fsuid=1337
egid=1337 sgid=1337 fsgid=1337 tty=(none) ses=4294967295 comm=java exe=/opt/
jdk1.8.0_121/bin/java subj=system_u:system_r:svirt_lxc_net_t:s0:c320,c876 key=(null)
Hash: mv,svirt_lxc_net_t,usr_t,dir,write
이 보고서는 다음과 같은 제안된 솔루션을 보여줍니다.
# semanage fcontext -a -t FILE_TYPE 'ThingworxStorage'
where FILE_TYPE is one of the following: cgroup_t, container_var_lib_t, nfs_t,
svirt_home_t, svirt_sandbox_file_t, tmpfs_t, virt_home_t.
Then execute:
restorecon -v 'ThingworxStorage'
다음은 이 솔루션을 구현하기 위해 사용할 명령입니다.
semanage fcontext -a -t svirt_sandbox_file_t "/opt/thingworx-storage(/.*)?"
restorecon -R /opt/thingworx-storage