SSH AuthorizedKeysCommandとSELinux

SSH AuthorizedKeysCommandとSELinux

AuthorizedKeysCommandCentOS 6.5システムでSSHを使用しようとするとSELinuxエラーが発生します。 SELinuxを許可モード(有効)に切り替えるとsetenforce 0機能しますが、SELinuxを強制モードに戻すと、コマンドは機能しなくなります。

監査ログには、次の内容が表示されます(すべて1行)。

type=AVC msg=audit(1404210795.382:917): avc: denied { execute } for pid=2924 comm="sshd"
name="get-keys" dev=dm-0 ino=167467 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023
tcontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tclass=file

このコマンドのSELinuxポリシーget-keysは異なります。コマンドと同じ設定に設定しましたsshd。また、すべてのSSH関連SELinuxブールをtrueに設定してみました。見つけることができるすべてのブール値は次のとおりですgrep

$ getsebool -a | grep ssh
allow_ssh_keysign --> on
fenced_can_ssh --> on
ssh_chroot_full_access --> on
ssh_chroot_manage_apache_content --> on
ssh_chroot_rw_homedirs --> on
ssh_sysadm_login --> on

/usr/bin/get-ssh-keys/コマンドが含まれていますget-keys。以下はディレクトリの権限です。

$ ls -laZ /usr/bin/get-ssh-keys/
drwxr--r--. root root unconfined_u:object_r:etc_t:s0   .
dr-xr-xr-x. root root system_u:object_r:bin_t:s0       ..
-rwx--x--x. root root system_u:system_r:sshd_t:s0-s0:c0.c1023 get-keys

[...]

$ ls -laZ /usr/
drwxr-xr-x. root root system_u:object_r:usr_t:s0       .
dr-xr-xr-x. root root system_u:object_r:root_t:s0      ..

[...]

関連する/etc/ssh/sshd_config設定は次のとおりです。

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
AuthorizedKeysCommand /usr/bin/get-ssh-keys/get-keys
AuthorizedKeysCommandRunAs root

このget-keysコマンドはソケットを介して他のサーバーに接続します/var/log/get-ssh-keys/error_log

私が明らかに見逃しているものはありますか?

について少し混乱がありますAuthorizedKeysCommand。実際には~/.ssh/ディレクトリからキーを読み取ることはありません。代わりに、このAuthorizedKeysCommand設定は、特定のユーザーのすべてのキーを標準出力に別々の行で印刷するプログラムを指定します。

私が指定したコマンドは、get-keysSELinuxが許可に設定されている場合は機能しますが、必須に設定されている場合は失敗します。

SELinux の施行ではパスワードの入力を求められますが、SELinux 権限でこのコマンドで検索されたキーを使用してログインできます。

ベストアンサー1

友人、あなたがそれを知っていると確信しています。しかし、万が一の場合に備えて:

  1. selinux yum install setroubleshootの問題を解決するには、ツールが必要です。
  2. 警告が記録されていることを確認し、sealert -a /var/log/audit/audit.log を表示してポリシーを作成します。

このツールは何をすべきか教えてくれます

[root@zabbix audit]# sealert -a /var/log/audit/audit.log
 49% done'list' object has no attribute 'split'
 100% done
found 1 alerts in /var/log/audit/audit.log
--------------------------------------------------------------------------------

SELinux is preventing /usr/bin/python2.7 from name_connect access on the       tcp_socket port 3306.

*****  Plugin catchall (100. confidence) suggests   **************************

If you believe that python2.7 should be allowed name_connect access on the      port 3306 tcp_socket by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep python /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

おすすめ記事