공개 키를 통해 SSH를 방지하는 SELinux

공개 키를 통해 SSH를 방지하는 SELinux

$USER인증된 사용자 파일이 있는 시스템 사용자 계정인 사용자가 있습니다 . SELinux를 활성화하면 공개 키를 사용하여 서버에 SSH로 접속할 수 없습니다. 이면 이제 로그인할 수 있습니다 setenabled 0.$USER

SELinux를 완전히 비활성화하지 않고 이 동작을 수정하려면 어떤 SELinux 부울/정책을 변경해야 합니까?

$USER이 기본 SELinux 구성에서 비밀번호로 로그인할 수 있다는 점은 주목할 가치가 있습니다. 여기서 무슨 일이 일어나고 있는지, 그리고 SELinux가 이를 차단하지 않는 이유에 대해 알려주시면 감사하겠습니다. (이 문제가 해결된 후에는 비밀번호 인증을 완전히 비활성화할 예정이므로 이 질문을 알아두면 더 좋습니다.)

답변1

~/.ssh/*에 대한 파일 시스템 권한이 정확하다고 가정하고 다음의 출력을 확인하십시오.

sealert -a /var/log/audit/audit.log

AVC 항목에 단서가 있어야 합니다. 아마도 솔루션은 다음과 같이 실행될 것입니다.

restorecon -R -v ~/.ssh

답변2

sealert최근에 접한 시스템에서와 같이 시스템에 이 누락된 경우 다음과 같은 가능성도 있습니다 audit2allow.

$ sudo audit2allow -w -a
type=AVC msg=audit(1548909218.552:1037): avc:  denied  { read } for  pid=13996 comm="sshd" name="authorized_keys" dev="dm-0" ino=4663556 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:admin_home_t:s0 tclass=file
    Was caused by:
            Missing type enforcement (TE) allow rule.

            You can use audit2allow to generate a loadable module to allow this access.

AVC 분석:

avc: denied { read } for pid=13996 comm="sshd" name="authorized_keys" dev="dm-0" ino=4663556
    "sshd" was denied read on a file resource named "authorized_keys".
scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023
    SELinux context of the sshd process that attempted the denied action.
tcontext=system_u:object_r:admin_home_t:s0 tclass=file
    SELinux context of the authorized_keys file.

scontextaudit2allow는 문제 해결 방법을 간결하게 설명하지 않았지만 및 를 살펴보면 tcontextscontext은 필요한 컨텍스트를 나타내는 반면 tcontext만족스럽지 못한 "authorized_keys" 파일 컨텍스트를 보여줍니다.

이 경우 restorecon -R -v ~/.ssh자체적으로는 작동하지 않았지만 원하는 컨텍스트를 적용하면 다음과 같은 작업이 수행되었습니다.

$ sudo semanage fcontext --add -t ssh_home_t "/path/to/my/.ssh(/.*)?"; \
$ sudo restorecon -FRv /path/to/my/.ssh

필요에 따라 AVC에 표시된 내용에 따라 리소스 이름 및/또는 컨텍스트를 변경합니다. 이 답변의 정확한 세부 사항은 "authorized_keys"와 관련된 문제를 해결하기 위해 구성되었지만 sealert또는 에서 생성된 AVC에 다른 파일이나 컨텍스트가 표시되어 있어도 솔루션은 이 모델을 따를 수 있습니다 audit2allow.

관련 정보