SELinux运行在宽容模式下:
# sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: permissive Mode from config file: disabled Policy version: 21 Policy from config file: targeted
每当我通过sshlogin, /var/log/secure抱怨:
sshd[4957]: Accepted publickey for quanta from 192.168.3.40 port 55822 ssh2 sshd[4957]: pam_unix(sshd:session): session opened for user quanta by (uid=0) sshd[4957]: error: ssh_selinux_setup_pty: security_compute_relabel: Invalid argument
Google把我指向Fedora论坛上的这个主题:
可能最简单的方法(尽pipe最长)是创build文件
/.autorelabel并reboot。
但我不知道有没有其他的方式来摆脱这个不重新启动 ?
quanta的安全上下文:
$ id -Z system_u:system_r:unconfined_t:SystemLow-SystemHigh
Linux用户和user_u之间的映射:
$ sudo /usr/sbin/semanage login -l Login Name SELinux User MLS/MCS Range __default__ user_u s0 root root SystemLow-SystemHigh
SELinux用户:
$ sudo /usr/sbin/semanage user -l Labeling MLS/ MLS/ SELinux User Prefix MCS Level MCS Range SELinux Roles root user s0 SystemLow-SystemHigh system_r sysadm_r user_r system_u user s0 SystemLow-SystemHigh system_r user_u user s0 SystemLow-SystemHigh system_r sysadm_r user_r
sshd运行的安全上下文为:
$ ps -eZ | grep sshd system_u:system_r:unconfined_t:SystemLow-SystemHigh 9509 ? 00:02:11 sshd system_u:system_r:unconfined_t:SystemLow-SystemHigh 18319 ? 00:00:00 sshd system_u:system_r:unconfined_t:SystemLow-SystemHigh 18321 ? 00:00:00 sshd
sshd的PAMconfiguration:
#%PAM-1.0 auth include system-auth account required pam_nologin.so #account required pam_access.so account include system-auth password include system-auth session optional pam_keyinit.so force revoke session include system-auth session required pam_loginuid.so
我已经尝试过,并没有帮助:
# yum reinstall selinux-policy-targeted # restorecon -R -v /etc/selinux/ # restorecon -R -v /home/
/var/log/audit/audit.log :
type=USER_AUTH msg=audit(1362372405.835:28361028): user pid=14332 uid=0 auid=503 subj=system_u:system_r:unconfined_t:s0-s0:c0.c1023 msg='op=pubkey_auth rport=50939 acct="quanta" exe="/usr/sbin/sshd" (hostname=?, addr=192.168.3.40, terminal=? res=success)'
更新3月4日星期一21:20:49 ICT 2013
回复Michael Hampton:
请记住,重新启动的原因是更改安全上下文会影响正在运行的服务,所以至less应该重新启动受影响的服务(即重新启动sshd)。
root 10244 1 0 17:18 ? 00:00:00 /usr/sbin/sshd
/var/log/secure
Mar 4 17:18:48 hostname sshd[10308]: error: ssh_selinux_setup_pty: security_compute_relabel: Invalid argument
更新2月5日21:54:00 ICT 2013
你能提供
ls -lZ /dev/pts /dev/ptmx吗?
# ls -lZ /dev/pts/ /dev/ptmx crw-rw-rw-. 1 root tty system_u:object_r:ptmx_t 5, 2 Mar 5 21:54 /dev/ptmx /dev/pts/: total 0 crw--w----. 1 quanta tty system_u:object_r:devpts_t 136, 0 Mar 5 21:54 0 crw--w----. 1 dieppv tty system_u:object_r:devpts_t 136, 1 Feb 26 17:08 1 crw--w----. 1 dieppv tty system_u:object_r:devpts_t 136, 2 Feb 25 17:53 2
更新3月6日星期三10:57:11 ICT 2013
我编译了openssh-5.8p1 ,然后复制configuration文件( /etc/ssh/和/etc/pam.d/sshd ),并在不同的端口上启动。
让我感到惊讶的是/var/log/secure在我尝试login时没有抱怨:
sshd[5061]: Server listening on 192.168.6.142 port 2317. sshd[5139]: Accepted publickey for quanta from 192.168.3.40 port 54384 ssh2 sshd[5139]: pam_unix(sshd:session): session opened for user quanta by (uid=0)
新的/usr/local/sbin/sshd守护程序的安全上下文与旧的( /usr/sbin/sshd )相同:
ps -efZ | grep /usr/local/sbin/sshd
system_u:system_r:unconfined_t:SystemLow-SystemHigh root 5061 1 0 10:56 ? 00:00:00 /usr/local/sbin/sshd system_u:system_r:unconfined_t:SystemLow-SystemHigh root 7850 3104 0 11:06 pts/3 00:00:00 grep /usr/local/sbin/sshd
你有什么想法?
更新3月6日星期三15:36:39 ICT 2013
确保使用
--with-selinux编译,默认情况下没有完成。
OpenSSH has been configured with the following options: User binaries: /usr/local//bin System binaries: /usr/local//sbin Configuration files: /etc/openssh Askpass program: /usr/local//libexec/ssh-askpass Manual pages: /usr/local//share/man/manX PID file: /var/run Privilege separation chroot path: /var/empty sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local//bin Manpage format: doc PAM support: yes OSF SIA support: no KerberosV support: no SELinux support: yes Smartcard support: S/KEY support: no TCP Wrappers support: no MD5 password support: yes libedit support: no Solaris process contract support: no Solaris project support: no IP address in $DISPLAY hack: no Translate v4 in v6 hack: yes BSD Auth support: no Random number source: OpenSSL internal ONLY Host: i686-pc-linux-gnu Compiler: gcc Compiler flags: -g -O2 -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wno-pointer-sign -fno-strict-aliasing -fno-builtin-memset -fstack-protector-all -std=gnu99 Preprocessor flags: Linker flags: -fstack-protector-all Libraries: -lresolv -lcrypto -ldl -lutil -lz -lnsl -lcrypt +for sshd: -lpam -lselinux +for ssh: -lselinux
login到端口22( /usr/sbin/sshd )时, /var/log/secure :
sshd[27339]: Accepted publickey for quanta from 192.168.3.40 port 50560 ssh2 sshd[27339]: pam_unix(sshd:session): session opened for user quanta by (uid=0) sshd[27339]: error: ssh_selinux_setup_pty: security_compute_relabel: Invalid argument sshd[28025]: Received disconnect from 192.168.3.40: 11: disconnected by user sshd[28022]: pam_unix(sshd:session): session closed for user quanta
/var/log/securelogin到端口2317( /usr/local/sbin/sshd )时:
sshd[27705]: Accepted publickey for quanta from 192.168.3.40 port 34175 ssh2 sshd[27705]: pam_unix(sshd:session): session opened for user quanta by (uid=0) sshd[27707]: Received disconnect from 192.168.3.40: 11: disconnected by user sshd[27705]: pam_unix(sshd:session): session closed for user quanta
这里是日志来certificate它进入ssh_selinux_setup_pty :
sshd[4023]: debug1: SELinux support enabled sshd[4023]: debug3: ssh_selinux_setup_pty: setting TTY context on /dev/pts/3 sshd[4023]: debug3: ssh_selinux_setup_pty: User context is user_u:system_r:unconfined_t, target tty is system_u:object_r:devpts_t sshd[4023]: debug3: ssh_selinux_setup_pty: done
/.autorelabel文件只是引导启动脚本在启动时运行restorecon -r -v / ,然后重新启动。 (其实它运行一些调用fixfiles打印很多点,但因为这只是一个前端restorecon我不在乎…)
你可以自己运行而不用重新启动,而这通常是我尝试诊断一个奇怪的SELinux问题时的第一步。 请记住,重新启动的原因是更改安全上下文会影响正在运行的服务,所以至less应该重新启动受影响的服务(即重新启动sshd)。
如果这确实解决了这个问题,那么在输出的某个地方你会看到一个改变的安全上下文,这个问题的原因和解决scheme。 很可能它不在 /home或/etc/selinux 。
起初我写了一个比较复杂的答案,只适用于EL6,但后来有些东西出现,我觉得在你的情况下很奇怪。
错误消息:
ssh_selinux_setup_pty: security_compute_relabel: Invalid argument
很奇怪 我这样说的原因是因为在EL5上,最新版本的SSHD,这个错误信息是不可能的 。 它不在源头上。 无处不在。 我grepped整个源码树和“ssh_selinux_setup_pty”的红帽补丁。 它不在那里。
它确实出现在Fedora 18上。
这导致我认为你正在运行的SSHD版本不是它应该的版本,它已被replace。 无论是自己还是别人。
SSHD在不起作用的关键部分执行类似于此(用python); 我相信在sshd中使用的selinux上下文正如你所提到的。
from selinux import * sec_class = string_to_security_class("chr_file") print security_compute_relabel("system_u:object_r:unconfined_t", \ "system_u:object_r:initrc_devpts_t", sec_class)
这应该返回:
[0,some_context_stuff]
你需要使用与sshd相同的上下文来运行它。 “initrc_devpts_t”是绝对正确的。 另一个上下文是您提供的引用的用户上下文。
你在sshd中的代码现在得到-1,吐出这个错误。 如果在sshd中生成的用户上下文(参数1)不正确,则会发生这种情况。
如果你可以得到这个python不会在元组的第一个元素中产生-1,那么我build议的唯一方法就是修改sshd源文件,在该函数中添加一个额外的debugging行,以找出真正的上下文转换然后打开sshds config中的debug3日志logging。
在 openbsd-compat/port-linux.c: ssh_selinux_setup_pty
if (getfilecon(tty, &old_tty_ctx) == -1) { error("%s: getfilecon: %s", __func__, strerror(errno)); goto out; } +debug3("%s: User context is %s, target tty is %s", __func__, user_ctx, old_tty_ctx); if (security_compute_relabel(user_ctx, old_tty_ctx, SECCLASS_CHR_FILE, &new_tty_ctx) != 0) { error("%s: security_compute_relabel: %s", __func__, strerror(errno)); goto out; }
在有针对性的政策运行中有相同的问题
Nov 14 17:34:41 server sshd[13863]: error: PAM: pam_open_session(): Cannot make/remove an entry for the specified session Nov 14 17:34:42 server sshd[13863]: error: ssh_selinux_setup_pty: security_compute_relabel: Invalid argument Nov 14 17:34:43 server sshd[13868]: Received disconnect from xxxx: 11: disconnected by user
但可以从http://www.unix.com/man-page/centos/8/sysadm_selinux/获得参考
semanage user -m -R 'staff_r sysadm_r system_r unconfined_r' sysadm_u
应该这样做。 希望能帮助到你