启用S​​ELinux后,/ bin / su权限被拒绝 – 不能通过手动创buildSELinux策略来解决

出于某种原因,我不能su从根非root用户:

[rilindo@kerberos ~]$ /bin/su - -bash: /bin/su: Permission denied 

从/var/log/audit/audit.log运行输出或者返回:

 [root@kerberos tmp]# cat /tmp/audit type=AVC msg=audit(1319322088.937:68012): avc: denied { execute } for pid=9794 comm="bash" name="su" dev=dm-0 ino=1048659 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:su_exec_t:s0 tclass=file type=SYSCALL msg=audit(1319322088.937:68012): arch=c000003e syscall=59 success=no exit=-13 a0=26a7df0 a1=26c9b30 a2=269efa0 a3=18 items=0 ppid=8435 pid=9794 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts0 ses=4454 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1319322088.944:68013): avc: denied { getattr } for pid=9794 comm="bash" path="/bin/su" dev=dm-0 ino=1048659 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:su_exec_t:s0 tclass=file type=SYSCALL msg=audit(1319322088.944:68013): arch=c000003e syscall=4 success=no exit=-13 a0=26a7df0 a1=7fff26b200d0 a2=7fff26b200d0 a3=18 items=0 ppid=8435 pid=9794 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts0 ses=4454 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1319322088.944:68014): avc: denied { getattr } for pid=9794 comm="bash" path="/bin/su" dev=dm-0 ino=1048659 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:su_exec_t:s0 tclass=file type=SYSCALL msg=audit(1319322088.944:68014): arch=c000003e syscall=4 success=no exit=-13 a0=26a7df0 a1=7fff26b200b0 a2=7fff26b200b0 a3=18 items=0 ppid=8435 pid=9794 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts0 ses=4454 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) 

这导致audit2allow的这个解决scheme:

[root @ kerberos tmp]#cat / tmp / audit | audit2allow

 #============= user_t ============== #!!!! This avc is allowed in the current policy allow user_t su_exec_t:file { execute getattr }; [root@kerberos tmp]# 

或者这个输出:

 type=AVC msg=audit(1319334064.195:39047): avc: denied { read open } for pid=6067 comm="bash" name="su" dev=dm-0 ino=1048587 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:su_exec_t:s0 tclass=file type=SYSCALL msg=audit(1319334064.195:39047): arch=c000003e syscall=59 success=no exit=-13 a0=eecbd0 a1=eecbf0 a2=ec7720 a3=18 items=0 ppid=2857 pid=6067 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts8 ses=2 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1319334064.200:39048): avc: denied { read } for pid=6067 comm="bash" name="su" dev=dm-0 ino=1048587 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:su_exec_t:s0 tclass=file type=SYSCALL msg=audit(1319334064.200:39048): arch=c000003e syscall=21 success=no exit=-13 a0=eecbd0 a1=4 a2=0 a3=18 items=0 ppid=2857 pid=6067 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts8 ses=2 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1319334064.200:39049): avc: denied { read } for pid=6067 comm="bash" name="su" dev=dm-0 ino=1048587 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:su_exec_t:s0 tclass=file type=SYSCALL msg=audit(1319334064.200:39049): arch=c000003e syscall=2 success=no exit=-13 a0=eecbd0 a1=0 a2=43 a3=18 items=0 ppid=2857 pid=6067 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=pts8 ses=2 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1319334064.208:39050): avc: denied { rlimitinh } for pid=6069 comm="setroubleshootd" scontext=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 tcontext=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 tclass=process type=AVC msg=audit(1319334064.208:39050): avc: denied { siginh } for pid=6069 comm="setroubleshootd" scontext=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 tcontext=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 tclass=process type=AVC msg=audit(1319334064.208:39050): avc: denied { noatsecure } for pid=6069 comm="setroubleshootd" scontext=system_u:system_r:system_dbusd_t:s0-s0:c0.c1023 tcontext=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 tclass=process type=SYSCALL msg=audit(1319334064.208:39050): arch=c000003e syscall=59 success=yes exit=0 a0=944aa0 a1=9447e0 a2=943010 a3=1 items=0 ppid=6068 pid=6069 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="setroubleshootd" exe="/usr/bin/python" subj=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 key=(null) type=AVC msg=audit(1319334064.369:39051): avc: denied { write } for pid=6069 comm="setroubleshootd" name="rpm" dev=dm-0 ino=655363 scontext=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:rpm_var_lib_t:s0 tclass=dir type=SYSCALL msg=audit(1319334064.369:39051): arch=c000003e syscall=21 success=no exit=-13 a0=1405430 a1=2 a2=0 a3=9 items=0 ppid=6068 pid=6069 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="setroubleshootd" exe="/usr/bin/python" subj=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 key=(null) type=AVC msg=audit(1319334064.370:39052): avc: denied { write } for pid=6069 comm="setroubleshootd" name="rpm" dev=dm-0 ino=655363 scontext=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:rpm_var_lib_t:s0 tclass=dir type=SYSCALL msg=audit(1319334064.370:39052): arch=c000003e syscall=21 success=no exit=-13 a0=1405430 a1=2 a2=0 a3=5 items=0 ppid=6068 pid=6069 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="setroubleshootd" exe="/usr/bin/python" subj=system_u:system_r:setroubleshootd_t:s0-s0:c0.c1023 key=(null) 

在此,audit2allowbuild议如下:

 #============= setroubleshootd_t ============== #!!!! The source type 'setroubleshootd_t' can write to a 'dir' of the following types: # var_log_t, setroubleshoot_var_lib_t, setroubleshoot_var_run_t, setroubleshoot_var_log_t, var_lib_t, var_run_t, root_t allow setroubleshootd_t rpm_var_lib_t:dir write; #============= system_dbusd_t ============== allow system_dbusd_t setroubleshootd_t:process { siginh rlimitinh noatsecure }; #============= user_t ============== allow user_t su_exec_t:file { read open }; 

奇怪的是,每当我尝试加载新的策略时,它在两个消息之间切换,如下所示:

 [root@kerberos tmp]# cat /tmp/audit2 | audit2allow -M local ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i local.pp 

试图使用升级选项返回以下内容:

 [root@kerberos tmp]# semodule -u local.pp libsemanage.get_direct_upgrade_filename: Previous module local is same or newer. (No such file or directory). semodule: Failed on local.pp! 

值得注意的是以下几点:

  • 系统最初没有启用selinux。 问题启动后,我启用了selinux

  • 原来,这是一个问题,使用“sudo su – ”,在故障排除期间,导致这个问题。

  • 我之后build立的新主机在默认情况下启用了selinux,而且他们没有这个问题,这意味着当我将SELinux恢复为原始服务器的“强制执行”时,没有启用。

这里是su命令的权限和facl:

 [root@kerberos tmp]# getfacl /bin/su getfacl: Removing leading '/' from absolute path names # file: bin/su # owner: root # group: root # flags: s-- user::rwx group::rx other::rx [root@kerberos tmp]# ls -laZ /bin/su -rwsr-xr-x. root root system_u:object_r:su_exec_t:s0 /bin/su [root@kerberos tmp]# 
  • 奇怪的是,在某种程度上,我必须按照确切的路线执行su,尽pipe它在我的道路上。 也奇怪的是,如果我以root身份login,那么su作为普通用户,那么我可以使用su命令:

     [root @ kerberos tmp]#su  -  rilindo
     [rilindo @ kerberos〜] $ su  -  
    密码: 
     [root @ kerberos〜]# 
    

一些方向是赞赏。

你的问题是你以root身份在user_t域中运行。

user_t不能访问su。

将您的用户更改为staff_u用户,这将使其消失。

 semanage login -a -s staff_u -r s0 rilindo 

另外,注意su,在这方面不会帮助你,因为你会su到staff_ttypes,不会做你想做的一切。

为了解决这个问题,编辑sudoers并添加你的用户,如下所示:

 rilindo ALL=(ALL) ROLE=sysadm_r TYPE=sysadm_t ALL 

现在,你可以做sudo su – 而不会得到一个问题!