SElinux nie akceptuje połączenia z kluczem prywatnym

Nov 26 2020

Mam następujący problem:

Zainstalowałem SElinux, zmapowałem mojego użytkownika tak, jak unconfined_rz uprawnieniami sudo i zezwoliłem na połączenia SSH, ale po skonfigurowaniu trybu wymuszania nie mogę już zalogować się przy użyciu sshklucza prywatnego.

Kiedy próbuję się połączyć ssh, otrzymuję:

client_loop: send disconnect: Broken pipe

Oto konfiguracja, którą zrobiłem:

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

Dodałem pełną konfigurację SE Linuksa, którą zrobiłem, może pomoże w debugowaniu ...

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/

tutaj /var/log/audit.log, który jest generowany podczas próby logowania za pomocą ssh:

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

Czy ktoś może pomóc?

Odpowiedzi

telcoM Nov 28 2020 at 20:39

Oto pierwsza wiadomość dziennika kontroli, podzielona na wiele wierszy dla lepszej czytelności:

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=?'

Typ to USER_AVC, więc to sprawdzenie SELinuksa zostało wykonane specjalnie, ponieważ zażądał tego kod przestrzeni użytkownika. Zatem program przestrzeni użytkownika, który go uruchomił, wyraźnie obsługuje SELinuksa.

pid=1Wskazuje, że kontrola została wykonana dla podstawowego systemu initprocesu, który jest najwyraźniej systemdw tym przypadku.

Pole subj=jest system_u:system_r:kernel_t, więc systemdproces, o którym mowa, został najwyraźniej uruchomiony w domyślnym kontekście SELinux jądra.

path=I cmdline=pola wskazują, że systemdbył najwyraźniej w procesie uruchamiania zakres sesji użytkownika, który będzie gościć przez poszczególnych użytkowników systemdusługi dla tego użytkownika, a wszystkie zwykłe procesy tego użytkownika.

Wykonanie tego wymagałoby przekroczenia linii między źródłowym kontekstem SELinux ( scontext=system_u:system_r:kernel_t:s0) a kontekstem docelowym ( tcontext=system_u:object_r:systemd_unit_t:s0), aby uruchomić plik wykonywalny /lib/systemd/systemdw kontekście docelowym. Ale według msg=pola odmówiono.

Jest to dość fundamentalna operacja w systemie, który używa systemd, więc dobrze opracowana domyślna polityka z dużym prawdopodobieństwem mogłaby ją objąć. Spodziewałbym się, że system klasy produkcyjnej nie będzie powodował takich awarii. To sprawia, że ​​myślę, że twoja obecna polityka SELinux może nie być w pełni aktualna do użytku z systemd.

Ponieważ twoja konfiguracja SELinux obejmuje ubuntu_user_u, sugeruje to, że używasz Ubuntu lub jego pochodnej.

Czy jesteś pewien, że polityka SELinux, której używasz, jest aktualna dla dokładnej głównej wersji dystrybucji, której używasz? Jeśli system został zaktualizowany z jednej wersji głównej do innej, np. apt full-upgradeLub podobną, może być konieczne podjęcie dodatkowych kroków, aby zregenerować aktywną politykę SELinux ze zaktualizowanych plików modułu zasad.