I am trying to understand how selinux confined users really work, but there are a few behaviours that I still can not understand.
According to redhat
SELinux User Capabilities
stuff_u users should be able to run sudo, but not su.
So I have created the user someuser and mapped it to staff_u
[someuser@testserver ~]$ id -Z
staff_u:staff_r:staff_t:s0-s0:c0.c1023
Now if I add full permissions using sudo, but not setting the role/type on sudoers I will not be able to do much( as expected ).
[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 ~]$
If I change the sudoers to make the transitioning to sysadm_r and sysadm_t I was expecting to get basically permission to do anything, but it is not exactly what I am getting.
I can do lots of things:
[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 ~]$
But some commands are still blocked, for example postsuper from the postfix package.
[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 ~]$
Can anyone please explain to me the reason of that ? the strangest thing is that I do not see any denial on /var/log/audit/audit.log for the postsuper command. But it must be related to SELINUX because if I change the user back to the unconfined_u everything works.