SElinuxは秘密鍵との接続を受け入れません

Nov 26 2020

私は次の問題を抱えています:

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

私が行った完全なSELinux構成を追加しました。おそらくデバッグに役立つでしょう...

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 "auth"

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

誰でも助けることができますか?

回答

telcoM Nov 28 2020 at 20:39

これが最初の監査ログメッセージで、読みやすくするために複数行に分割されています。

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ポリシーを再生成するために必要な追加の手順がいくつかある場合があります。