SElinux는 개인 키와의 연결을 허용하지 않습니다.
다음과 같은 문제가 있습니다.
SElinux를 설치하고 사용자 unconfined_r
를 sudo 권한 으로 매핑 하고 SSH 연결을 허용했지만 강제 모드를 설정 한 후에는 ssh
개인 키로 더 이상 로그인 할 수 없습니다 .
연결을 시도 ssh
하면 다음을 얻습니다.
client_loop: send disconnect: Broken pipe
이것은 내가 한 구성입니다.
echo "myuser_user ALL=(ALL) TYPE=sysadm_t ROLE=system_r /bin/sh " > /etc/sudoers.d/myuser_user
getsebool -a | grep ssh
allow_ssh_keysign --> on
fenced_can_ssh --> off
sftpd_write_ssh_home --> off
ssh_sysadm_login --> on
ssh_use_gpg_agent --> off
내가 한 전체 SE Linux 구성을 추가했습니다. 디버그에 도움이 될 수 있습니다.
semanage user -a -r s0-s0:c0.c1023 -R "unconfined_r system_r" ubuntu_user_u
cp /etc/selinux/default/contexts/users/unconfined_u /etc/selinux/default/contexts/users/ubuntu_user_u
semanage login -a -s ubuntu_user_u -rs0:c0.c1023 ubuntu
echo "ubuntu ALL=(ALL) TYPE=system_sudo_t ROLE=system_r /bin/sh " > /etc/sudoers.d/ubuntu
chcon -R -v system_u:object_r:system_sudo_t:s0 /home/ubuntu/.ssh/
여기 ssh로 로그를 시도 할 때 생성되는 /var/log/audit.log :
type=USER_AVC msg=audit(1606521919.331:151): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/run/systemd/transient/session-8.scope" cmdline="/lib/systemd/systemd-logind" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:systemd_unit_t:s0 tclass=service permissive=0 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_START msg=audit(1606521919.823:152): pid=1163 uid=0 auid=1000 ses=8 subj=system_u:system_r:kernel_t:s0 msg='op=PAM:session_open acct="ubuntu" exe="/usr/sbin/sshd" hostname=15.170.168.139 addr=15.170.168.139 terminal=ssh res=failed'
type=CRED_ACQ msg=audit(1606521919.823:153): pid=1231 uid=0 auid=1000 ses=8 subj=system_u:system_r:kernel_t:s0 msg='op=PAM:setcred acct="ubuntu" exe="/usr/sbin/sshd" hostname=15.170.168.139 addr=15.170.168.139 terminal=ssh res=success'
type=CRED_DISP msg=audit(1606521919.831:154): pid=1163 uid=0 auid=1000 ses=8 subj=system_u:system_r:kernel_t:s0 msg='op=PAM:setcred acct="ubuntu" exe="/usr/sbin/sshd" hostname=15.170.168.139 addr=15.170.168.139 terminal=ssh res=success'
audit2allow -w -a | grep "ssh"
type=USER_AVC msg=audit(1606522579.718:169): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606522579.718:170): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { status } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606522673.346:192): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=0 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606522687.874:196): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606522687.878:198): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { status } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=AVC msg=audit(1606522853.067:220): avc: denied { relabelto } for pid=1529 comm="chcon" name=".ssh" dev="nvme0n1p1" ino=256082 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:system_sudo_t:s0 tclass=dir permissive=1
type=USER_AVC msg=audit(1606527581.704:277): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { status } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606527582.256:278): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606527704.324:293): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=0 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606527713.724:297): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { start } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=USER_AVC msg=audit(1606527713.724:298): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:kernel_t:s0 msg='avc: denied { status } for auid=n/a uid=0 gid=0 path="/lib/systemd/system/ssh.service" cmdline="" scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=service permissive=1 exe="/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
type=AVC msg=audit(1606567016.248:483): avc: denied { relabelfrom } for pid=10828 comm="restorecon" name=".ssh" dev="nvme0n1p1" ino=256082 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:system_sudo_t:s0 tclass=dir permissive=0
type=AVC msg=audit(1606567026.156:487): avc: denied { relabelfrom } for pid=10830 comm="restorecon" name=".ssh" dev="nvme0n1p1" ino=256082 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:system_sudo_t:s0 tclass=dir permissive=1
audit2allow -w -a | grep "인증"
type=AVC msg=audit(1606522853.063:219): avc: denied { associate } for pid=1529 comm="chcon" name="authorized_keys" dev="nvme0n1p1" ino=256083 scontext=system_u:object_r:system_sudo_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem permissive=1
type=AVC msg=audit(1606522853.063:219): avc: denied { relabelto } for pid=1529 comm="chcon" name="authorized_keys" dev="nvme0n1p1" ino=256083 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:system_sudo_t:s0 tclass=file permissive=1
type=AVC msg=audit(1606567016.248:484): avc: denied { relabelfrom } for pid=10828 comm="restorecon" name="authorized_keys" dev="nvme0n1p1" ino=256083 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:system_sudo_t:s0 tclass=file permissive=0
type=AVC msg=audit(1606567026.156:488): avc: denied { relabelfrom } for pid=10830 comm="restorecon" name="authorized_keys" dev="nvme0n1p1" ino=256083 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:system_sudo_t:s0 tclass=file permissive=1
누구든지 도울 수 있습니까?
답변
다음은 가독성을 높이기 위해 여러 줄로 분할 된 첫 번째 감사 로그 메시지입니다.
type=USER_AVC msg=audit(1606521919.331:151): pid=1 uid=0 auid=4294967295 ses=4294967295 \
subj=system_u:system_r:kernel_t:s0 \
msg='avc: denied { start } for auid=n/a uid=0 gid=0 \
path="/run/systemd/transient/session-8.scope" \
cmdline="/lib/systemd/systemd-logind" \
scontext=system_u:system_r:kernel_t:s0 \
tcontext=system_u:object_r:systemd_unit_t:s0 \
tclass=service permissive=0 \
exe="/lib/systemd/systemd" \
sauid=0 hostname=? addr=? terminal=?'
유형은 USER_AVC
이므로이 SELinux 검사는 사용자 공간 코드에서 요청했기 때문에 특별히 수행되었습니다. 따라서이를 트리거 한 사용자 공간 프로그램은 명시 적으로 SELinux를 지원합니다.
는 pid=1
이 검사는 시스템의 기본에 대해 수행되었음을 나타냅니다 init
명백하게 과정, systemd
이 경우.
subj=
제기는 system_u:system_r:kernel_t
그렇게, systemd
해당 프로세스가 분명히 커널의 기본 SELinux에 컨텍스트에서 시작되었다.
path=
및 cmdline=
필드는 그 표시 systemd
사용자 별 호스트 것이다 사용자 세션 범위, 시작의 과정에서 분명히했다 systemd
이 사용자에 대한 서비스를,이 사용자의 모든 정규 과정.
그렇게 scontext=system_u:system_r:kernel_t:s0
하려면 대상 컨텍스트 tcontext=system_u:object_r:systemd_unit_t:s0
에서 실행 파일을 시작하기 위해 소스 SELinux 컨텍스트 ( )와 대상 컨텍스트 ( ) 사이의 선을 넘어야했습니다 /lib/systemd/systemd
. 그러나 msg=
현장 에 따르면 거부되었습니다.
이것은를 사용하는 시스템에서 매우 기본적인 작업 systemd
이므로 잘 만들어진 기본 정책이 당연히이를 다룰 가능성이 매우 높습니다. 나는 프로덕션 등급 시스템이 이와 같은 오류를 일으키지 않을 것으로 기대합니다. 이로 인해 현재 SELinux 정책이 systemd
.
SELinux 구성에는 포함되어 있으므로 ubuntu_user_u
Ubuntu 또는 일부 파생물을 사용하고 있음을 나타냅니다.
사용중인 SELinux 정책이 사용중인 배포판의 정확한 주요 릴리스에 대해 최신 버전이라고 확신하십니까? 시스템이 예를 들어 apt full-upgrade
또는 이와 유사한 방식으로 하나의 주요 릴리스에서 다른 릴리스로 업그레이드 된 경우 업데이트 된 정책 모듈 파일에서 활성 SELinux 정책을 다시 생성하기 위해 몇 가지 추가 단계를 수행해야 할 수 있습니다.