SELinux: /etc/passwd에서 사용자 정의 셸 바이너리 실행

SELinux: /etc/passwd에서 사용자 정의 셸 바이너리 실행

----- 문제 --------

내 시스템에는 CentOS 7.6이 실행되고 있습니다. /etc/passwd 파일에서 표준 쉘 대신 사용자 정의 쉘을 호출하고 싶습니다.

SELinux를 활성화했는데 어떤 이유로 sshd_t 도메인이 내 사용자 정의 셸이 보유한 새 사용자 정의 도메인으로 전환되지 않습니다.

이 같은:

/etc/passwd에서:

root:x:0:0:root:/root:/bin/myshell

SELinux 도메인 전환:

myshell.fc

/bin/myshell                             gen_context(system_u:object_r:myshell_exec_t,s0)

myshell.te

role unconfined_r types myshell_t;
role_transition unconfined_r myshell_t system_r;
domtrans_pattern(unconfined_t, myshell_exec_t, myshell_t)

기본 사용자는unconfined_u:unconfined_r:unconfined_t.

또한 unconfined_r에서 system_r로 역할 전환이 있습니다.

---- 문제 ------

어떤 이유로 sshd_t가 myshell_t 도메인으로 전환되지 않습니다. 사용자는 루트입니다.

역할 변경 로그 메시지는 다음과 같습니다.

type=USER_ROLE_CHANGE msg=audit(1559079004.637:339116): pid=24478 uid=0 auid=0 ses=823 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg='pam: default-context=system_u:unconfined_r:unconfined_t:s0 selected-context=system_u:unconfined_r:unconfined_t:s0 exe="/usr/sbin/sshd" hostname=X.X.X.X addr=X.X.X.X terminal=ssh res=success'

type=AVC msg=audit(1559067681.085:327703): avc:  granted  { execute } for  pid=17593 comm="sshd" name="myshell"  scontext=system_u:unconfined_r:unconfined_t:s0 tcontext=system_u:object_r:myshell_exec_t:s0 tclass=file

바이너리를 실행하지만 전환이 발생하지 않습니다. 아마도 역할이 다르기 때문일 수도 있지만 역할 전환이 있습니다. 그래도 왜 작동하지 않는지 잘 모르겠습니다.

답변1

여기에는 두 가지 측면이 있습니다. 첫 번째 측면을 다루겠습니다.

  1. label /bin/myshell type shell_exec_t: echo '(filecon "/usr/bin/myshell" file (system_u object_r shell_exec_t ((s0)(s0))))' > myshell.cil && semodule -i myshell.cil
  2. 사용자 joe를 생성하고 기존 user_t 제한 쉘 도메인과 연결: useradd -Z user_u joe

ssh joe@localhost 'id -Z'

새로운 제한된 사용자를 생성하는 것은 좀 더 복잡하지만 요점은 sshd, 로그인 등과 같은 로그인 프로그램이 pam_selinux를 사용하여 로그인 쉘을 실행할 컨텍스트를 결정하고 자동이 아닌 수동으로 전환한다는 것입니다. /etc/selinux/TYPE/contexts/users/에 있는 파일은 /etc/selinux/TYPE/contexts에 있는 다른 파일들과 함께 사용됩니다.

관련 정보