SELinux Security Policy Part2: Labels
From the previousblog we know that SElinux policy consists of rules, each of which describes an INTERACTION between processes and system resources.
In the second part of this blog series I will tell you more about LABELS. Where SELinux labels are stored and how they look in reality. Labels are an important part of SELinux since all SELinux decisions are based on them. As my colleague Dan Walsh says:“SELinux is all about labels“
Where are SELinux labels stored?
SELinux labels are stored in extended attributes (abbreviated xattr) of file systems that support them ext2 , ext3 , ext4 and others.
How can I show labels placed in XATTR ?# getfattr -n security.selinux /etc/passwd getfattr: Removing leading '/' from absolute path names # file: etc/passwd security.selinux="system_u:object_r:passwd_file_t:s0"
Is there another way to show it?# ls -Z /etc/passwd system_u:object_r:passwd_file_t:s0 /etc/passwd
“ -Z ” option is your friend. In most cases it is related to SELinux and help us either show SELinux labels or modify them directly. You can check it for mv , cp , ps user commands for example.
From the above example of SELinux label you can see that SELinux labels consist of FOUR parts with the following templateSELinux user:SELinux role:SELinux type:SELinux category SELinux users Not the same as Linux users.
Several Linux users can be mapped to a single SELinux user.
object_u is a placeholder for Linux system resources.
system_u is a placeholder for Linux processes.
Can be limited to a set of SELinux roles. SELinux role SELinux users can have multiple roles but only one can be active.
object_r is a placeholder for Linux system resources.
system_r is a placeholder for system processes.
Can be limited to a set of SELinux types. SELinux type Security model known as TYPE ENFORCEMENT .
In 99% you care only about TYPES.
policy rules and interactions between types. SELinux category Allow users to mark resources with compartment tags (MCS1 , MCS2 ).
Used for RHEL virtualization and for container security.
s0 as the placeholder for default category.
s0:c1 can not access s0:c2.
In Fedora we ship TARGETED SELinux policy featuring mainly TYPE ENFORCEMENT. It means we mostly care only about TYPES . We can re-define the introductory statement of policy rules with this knowledge fromALLOW LABEL1 LABEL2 :OBJECT_CLASS PERMISSION ;
toALLOW TYPE1 TYPE2 :OBJECT_CLASS PERMISSION ;
Where TYPE1 could be APACHE_T process type for apache processes and TYPE2 could be file type for apache logging files. In that case we declare the following SELinux policy rulesALLOW APACHE_T APACHE_LOG_T:FILE READ;
Now you know that if we talk about TYPES, we talk about LABELS with respect to TARGETED policy, which is the default policy used in FEDORA.
本文系统（linux）相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统