SSH AuthorizedKeysCommand 和 SELinux

SSH AuthorizedKeysCommand 和 SELinux

我尝试AuthorizedKeysCommand在 CentOS 6.5 计算机中使用 SSH,但遇到 SELinux 错误。当我将 SELinux 切换到宽容模式(使用)时setenforce 0,它可以工作,但是当我将 SELinux 切换回强制模式时,该命令不再工作。

我在审核日志中得到以下读数(全部一行):

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.也许这就是 SELinux 阻止访问的原因,但我不这么认为。

我有什么明显遗漏的东西吗?

关于 . 存在一些混乱AuthorizedKeysCommand。它实际上并不从~/.ssh/目录中读取密钥。相反,该AuthorizedKeysCommand设置指定一个程序,该程序将给定用户的所有键作为单独的行打印到标准输出。

我指定的命令get-keys可以在 SELinux 设置为宽容的情况下工作,但在设置为强制时会失败。

在 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

相关内容