我正在尝试了解 selinux 限制用户的实际工作方式,但有些行为我仍无法理解。根据红帽
stuff_u 用户应该能够运行 sudo,但不能运行 su。因此我创建了用户某些用户并将其映射到 staff_u
[someuser@testserver ~]$ id -Z
staff_u:staff_r:staff_t:s0-s0:c0.c1023
现在,如果我使用 sudo 添加完全权限,但不在 sudoers 上设置角色/类型,我将无法做很多事情(正如预期的那样)。
[someuser@testserver ~]$ sudo -l
Matching Defaults entries for someuser on testserver:
!visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
User someuser may run the following commands on testserver:
(ALL) NOPASSWD: ALL
[someuser@testserver ~]$ sudo ls -la /var/log/audit/audit.log
ls: cannot access '/var/log/audit/audit.log': Permission denied
[someuser@testserver ~]$ sudo ausearch -m avc -ts recent
Error opening config file (Permission denied)
NOTE - using built-in logs: /var/log/audit/audit.log
Error opening /var/log/audit/audit.log (Permission denied)
[someuser@testserver ~]$
如果我更改 sudoers 以转换到 sysadm_r 和 sysadm_t,我期望获得执行任何操作的基本权限,但这并不是我所得到的。
我可以做很多事情:
[someuser@testserver ~]$ sudo -l
Matching Defaults entries for someuser on testserver:
!visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
User someuser may run the following commands on testserver:
(ALL) ROLE=sysadm_r TYPE=sysadm_t NOPASSWD: ALL
[someuser@testserver ~]$ sudo ausearch -m avc -ts recent | wc -l
66
[someuser@testserver ~]$ sudo ls -la /var/log/audit/audit.log
-rw-------. 1 root root 1996980 Jul 30 12:55 /var/log/audit/audit.log
[someuser@testserver ~]$ sudo cat /var/log/audit/audit.log | wc -l
8172
[someuser@testserver ~]$
但有些命令仍然被阻止,例如 postfix 包中的 postsuper。
[someuser@testserver ~]$ sudo postsuper
sesh: unable to execute /sbin/postsuper: Permission denied
[someuser@testserver ~]$ file /sbin/postsuper
/sbin/postsuper: cannot open `/sbin/postsuper' (Permission denied)
[someuser@testserver ~]$ sudo file /sbin/postsuper
/sbin/postsuper: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=aa0157870508c475195fe5fb1dafe5a9b3898a61, stripped
[someuser@testserver ~]$
有人能解释一下原因吗?最奇怪的是,我没有在 /var/log/audit/audit.log 上看到任何关于 postsuper 命令的拒绝。但这一定与 SELINUX 有关,因为如果我将用户改回 unconfined_u,一切正常。