Difference between revisions of "PolicyStoreConfigurationFiles"

From SELinux Wiki
Jump to: navigation, search
(New page: = Policy Store Configuration Files = Each file discussed in this section is relative to the policy name as follows: <pre> <nowiki>/etc/selinux/<policy_name></nowiki> </pre> The Policy Sto...)
 
(modules/active/disable_dontaudit File)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Policy Store Configuration Files =
 
= Policy Store Configuration Files =
Each file discussed in this section is relative to the policy name as follows:
+
Depending on the release being used policy stores will be located at:
<pre>
+
* <tt><nowiki>/etc/selinux/<policy_name>/modules</nowiki></tt><nowiki> - This is the default for systems that support versions < 2.4 of </nowiki><tt>libsemanage</tt>, <tt>libsepol</tt>, and <tt>policycoreutils</tt>.
<nowiki>/etc/selinux/<policy_name></nowiki>
+
* <tt><nowiki>/var/lib/selinux/<policy_name>/modules</nowiki></tt> - This is the default for systems that support versions >= 2.4 of <tt>libsemanage</tt>, <tt>libsepol</tt>, and <tt>policycoreutils</tt>. The base (<tt>/var/lib/selinux</tt>) may be overridden by the <tt>store-root</tt> parameter defined in the [[GlobalConfigurationFiles#/etc/selinux/semanage.conf File | semanage.conf]] file. The migration process from previous releases is described at [https://github.com/SELinuxProject/selinux/wiki/Policy-Store-Migration https://github.com/SELinuxProject/selinux/wiki/Policy-Store-Migration]. Note that once the policy store migration is complete, these files will no longer exist
</pre>
+
  
The Policy Store files in the <nowiki>/etc/selinux/<policy_name>/modules</nowiki> area are either installed, updated or built by the semodule and semanage commands, and as a part of their process, relevant files are then copied to the Policy Configuration files area.  
+
Note: There can be multiple policy stores on a system at <tt><nowiki>/etc/selinux/<policy_name>/modules</nowiki></tt>.
  
The files present in each <nowiki><policy_name></nowiki> policy store will vary from policy to policy as different items could be configured for each one.  
+
The Policy Store files are either installed, updated or built by the '''semodule'''(8) and '''semanage'''(8) commands as a part of the build process. The resulting files will either be copied over to the [[PolicyConfigurationFiles | Policy Configuration Files]] area, or used to rebuild the kernel binary policy located at <nowiki>/etc/selinux/<policy_name>/policy</nowiki>.
  
Generally if a file has the extension '.local', then it has been generated by semanage and used to update the binary policy located at <nowiki>/etc/selinux/<policy_name>/policy</nowiki>.
+
All files may have comments inserted where each line must have the '#' symbol to indicate the start of a comment.
  
All files can have comments inserted where each line must have the '#' symbol to indicate the start of a comment.
+
The command options and outputs shown in the text are based on the current F-20 build.
  
 
== modules/ Files ==
 
== modules/ Files ==
Line 20: Line 19:
 
</pre>
 
</pre>
  
== base.pp File ==
+
== modules/active/base.pp File ==
This is the packaged base policy that contains the mandatory modules and policy components such as object classes and permission declarations, initial SIDs etc.
+
This is the packaged base policy that contains the mandatory modules and policy components such as object classes, permission declarations and initial SIDs.
  
== base.linked File ==
+
== modules/active/base.linked File ==
This is only present if the save-linked is set to TRUE as described in the /etc/selinux/semanage.conf section. It contains the modules that have been linked using the semodule_link(8) command.
+
This is only present if the save-linked is set to <tt>TRUE</tt> as described in the [[GlobalConfigurationFiles#/etc/selinux/semanage.conf File | /etc/selinux/semanage.conf]] section. It contains the modules that have been linked using the <tt>'''semodule_link'''(8)</tt> command.
  
== commit_num File ==
+
== modules/active/commit_num File ==
 
This is a binary file used by libsemanage for managing updates to the store. The format is not relevant to policy construction.
 
This is a binary file used by libsemanage for managing updates to the store. The format is not relevant to policy construction.
  
== file_contexts.template File ==
+
== modules/active/file_contexts.template File ==
This contains a copy all the modules 'Labeling Policy File' entries (e.g. the <nowiki><module_name>.fc</nowiki> files) that have been extracted from the base.pp and the loadable modules in the modules/active/modules directory.  
+
This contains a copy all the modules 'Labeling Policy File' entries (e.g. the <nowiki><module_name>.fc</nowiki> files) that have been extracted from the [[#modules/active/base.pp | base.pp]] and the loadable modules in the [[#modules/active/modules_Directory_Contents | modules/active/modules]] directory.  
  
The entries in the file_contexts.template file are then used to build the following files:
+
The entries in the file_contexts.template file are then used to build the following files as shown in the [http://selinuxproject.org/~rhaines/NB4-diagrams/25-file_contexts.png File Context Configuration Files] diagram:
 +
# [[#modules/active/homedir_template | homedir_template]] file that will be used to produce the [[#modules/active/file_contexts.homedirs | file_contexts.homedirs]] file which will then become the policies ./contexts/files/file_contexts.homedirs file.
 +
# [[#modules/active/file_contexts | file_contexts]] file that will become the policies file_contexts file.
  
# homedir_template file that will be used to produce the file_contexts.homedirs file which will then become the policies ./contexts/files/file_contexts.homedirs file.
+
Note that as a part of the <tt>semanage</tt> build process, these two files will also have <tt>file_contexts.bin</tt> and <tt>file_contexts.homedirs.bin</tt> files present in the [[PolicyConfigurationFiles#contexts/files/file_contexts File | Policy Configuration Files]] <tt>contexts/files</tt> directory. This is because <tt>semanage</tt> requires these in the Perl compatible regular expression (PCRE) internal format. They are generated by the <tt>'''sefcontext_compile'''(8)</tt> utility.
# file_contexts file that will become the policies ./contexts/files/file_contexts file.
+
  
The way these two files are built is as follows (and shown in Figure 1):
+
The homedir_template and file_contexts files are built is as follows:
 +
: '''homedir_template''' - Any line in the file_contexts.template file that has the keywords HOME_ROOT, HOME_DIR and/or USER are extracted and added to the homedir_template file. This is because these keywords are used to identify entries that are associated to a users home directory area. These lines may also have the ROLE keyword declared.
 +
: The homedir_template file will then be processed by '''genhomedircon'''(8)<ref name="ftn34"><sup>The genhomedircon command has now been built into the libsemanage library as a function to build the file_contexts.homedirs file via '''semanage'''(8).</sup></ref> to generate individual SELinux user entries in the file_contexts.homedirs file as discussed in the [[#modules/active/file_contexts.homedirs | modules/active/file_contexts.homedirs]] section.
  
'''homedir_template''' - Any line in the file_contexts.template file that has the keywords HOME_ROOT or HOME_DIR are extracted and added to the homedir_template file. This is because these keywords are used to identify entries that are associated to a users home directory area. These lines can also have the ROLE keyword declared.
+
These are examples of one line being processed as described above, taken from the F-20 targeted policy:
  
The homedir_template file will then be used by genhomedircon(8)(Note that the genhomedircon command has now been built into the libsepol library as a function to build the file_contexts.homedirs file via semanage) to generate individual SELinux user entries in the file_contexts.homedirs file as discussed in the ./modules/active/file_contexts.homedirs section.
+
The master file_contexts.template entry:
 +
<pre>
 +
HOME_DIR\/.wine(/.*)? system_u:object_r:wine_home_t:s0
 +
</pre>
  
'''file_contexts''' - All other lines are extracted and added to the file_contexts file as they are files not associated to a users home directory.  
+
The <tt>homedir_</tt>template entry is created as:
 +
<pre>
 +
HOME_DIR\/.wine(/.*)? system_u:object_r:wine_home_t:s0
 +
</pre>
  
ToDo - Get Figure 1 (filecontexts.png) uploaded.
+
The file_contexts.homedirs entries are created by <tt>genhomedircon</tt> for the SELinux users extracted from the [[#modules/active/seusers.final and seusers Files | seusers]] file as follows:
 +
<pre>
 +
# Home Context for any Linux user that is assigned
 +
# the SELinux user unconfined_u
 +
/home/[^/]*/\.wine(/.*)? unconfined_u:object_r:wine_home_t:s0
  
[[File:filecontexts.png|frame|<center>'''Figure 1: File Context Configuration Files - '''''The two files copied to the policy area will be used by the file labeling utilities to relabel files.''</center>]]
+
# Home Context for user root
 +
/root/\.wine(/.*)? unconfined_u:object_r:wine_home_t:s0
 +
</pre>
 +
 
 +
'''file_contexts''' - All other lines are extracted and added to the file_contexts file as they are files not associated to a users home directory.  
  
 
'''The format of the file_contexts.template file is as follows:'''
 
'''The format of the file_contexts.template file is as follows:'''
  
Each line within the file consists of either type of entry:
+
Each line within the file consists of the following:
 
<pre>
 
<pre>
pathname_regexp opt_security_context
+
pathname_regexp [file_type] opt_security_context
</pre>
+
'''Or'''
+
<pre>
+
pathname_regexp file_type opt_security_context
+
 
</pre>
 
</pre>
 +
'''Where:'''
  
'''Where:'''
 
 
{| border="1"
 
{| border="1"
| | pathname_regexp
+
| pathname_regexp
| | An entry that defines the pathname in the form of a regular expression.
+
| An entry that defines the pathname that may be in the form of a regular expression.
  
 
The metacharacters '^' (match beginning of line) and '$' (match end of line) are automatically added to the expression by the routines that process this file, however they can be over-ridden by using '.*' at either the beginning or end of the expression (see the example file_contexts files below).  
 
The metacharacters '^' (match beginning of line) and '$' (match end of line) are automatically added to the expression by the routines that process this file, however they can be over-ridden by using '.*' at either the beginning or end of the expression (see the example file_contexts files below).  
  
There are also keywords of HOME_ROOT, HOME_DIR, ROLE and USER that are used by file labeling commands (see the keyword definitions below and the ./modules/active/homedir_template file section for their usage).
+
There are also keywords of HOME_ROOT, HOME_DIR, ROLE and USER that are used by file labeling commands (see the keyword definitions below and the [[#modules/active/homedir_template | modules/active/homedir_template]] file section for their usage).
  
 
|-
 
|-
| | file_type
+
| file_type
| | The file_type options are:
+
| One of the following optional file_type entries (note if blank means "all file types"):
  
'-b' - Block Device       '-c' - Character Device
+
'<tt>-b</tt>' - Block Device '<tt>-c</tt>' - Character Device
  
'-d' - Directory         '-p' - Named Pipe
+
'<tt>-d</tt>' - Directory '<tt>-p</tt>' - Named Pipe (FIFO)
  
'-l' - Symbolic Link     '-s' - Socket
+
'<tt>-l</tt>' - Symbolic Link '<tt>-s</tt>' - Socket File
  
'--' - Ordinary file
+
'<tt>--</tt>' - Ordinary file
  
|-
+
By convention this entry is known as 'file type', however it really represents the 'file object class'.
| | opt_security_context
+
| | This entry can be either:
+
  
 +
|-
 +
| opt_security_context
 +
| This entry can be either:
 
# The security context, including the MLS / MCS level or range if applicable that will be assigned to the file.
 
# The security context, including the MLS / MCS level or range if applicable that will be assigned to the file.
# A value of <nowiki><<none>></nowiki> can be used to indicate that the matching files should not be re-labeled.  
+
# A value of <nowiki><<none>></nowiki> can be used to indicate that matching files should not be re-labeled.  
 
+
 
+
  
 
|}
 
|}
  
  
'''Keywords that can be in the file_contexts.template''' '''file are:'''
+
'''Keywords that can be in the file_contexts.template file are:'''
 +
 
 
{| border="1"
 
{| border="1"
| | HOME_ROOT
+
| HOME_ROOT
| | This keyword is replaced by the GNU / Linux users root home directory, normally '/home'.
+
| This keyword is replaced by the GNU / Linux users root home directory, normally '/home' is the default.
  
 
|-
 
|-
| | HOME_DIR
+
| HOME_DIR
| | This keyword is replaced by the GNU / Linux users home directory, normally '/home/'.
+
| This keyword is replaced by the GNU / Linux users home directory, normally '/home/' is the default.
  
 
|-
 
|-
| | ROLE
+
| USER
| | This keyword is replaced by the 'prefix' entry from the users_extra configuration file that corresponds to the SELinux users user id. Example users_extra configuration file entries are:
+
| This keyword will be replaced by the users GNU / Linux user id.
 +
 
 +
|-
 +
| ROLE
 +
| This keyword is replaced by the 'prefix' entry from the users_extra configuration file that corresponds to the SELinux users user id. Example users_extra configuration file entries are:
 
<pre>
 
<pre>
user user_u   prefix user;
+
user user_u prefix user;
user staff_u prefix staff;
+
user staff_u prefix staff;
user group1_u prefix group1;
+
 
</pre>
 
</pre>
  
It is used for files and directories within the users home directory area when relabeling takes place to allow the domain context to be based on a specific role (or any identifier !!) to allow easier identification in log files.  
+
It is used for files and directories within the users home directory area.  
  
It can be added by the semanage user command as follows:
+
The prefix can be added by the semanage <tt>login</tt> command as follows (although note that the <tt>-P</tt> option is suppressed when help is displayed as it is generally it is not used (defaults to <tt>user</tt>) - see [http://blog.gmane.org/gmane.linux.redhat.fedora.selinux/month=20110701 http://blog.gmane.org/gmane.linux.redhat.fedora.selinux/month=20110701] for further information):
 
<pre>
 
<pre>
<nowiki># Add prefix for SELinux user:</nowiki>
+
# Add a Linux user:
semanage user -a -R staff_r -P group1 group1_u
+
adduser rch
  
<nowiki># Add login user:</nowiki>
+
# Modify staff_u SELinux user and prefix:
semanage login -a -s group1_u rch
+
semanage user -m -R staff_r -P staff staff_u
 +
 
 +
# Associate the SELinux user to the Linux user:
 +
semanage login -a -s staff_u rch
 
</pre>
 
</pre>
  
The usage is similar to the Reference Policy 'per_role_template' (<nowiki><param name="userdomain_prefix"></nowiki>) that is an optional component of the external interface file (see the ftp.if or ssh.if files in the Reference Policy source). This feature will probably be removed as the semanage user -P option is more flexible !!!.
 
  
|-
 
| | USER
 
| | This keyword will be replaced by the users GNU / Linux user id.
 
  
 
|}
 
|}
  
  
'''Example file_contexts.template''' '''contents:'''
+
'''Example file_contexts.template''' '''contents from targeted policy:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/file_contexts.template - These sample entries
+
# modules/active/file_contexts.template - These sample entries
<nowiki># have been taken from the Reference Policy and show the </nowiki>
+
# have been taken from the targeted policy and show the
<nowiki># HOME_DIR, HOME_ROOT keywords whose lines will be extracted and </nowiki>
+
# HOME_DIR, HOME_ROOT and USER keywords whose lines will be
<nowiki># added to the </nowiki>homedir_template file that is used to manage  
+
# extracted and added to the homedir_template file that is
<nowiki># user home directory entries. The USER keyword will be replaced </nowiki>
+
# used to manage user home directory entries.
<nowiki># by the file labeling utilities with the corresponding GNU / </nowiki>
+
<nowiki># Linux user id. The ROLE keyword will be replaced by the prefix </nowiki>
+
<nowiki># assigned to the SELinux seuser_id taken from the users_extra </nowiki>
+
<nowiki># file.</nowiki>
+
  
/.*                         system_u:object_r:default_t
+
/.*                       system_u:object_r:default_t:s0
/a?quota\.(user|group) -- system_u:object_r:quota_db_t
+
/[^/]+                -- system_u:object_r:etc_runtime_t:s0
/xen(/.*)?                 system_u:object_r:xen_image_t
+
/a?quota\.(user|group) -- system_u:object_r:quota_db_t:s0
/dev/mcdx?             -b  system_u:object_r:removable_device_t
+
/nsr(/.*)?               system_u:object_r:var_t:s0
HOME_DIR/.+                system_u:object_r:user_home_t
+
/sys(/.*)?               system_u:object_r:sysfs_t:s0
/var/log/.*                 system_u:object_r:var_log_t
+
...
/tmp/gconfd-USER/.*    --  system_u:object_r:gconf_tmp_t
+
/etc/ntop.*               system_u:object_r:ntop_etc_t:s0
/var/log/sxid\.log.*    -- system_u:object_r:sxid_log_t
+
HOME_DIR/.+              system_u:object_r:user_home_t:s0
<nowiki>/var/log/messages[^/]*</nowiki>      system_u:object_r:var_log_t
+
/dev/dri/.+            -c system_u:object_r:dri_device_t:s0
/var/run/wnn-unix(/.*)      system_u:object_r:canna_var_run_t
+
...
HOME_DIR/\.ircmotd      -- system_u:object_r:ROLE_irc_home_t
+
/tmp/gconfd-USER      -d system_u:object_r:user_tmp_t:s0
HOME_ROOT/lost\+found/.*    <nowiki><<none>></nowiki>
+
...
HOME_DIR/\.config/gtk-.*    system_u:object_r:gnome_home_t
+
/tmp/gconfd-USER/.*   -- system_u:object_r:gconf_tmp_t:s0
 +
...
 +
HOME_ROOT/\.journal      <<none>>
 
</pre>
 
</pre>
  
== file_contexts File ==
+
== modules/active/file_contexts File ==
This file becomes the policies ./contexts/files/file_contexts file and is built from entries in the ./modules/active/file_contexts.template file as explained above and shown in Figure 1. It is then used by the file labeling utilities to ensure that files and directories are labeled according to the policy.
+
This file becomes the policies [[PolicyConfigurationFiles#contexts/files/file_contexts | contexts/files/file_contexts]] file and is built from entries in the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file as explained above and shown in the [http://selinuxproject.org/~rhaines/NB4-diagrams/25-file_contexts.png File Context Configuration Files] diagram. It is then used by the file labeling utilities to ensure that files and directories are labeled according to the policy.
  
The format of the file_contexts file is the same as the ./modules/active/file_contexts.template file.
+
The format of the file_contexts file is the same as the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file.
  
 
The USER keyword is replaced by the users GNU / Linux user id when the file labeling utilities are run.
 
The USER keyword is replaced by the users GNU / Linux user id when the file labeling utilities are run.
Line 167: Line 179:
 
'''Example file_contexts contents:'''
 
'''Example file_contexts contents:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/file_contexts - These sample entries have been
+
# modules/active/file_contexts - These sample entries have
<nowiki># taken from the Reference Policy and show the USER keyword </nowiki>
+
# been taken from the targeted policy.
<nowiki># that will be </nowiki>replaced by the users GNU / Linux user id when the
+
# The keywords HOME_DIR, HOME_ROOT, USER and ROLE have been
<nowiki># file labeling utilities are run.</nowiki>
+
# removed and put in the homedir_template file.
<nowiki># The other keywords HOME_DIR, HOME_ROOT and ROLE have been</nowiki>
+
<nowiki># extracted and put in the homedir_template file.</nowiki>
+
  
/.*                       system_u:object_r:default_t
+
/.*                       system_u:object_r:default_t:s0
/a?quota\.(user|group) -- system_u:object_r:quota_db_t
+
/[^/]+                -- system_u:object_r:etc_runtime_t:s0
/xen(/.*)?                 system_u:object_r:xen_image_t
+
/a?quota\.(user|group) -- system_u:object_r:quota_db_t:s0
/dev/mcdx?             -b  system_u:object_r:removable_device_t
+
/nsr(/.*)?               system_u:object_r:var_t:s0
/var/log/.*                system_u:object_r:var_log_t
+
/sys(/.*)?               system_u:object_r:sysfs_t:s0
/tmp/gconfd-USER/.*   -- system_u:object_r:gconf_tmp_t
+
/xen(/.*)?               system_u:object_r:xen_image_t:s0
/var/log/sxid\.log.*   -system_u:object_r:sxid_log_t
+
/mnt(/[^/]*)          -l system_u:object_r:mnt_t:s0
<nowiki>/var/log/messages[^/]*</nowiki>      system_u:object_r:var_log_t
+
/mnt(/[^/]*)?          -d system_u:object_r:mnt_t:s0
/var/run/wnn-unix(/.*)    system_u:object_r:canna_var_run_t
+
/bin/.*                  system_u:object_r:bin_t:s0
 +
/dev/.*                   system_u:object_r:device_t:s0
 +
/usr/.*                  system_u:object_r:usr_t:s0
 +
/var/.*                  system_u:object_r:var_t:s0
 +
/run/.*                  system_u:object_r:var_run_t:s0
 +
/srv/.*                   system_u:object_r:var_t:s0
 +
/tmp/.*                  <<none>>
 
</pre>
 
</pre>
 +
 
<pre>
 
<pre>
<nowiki># </nowiki>./contexts/files/file_contexts - Sample entries taken from the  
+
# contexts/files/file_contexts - Sample entries from the MLS reference policy.  
<nowiki># MLS reference policy. </nowiki>
+
# Notes:
 +
# 1) The fixed_disk_device_t is labeled SystemHigh (s15:c0.c255)
 +
# as it needs to be trusted. Also some logs and configuration
 +
# files are labeled SystemHigh as they contain sensitive
 +
# information used by trusted applications.
 +
#
 +
# 2) Some directories (e.g. ''/tmp'') are labeled
 +
# SystemLow-SystemHigh (s0-s15:c0.c255) as they will
 +
# support polyinstantiated directories.
  
<nowiki># Notes:</nowiki>
+
/.*system_u:object_r:default_t:s0
<nowiki># 1) The </nowiki>fixed_disk_device_t is labeled SystemHigh (s15:c0.c255)
+
/a?quota\.(user|group) -- system_u:object_r:quota_db_t:s0
<nowiki># </nowiki>as it needs to be trusted. Also some logs and configuration
+
/mnt(/[^/]*)           -l system_u:object_r:mnt_t:s0
<nowiki># </nowiki>files are labeled SystemHigh as they contain sensitive
+
/mnt/[^/]*/.*            <<none>>
<nowiki># </nowiki>information used by trusted applications.
+
/dev/.*mouse.*        -c system_u:object_r:mouse_device_t:s0
<nowiki>#</nowiki>
+
/dev/.*tty[^/]*        -c system_u:object_r:tty_device_t:s0
<nowiki># 2) Some directories (e.g. </nowiki>/tmp) are labeled
+
/dev/[shmx]d[^/]*      -b system_u:object_r:fixed_disk_device_t:s15:c0.c255
<nowiki># </nowiki>SystemLow-SystemHigh (s0-s15:c0.c255) as they will
+
/var/[xgk]dm(/.*)?        system_u:object_r:xserver_log_t:s0
<nowiki># </nowiki>support polyinstantiated directories.
+
/dev/(raw/)?rawctl    -c system_u:object_r:fixed_disk_device_t:s15:c0.c255
 +
/tmp                  -d system_u:object_r:tmp_t:s0-s15:c0.c255
 +
/dev/pts              -d system_u:object_r:devpts_t:s0-s15:c0.c255
 +
/var/log              -d system_u:object_r:var_log_t:s0-s15:c0.c255
 +
/var/tmp               -d system_u:object_r:tmp_t:s0-s15:c0.c255
 +
/var/run              -d system_u:object_r:var_run_t:s0-s15:c0.c255
 +
/usr/tmp              -d system_u:object_r:tmp_t:s0-s15:c0.c255
 +
<pre>
  
/.*                        system_u:object_r:default_t:s0
+
== modules/active/homedir_template File ==
/a?quota\.(user|group)  --  system_u:object_r:quota_db_t:s0
+
This file is built from entries in the [[#modules/active/file_contexts.template | file_contexts.template]] file (as shown in the [http://selinuxproject.org/~rhaines/NB4-diagrams/25-file_contexts.png File Context Configuration Files] diagram) and explained in the [[#modules/modules/active/file_contexts.template | modules/active/file_contexts.template]] section.  
<nowiki>/mnt(/[^/]*)</nowiki>  -l  system_u:object_r:mnt_t:s0
+
<nowiki>/mnt/[^/]*/.*</nowiki>      <nowiki><<none>></nowiki>
+
/dev/.*mouse.*          -c  system_u:object_r:mouse_device_t:s0
+
<nowiki>/dev/.*tty[^/]*</nowiki>  -c  system_u:object_r:tty_device_t:s0
+
<nowiki>/dev/[shmx]d[^/]*</nowiki>  -b  system_u:object_r:fixed_disk_device_t:s15:c0.c255
+
<nowiki>/var/[xgk]dm(/.*)?</nowiki>      system_u:object_r:xserver_log_t:s0
+
/dev/(raw/)?rawctl      -c  system_u:object_r:fixed_disk_device_t:s15:c0.c255
+
/tmp                    -d  system_u:object_r:tmp_t:s0-s15:c0.c255
+
dev/pts                -d  system_u:object_r:devpts_t:s0-s15:c0.c255
+
/var/log                -d  system_u:object_r:var_log_t:s0-s15:c0.c255
+
/var/tmp                -d  system_u:object_r:tmp_t:s0-s15:c0.c255
+
/var/run                -d  system_u:object_r:var_run_t:s0-s15:c0.c255
+
/usr/tmp                -d  system_u:object_r:tmp_t:s0-s15:c0.c255
+
</pre>
+
  
 +
The file is used by genhomedircon, semanage login or semanage user to generate individual user entries in the [[#modules/active/file_contexts.homedirs | file_contexts.homedirs]] file.
  
== homedir_template File ==
+
The homedir_template file has the same per line format as the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file.
This file is built from entries in the file_contexts.template file (as shown in Figure 1) and explained in the ./modules/active/file_contexts.template section.
+
 
+
The file is used by genhomedircon, semanage login or semanage user to generate individual user entries in the file_contexts.homedirs file.
+
 
+
The homedir_template file has the same per line format as the ./modules/active/file_contexts.template file.
+
  
 
'''Example file contents:'''
 
'''Example file contents:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/homedir_template - These sample entries have  
+
# modules/active/homedir_template - These sample entries have  
<nowiki># been taken from the Reference Policy and show the </nowiki>
+
# been taken from the targeted policy and show the  
<nowiki># HOME_DIR, HOME_ROOT and ROLE keywords that are used to manage </nowiki>
+
# HOME_DIR, HOME_ROOT and USER keywords that are used to manage  
<nowiki># users home directories:</nowiki>
+
# users home directories:
  
HOME_DIR/.+                   system_u:object_r:user_home_t
+
HOME_DIR/.+           system_u:object_r:user_home_t:s0
HOME_DIR/\.ircmotd        -- system_u:object_r:ROLE_irc_home_t
+
/tmp/gconfd-USER    -d system_u:object_r:user_tmp_t:s0
HOME_ROOT/lost\+found/.*      <nowiki><<none>></nowiki>
+
/tmp/gconfd-USER/.* -- system_u:object_r:gconf_tmp_t:s0
HOME_DIR/\.config/gtk-.*      system_u:object_r:gnome_home_t
+
HOME_ROOT/\.journal    <<none>>
 
</pre>
 
</pre>
  
 +
== modules/active/file_contexts.homedirs File ==
 +
This file becomes the policies [[PolicyConfigurationFiles#contexts/files/file_contexts.homedirs | contexts/files/file_contexts.homedirs]] file when building policy as shown in the [http://selinuxproject.org/~rhaines/NB4-diagrams/25-file_contexts.png File Context Configuration Files] diagram. It is then used by the file labeling utilities to ensure that users home directory areas are labeled according to the policy.
  
== file_contexts.homedirs File ==
+
The file can be built by the genhomedircon command (that just calls /usr/sbin/semodule -Bn) or if using semanage with user or login options to manage users, where it is called automatically as it is now a libsepol library function.  
This file becomes the policies ./contexts/files/file_contexts.homedirs file when building policy as shown in Figure 1. It is then used by the file labeling utilities to ensure that users home directory areas are labeled according to the policy.
+
 
+
The file can be built by the genhomedircon command (in F-10 this just calls /usr/sin/semodule -Bn) or if using semanage with user or login options to manage users, where it is called automatically as it is now a libsepol library function.  
+
  
The file_contexts.homedirs file has the same per line format as the ./modules/active/file_contexts.template file, however the HOME_DIR, ROOT_DIR and ROLE keywords will be replaced as explained in the keyword definitions section above. Note that the ROLE keyword will only be replaced for those valid types within the policy (for example if staff_irc_home_t cannot be found in the policy it will be silently dropped from the file_context.homedirs when being built '''True?'''.
+
The file_contexts.homedirs file has the same per line format as the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file, however the HOME_DIR, ROOT_DIR, <tt>ROLE</tt> and USER keywords will be replaced as explained in the keyword definitions section above.
  
 
'''Example file_contexts.homedirs contents:'''
 
'''Example file_contexts.homedirs contents:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/file_contexts.homedirs - These sample entries  
+
# modules/active/file_contexts.homedirs - These sample entries  
<nowiki># have been taken from the Reference Policy and show that </nowiki>
+
# have been taken from the targeted policy and show that  
<nowiki># the HOME_DIR, HOME_ROOT and ROLE keywords have been replaced</nowiki>
+
# the HOME_DIR, HOME_ROOT and USER keywords have been replaced
<nowiki># by entries as explained above.</nowiki>
+
# by entries as explained above.
<nowiki>#</nowiki>
+
#
<nowiki># User-specific file contexts, generated via libsemanage</nowiki>
+
# Home Context for the default user (unconfined_u)
<nowiki># use semanage command to manage system users to change the file_context</nowiki>
+
/home/[^/]*/.+                unconfined_u:object_r:user_home_t:s0
<nowiki>#</nowiki>
+
/home/[^/]*/.maildir(/.*)?    unconfined_u:object_r:mail_home_rw_t:s0
<nowiki># Home Context for user user_u</nowiki>
+
...
 +
/tmp/gconfd-.*/.*          -- unconfined_u:object_r:gconf_tmp_t:s0
 +
/tmp/gconfd-.*            -d unconfined_u:object_r:user_tmp_t:s0
  
/home/.+                  system_u:object_r:user_home_t
+
# Home Context for user rch
/home/\.ircmotd        -- system_u:object_r:user_irc_home_t
+
/home/rch/.+                  staff_u:object_r:user_home_t:s0
/home/lost\+found/.*     <nowiki><<none>></nowiki>
+
/home/rch/.maildir(/.*)?      staff_u:object_r:mail_home_rw_t:s0
/home/\.config/gtk-.*    system_u:object_r:gnome_home_t
+
...
 +
/tmp/gconfd-rch/.*         -- staff_u:object_r:gconf_tmp_t:s0
 +
/tmp/gconfd-rch            -d staff_u:object_r:user_tmp_t:s0
  
<nowiki># Home Context for user root</nowiki>
+
# Home Context for user root
/root/.+                 system_u:object_r:user_home_t
+
/root/.+                     unconfined_u:object_r:user_home_t:s0
/root/\.ircmotd        -- system_u:object_r:user_irc_home_t
+
/root/.maildir(/.*)?          unconfined_u:object_r:mail_home_rw_t:s0
/root/lost\+found/.*     <nowiki><<none>></nowiki>
+
...
/root/\.config/gtk-.*    system_u:object_r:gnome_home_t
+
/tmp/gconfd-root/.*       -- unconfined_u:object_r:gconf_tmp_t:s0
 +
/tmp/gconfd-root          -d unconfined_u:object_r:user_tmp_t:s0
 
</pre>
 
</pre>
  
== netfilter_contexts & netfilter.local File ==
+
== modules/active/netfilter_contexts & netfilter.local File ==
These files do not seem to be used at present. There is code to produce a netfilter_contexts file for use by the GNU/Linux iptables service (This uses SECMARK labeling that has been utilised by SELinux) in the Reference Policy that would generate a file similar to the example below, however there seems much debate on how they should be managed (see [https://bugzilla.redhat.com/show_bug.cgi?id=201573 bug 201573 - Secmark iptables integration] for details).
+
These files are not used at present. There is code to produce a netfilter_contexts file for use by the GNU/Linux iptables service<ref name="ftn35"><sup>This uses SECMARK labeling that has been utilised by SELinux as described in the [[NB_Networking | SELinux Networking Support]] section.</sup></ref> in the Reference Policy that would generate a file similar to the example below, however there seems much debate on how they should be managed (see [https://bugzilla.redhat.com/show_bug.cgi?id=201573 bug 201573 - Secmark iptables integration] for details).
  
'''Example netfilter_contexts contents:'''
+
== modules/active/policy.kern File ==
<pre>
+
This is the binary policy file built by either the '''semanage'''(8) or '''semodule'''(8) commands (depending on the configuration action), that then becomes the binary policy to be loaded into the kernel.
<nowiki># This is an example that would be generated by the Reference </nowiki>
+
<nowiki># Policy, however seems on hold.</nowiki>
+
 
+
<nowiki># This is the standard iptables header:</nowiki>
+
<nowiki>*mangle</nowiki>
+
 
+
<nowiki>:PREROUTING ACCEPT [0:0]</nowiki>
+
<nowiki>:INPUT ACCEPT [0:0]</nowiki>
+
<nowiki>:FORWARD ACCEPT [0:0]</nowiki>
+
<nowiki>:OUTPUT ACCEPT [0:0]</nowiki>
+
<nowiki>:POSTROUTING ACCEPT [0:0]</nowiki>
+
<nowiki>:selinux_input - [0:0]</nowiki>
+
<nowiki>:selinux_output - [0:0]</nowiki>
+
<nowiki>:selinux_new_input - [0:0]</nowiki>
+
<nowiki>:selinux_new_output - [0:0]</nowiki>
+
-A INPUT -j selinux_input
+
-A OUTPUT -j selinux_output
+
-A selinux_input -m state --state NEW -j selinux_new_input
+
-A selinux_input -m state --state RELATED,ESTABLISHED -j CONNSECMARK --restore
+
-A selinux_output -m state --state NEW -j selinux_new_output
+
-A selinux_output -m state --state RELATED,ESTABLISHED -j CONNSECMARK --restore
+
-A selinux_new_input -j SECMARK --selctx system_u:object_r:server_packet_t:s0
+
 
+
<nowiki># These entries are built from the ports defined in the policy:</nowiki>
+
-A selinux_new_input -p udp --dport 7007 -j SECMARK --selctx system_u:object_r:afs_bos_server_packet_t:s0
+
-A selinux_new_input -p tcp --dport 2040 -j SECMARK --selctx system_u:object_r:afs_fs_server_packet_t:s0
+
-A selinux_new_input -p udp --dport 7000 -j SECMARK --selctx system_u:object_r:afs_fs_server_packet_t:s0
+
-A selinux_new_input -p udp --dport 7005 -j SECMARK --selctx system_u:object_r:afs_fs_server_packet_t:s0
+
.....
+
.....
+
<nowiki># This is the standard iptables trailer:</nowiki>
+
-A selinux_new_input -j CONNSECMARK --save
+
-A selinux_new_input -j RETURN
+
-A selinux_new_output -j CONNSECMARK --save
+
-A selinux_new_output -j RETURN
+
COMMIT
+
</pre>
+
 
+
== policy.kern File ==
+
This is the binary policy file built by either the semanage or semodule process (depending on the configuration action), that is then copied as the ./policy/policy.[ver] binary policy that will be loaded into the kernel.
+
 
+
== seusers.final and seusers Files ==
+
The seusers.final file maps GNU / Linux users to SELinux users and becomes the policies seusers file as discussed in the ./seusers section. (Many seusers make confusion: The ./modules/active/seusers file is used to hold initial seusers entries, the ./modules/active/seusers.final file holds the complete entries that then becomes the policy ./seusers file). The seusers.final file is built or modified when:
+
  
* Building a policy where an optional seusers file has been included in the base package via the semodule_package(8) command (signified by the -s flag) as follows (The Reference Policy Makefile 'Rules.modular' script uses this method to install the initial seusers file):
+
== modules/active/seusers.final and seusers Files ==
 +
The seusers.final file maps GNU / Linux users to SELinux users and becomes the policies seusers<ref name="ftn36"><sup>Many seusers make confusion: The modules/active/seusers file is used to hold initial seusers entries, the modules/active/seusers.final file holds the complete entries that then becomes the policy <tt>seusers</tt> file.</sup></ref> file as discussed in the [[PolicyConfigurationFiles#seusers | seusers]] section. The seusers.final file is built or modified when:
 +
* Building a policy where an optional seusers file has been included in the base package via the '''semodule_package'''(8) command (signified by the -s flag) as follows<ref name="ftn37"><sup>The Reference Policy Makefile 'Rules.modular' script uses this method to install the initial seusers file.</sup></ref>:
 
<pre>
 
<pre>
 
semodule_package -o base.pp -m base.mod -s seusers ...  
 
semodule_package -o base.pp -m base.mod -s seusers ...  
 
</pre>
 
</pre>
 
 
The seusers file would be extracted by the subsequent semodule command when building the policy to produce the seusers.final file.
 
The seusers file would be extracted by the subsequent semodule command when building the policy to produce the seusers.final file.
  
Line 328: Line 304:
 
semanage login -a -s staff_u rch  
 
semanage login -a -s staff_u rch  
 
</pre>
 
</pre>
 +
This action will update the seusers file that would then be used to produce the seusers.final file with both policy and locally defined user mapping.
  
This action will update the seusers file that would then be used to produce the seusers.final file with both policy and locally defined user mapping.
+
It is also possible to associate a GNU / Linux group of users to an SELinux user as follows:
 +
<pre>
 +
semanage login -a -s staff_u %staff_group
 +
</pre>
  
 
'''The format of the seusers.final & seusers files are as follows:'''
 
'''The format of the seusers.final & seusers files are as follows:'''
 
<pre>
 
<pre>
<nowiki>user_id:seuser_id [:range]</nowiki>
+
[%]user_id:seuser_id[:range]
 
</pre>
 
</pre>
  
 
'''Where:'''
 
'''Where:'''
 +
 
{| border="1"
 
{| border="1"
| | user_id
+
| user_id
| | The GNU / Linux user identity.
+
| Where <tt>user_id</tt> is the GNU / Linux user identity. If this is a GNU / Linux <tt>group_id</tt> then it will be preceded with the '<tt>%</tt>' sign as shown in the example below.
  
 
|-
 
|-
| | seuser_id
+
| seuser_id
| | The SELinux user identity.
+
| The SELinux user identity.
  
 
|-
 
|-
| | range
+
| range
| | The optional range as defined in the MLS range definition section.
+
| The optional <tt>level</tt> or range.
  
 
|}
 
|}
Line 354: Line 335:
 
'''Example seusers.final file contents:'''
 
'''Example seusers.final file contents:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/seusers.final
+
# modules/active/seusers.final
 
+
 
system_u:system_u
 
system_u:system_u
 
root:root
 
root:root
Line 363: Line 343:
 
'''Example semanage login command to add a GNU / Linux user mapping:'''
 
'''Example semanage login command to add a GNU / Linux user mapping:'''
 
<pre>
 
<pre>
<nowiki># This command will add the </nowiki>rch:user_u entry in the seusers file:  
+
# This command will add the rch:user_u entry in the seusers file:
  
 
semanage login -a -s user_u rch
 
semanage login -a -s user_u rch
Line 370: Line 350:
 
'''The resulting seusers file would be:'''
 
'''The resulting seusers file would be:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/seusers
+
# modules/active/seusers
  
 
rch:user_u
 
rch:user_u
 
</pre>
 
</pre>
 +
 
'''The seusers.final file that will become the <nowiki>./<policy_name>/seusers</nowiki> file is as follows:'''
 
'''The seusers.final file that will become the <nowiki>./<policy_name>/seusers</nowiki> file is as follows:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/seusers.final
+
# /modules/active/seusers.final
  
 
system_u:system_u
 
system_u:system_u
Line 384: Line 365:
 
</pre>
 
</pre>
  
 +
'''Example semanage login command to add a GNU / Linux group mapping:'''
 +
<pre>
 +
# This command will add the %user_group:user_u entry in the seusers file:
  
== users_extra, users_extra.local and users.local Files ==
+
semanage login -a -s user_u %user_group
These three files work together to describe SELinux user information as follows:
+
</pre>
  
* The users_extra and users_extra.local files are used to map a prefix to users home directories as discussed in the ./modules/active/file_contexts.template file section, where it is used to replace the ROLE keyword. The prefix is linked to an SELinux user id and should reflect the users role. The semanage user command will allow a prefix to be added via the -P flag.  
+
'''The resulting seusers file would be:'''
 +
<pre>
 +
# /modules/active/seusers
 +
 
 +
rch:user_u
 +
%user_group:user_u
 +
</pre>
 +
 
 +
'''The seusers.final file that will become the <nowiki>./<policy_name>/seusers</nowiki> file is as follows:'''
 +
<pre>
 +
# modules/active/seusers.final
 +
 
 +
system_u:system_u
 +
root:root
 +
__default__:user_u
 +
rch:user_u
 +
%user_group:user_u
 +
</pre>
 +
 
 +
== modules/active/users_extra, users_extra.local and users.local Files ==
 +
These three files work together to describe SELinux user information as follows:
 +
* The users_extra and users_extra.local files are used to map a prefix to users home directories as discussed in the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file section, where it is used to replace the ROLE keyword. The prefix is linked to an SELinux user id and should reflect the users role. The semanage user command will allow a prefix to be added via the -P flag (although no longer used by policies as discussed in the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file section).  
  
 
The users_extra file contains all the policy prefix entries, and the users_extra.local file contains those generated by the semanage user command.
 
The users_extra file contains all the policy prefix entries, and the users_extra.local file contains those generated by the semanage user command.
  
The users_extra file can optionally be included in the base package via the semodule_package(8) command (signified by the -u flag) as follows (The Reference Policy Makefile 'Rules.modular' script uses this method to install the initial users_extra file):
+
The users_extra file can optionally be included in the base package via the '''semodule_package'''(8) command (signified by the -u flag) as follows<ref name="ftn38"><sup>The Reference Policy Makefile 'Rules.modular' script uses this method to install the initial users_extra file.</sup></ref>:
 
<pre>
 
<pre>
 
semodule_package -o base.pp -m base.mod -u users_extra ...  
 
semodule_package -o base.pp -m base.mod -u users_extra ...  
Line 399: Line 404:
 
The users_extra file would then be extracted by a subsequent semodule command when building the policy.
 
The users_extra file would then be extracted by a subsequent semodule command when building the policy.
  
* The users.local file is used to add new SELinux users to the policy without editing the policy source itself (with each line in the file following a user policy language statement). This is useful when only the Reference Policy headers are installed and additional users need to added. The semanage user command will allow a new SELinux user to be added that would generate the user.local file and if a -P flag has been specified, then a users_extra.local file is also generated (note: if this is a new SELinux user and a prefix is not specified a default prefix of user is generated).  
+
* The users.local file is used to add new SELinux users to the policy without editing the policy source itself (with each line in the file following a policy language [[KernelPolicyLanguage#user | user]] statement section). This is useful when only the Reference Policy headers are installed and additional users need to added. The semanage user command will allow a new SELinux user to be added that would generate the user.local file and if a -P flag has been specified, then a users_extra.local file is also updated (note: if this is a new SELinux user and a prefix is not specified a default prefix of user is generated).  
  
 
The sections that follow will:
 
The sections that follow will:
 
 
* Define the format and show example users_extra and users_extra.local files.
 
* Define the format and show example users_extra and users_extra.local files.
 
* Execute an semanage user command that will add a new SELinux user and associated prefix, and show the resulting users_extra, users_extra.local and users.local files.  
 
* Execute an semanage user command that will add a new SELinux user and associated prefix, and show the resulting users_extra, users_extra.local and users.local files.  
  
Note that each line of the users.local file contains a user statement that is defined in the policy language user Statement section, and will be built into the policy via the semanage command.
+
Note that each line of the users.local file contains a user statement that is defined in the policy language [[KernelPolicyLanguage#user | user]] statement section, and will be built into the policy via the semanage command.
  
 
'''The format of the users_extra & users_extra.local files are as follows:'''
 
'''The format of the users_extra & users_extra.local files are as follows:'''
Line 414: Line 418:
  
 
'''Where:'''
 
'''Where:'''
 +
 
{| border="1"
 
{| border="1"
| | user
+
| user
| | The user keyword.
+
| The user keyword.
  
 
|-
 
|-
| | seuser_id
+
| seuser_id
| | The SELinux user identity.
+
| The SELinux user identity.
  
 
|-
 
|-
| | prefix
+
| prefix
| | The prefix keyword.
+
| The prefix keyword.
  
 
|-
 
|-
| | prefix_id
+
| prefix_id
| | An identifier that will be used to replace the ROLE keyword within the ./modules/active/homedir_template file when building the ./modules/active/file_contexts.homedirs file for the relabeling utilities to set the security context on users home directories.
+
| An identifier that will be used to replace the ROLE keyword within the modules/active/homedir_template file when building the ./modules/active/file_contexts.homedirs file for the relabeling utilities to set the security context on users home directories.
  
 
|}
 
|}
Line 435: Line 440:
 
'''Example users_extra file contents:'''
 
'''Example users_extra file contents:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/users_extra entries, note that the  
+
# modules/active/users_extra entries, note that the  
<nowiki># </nowiki>users_extra.local file contents are similar and generated by  
+
# users_extra.local file contents are similar and generated by  
<nowiki># the semanage user command.</nowiki>
+
# the semanage user command.
  
 
user user_u prefix user;
 
user user_u prefix user;
Line 447: Line 452:
 
'''Example semanage user command to add a new SELinux user:'''
 
'''Example semanage user command to add a new SELinux user:'''
 
<pre>
 
<pre>
<nowiki># This command will add the </nowiki>user test_u prefix staff entry in  
+
# This command will add the user test_u prefix staff entry in  
<nowiki># the users_extra.local file: </nowiki>
+
# the users_extra.local file:  
  
 
semanage user -a -R staff_r -P staff test_u
 
semanage user -a -R staff_r -P staff test_u
Line 455: Line 460:
 
'''The resulting users_extra.local file is as follows:'''
 
'''The resulting users_extra.local file is as follows:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/users_extra.local
+
# modules/active/users_extra.local
  
 
user test_u prefix staff;
 
user test_u prefix staff;
Line 462: Line 467:
 
'''The resulting users_extra file is as follows:'''
 
'''The resulting users_extra file is as follows:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/users_extra
+
# modules/active/users_extra
  
 
user user_u prefix user;
 
user user_u prefix user;
Line 473: Line 478:
 
'''The resulting users.local file is as follows:'''
 
'''The resulting users.local file is as follows:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/users.local file entry:
+
# modules/active/users.local file entry:
  
 
user test_u roles { staff_r } level s0 range s0;
 
user test_u roles { staff_r } level s0 range s0;
 
</pre>
 
</pre>
  
== booleans.local File ==
+
== modules/active/booleans.local File ==
This file is created and updated by the semanage boolean command and holds boolean value as requested. It should be noted that instead of using this file, the command allows a different file to be specified (see the semanage man page).
+
This file is created and updated by the <tt>semanage boolean</tt> command and holds boolean value as requested.
  
 
'''Example semanage boolean command to modify a boolean value:'''
 
'''Example semanage boolean command to modify a boolean value:'''
 
<pre>
 
<pre>
<nowiki># This command will add an entry in the booleans.local </nowiki>
+
# This command will add an entry in the booleans.local  
<nowiki># file and set the boolean value to off: </nowiki>
+
# file and set the boolean value to 'off':  
  
semanage boolean -m -0 ext_gateway_audit  
+
semanage boolean -m -0 ext_gateway_audit
 
</pre>
 
</pre>
  
'''The resulting booleans.local file would be:'''
+
'''The resulting <tt>booleans.</tt>local file would be:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/booleans.local
+
# modules/active/booleans.local
  
 
ext_gateway_audit=0
 
ext_gateway_audit=0
 
</pre>
 
</pre>
  
== file_contexts.local File ==
+
== modules/active/file_contexts.local File ==
 
This file is created and updated by the semanage fcontext command. It is used to hold file context information on files and directories that were not delivered by the core policy (i.e. they are not defined in any of the <nowiki>*.fc</nowiki> files delivered in the base and loadable modules).
 
This file is created and updated by the semanage fcontext command. It is used to hold file context information on files and directories that were not delivered by the core policy (i.e. they are not defined in any of the <nowiki>*.fc</nowiki> files delivered in the base and loadable modules).
  
 
The semanage command will add the information to the policy stores file_contexts.local file and then copy this file to the ./contexts/files/file_contexts.local file, where it will be used when the file context utilities are run.
 
The semanage command will add the information to the policy stores file_contexts.local file and then copy this file to the ./contexts/files/file_contexts.local file, where it will be used when the file context utilities are run.
  
The format of the file_contexts.local file is the same as the ./modules/active/file_contexts.template file.
+
The format of the file_contexts.local file is the same as the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file.
  
 
'''Example semanage fcontext command to add a new entry:'''
 
'''Example semanage fcontext command to add a new entry:'''
 
<pre>
 
<pre>
<nowiki># This command will add an entry in the file_contexts.local </nowiki>
+
# This command will add an entry in the file_contexts.local file:  
<nowiki># file: </nowiki>
+
  
 
semanage fcontext -a -t user_t /usr/move_file
 
semanage fcontext -a -t user_t /usr/move_file
  
<nowiki># </nowiki>Note that the type (-t flag) must exist in the policy  
+
# Note that the type (-t flag) must exist in the policy  
<nowiki># otherwise the command will fail.</nowiki>
+
# otherwise the command will fail.
 
</pre>
 
</pre>
  
 
'''The resulting file_contexts.local file would be:'''
 
'''The resulting file_contexts.local file would be:'''
 
<pre>
 
<pre>
<nowiki># </nowiki>./modules/active/file_contexts.local
+
# modules/active/file_contexts.local
  
 
/usr/move_filesystem_u:object_r:user_t
 
/usr/move_filesystem_u:object_r:user_t
 
</pre>
 
</pre>
  
 +
== modules/active/interfaces.local File ==
 +
This file is created and updated by the semanage interface command to hold network interface information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new interface information is then built into the policy by the '''semanage'''(8) command.
  
== interfaces.local File ==
+
Each line of the file contains a netifcon statement that is defined along with examples in the [[NetworkStatements#netifcon | netifcon]] statement section.
This file is created and updated by the semanage interface command to hold network interface information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new interface information is then built into the policy by the semanage process.
+
  
Each line of the file contains a netifcon statement that is defined along with examples in the netifcon Statement section.
+
== modules/active/nodes.local File ==
 +
This file is created and updated by the semanage node command to hold network address information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new node information is then built into the policy by the '''semanage'''(8) command.
  
== nodes.local File ==
+
Each line of the file contains a nodecon statement that is defined along with examples in the policy language [[KernelPolicyLanguage#nodecon | nodecon]] statement section.
This file is created and updated by the semanage node command to hold network address information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new node information is then built into the policy by the semanage process.
+
  
Each line of the file contains a nodecon statement that is defined along with examples in the policy language nodecon Statement section.
+
== modules/active/ports.local File ==
 +
This file is created and updated by the semanage port command to hold network port information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new port information is then built into the policy by the '''semanage'''(8) command.
  
== ports.local File ==
+
Each line of the file contains a portcon statement that is defined along with examples in the policy language [[KernelPolicyLanguage#portcon | portcon]] statement section.
This file is created and updated by the semanage port command to hold network port information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new port information is then built into the policy by the semanage process.
+
  
Each line of the file contains a portcon statement that is defined along with examples in the policy language portcon Statement section.
+
== modules/active/preserve_tunables File ==
 +
This file will only exist if the policy build specified that tunables should be preserved, if so they would be converted to booleans by the policy build process.
  
== modules Directory Contents ==
+
== modules/active/disable_dontaudit File ==
This directory contains the loadable modules (<nowiki><module_name>.pp</nowiki>) that have been packaged by the semodule_package command and placed in the store by the semodule command as shown in the following example:
+
This file will only exist if the policy build specified that [[AVCRules#dontaudit | dontaudit]] rules should be disabled.
 +
 
 +
== modules/active/modules Directory Contents ==
 +
This directory contains loadable modules (<nowiki><module_name>.pp</nowiki> or when disabled <tt><nowiki><module_name>.pp.disabled</nowiki></tt>) that have been built by the semodule_package command and placed in the store by the semodule or <tt>semanage module -a</tt> commands as shown in the following example:
 
<pre>
 
<pre>
<nowiki># Package the module </nowiki>''move_file_c'':
+
# Package the module move_file_c:
  
 
semodule_package -o move_file_c.pp -m move_file_c.mod -f move_file.fc  
 
semodule_package -o move_file_c.pp -m move_file_c.mod -f move_file.fc  
  
<nowiki># Then to install it in the store (at /etc/selinux/modular-test/</nowiki>
+
# Then to install it in the store (at /etc/selinux/modular-test/
<nowiki># modules/active/modules/move_file_c.pp) and build the binary </nowiki>
+
# modules/active/modules/move_file_c.pp) and build the binary  
<nowiki># policy file, run the semodule command:</nowiki>
+
# policy file, run the semodule command:
  
 
semodule -v -s modular-test -i move_file_c.pp
 
semodule -v -s modular-test -i move_file_c.pp
 +
# Or:
 +
semanage module -a -S modular-test move_file_c.pp
 
</pre>
 
</pre>
 +
 +
The modules within the policy store may be compressed or not depending on the value of the <tt>bzip-blocksize</tt> parameter in the [[GlobalConfigurationFiles#/etc/selinux/semanage.conf File | semanage.conf]] file. The modules and their status can be listed using the <tt>semanage module -l</tt> command as shown below.
 +
<pre>
 +
semanage module -l
 +
ext_gateway    1.1.0
 +
int_gateway    1.1.0
 +
move_file      1.1.0
 +
netlabel      1.0.0    Disabled
 +
</pre>
 +
 +
 +
{| style="width: 100%;" border="0"
 +
|-
 +
| [[GlobalConfigurationFiles | '''Previous''']]
 +
| <center>[[NewUsers | '''Home''']]</center>
 +
| <center>[[PolicyConfigurationFiles | '''Next''']]</center>
 +
|}
 +
 +
 +
----
 +
<references/>
 +
 +
[[Category:Notebook]]

Latest revision as of 14:28, 25 September 2015

Policy Store Configuration Files

Depending on the release being used policy stores will be located at:

  • /etc/selinux/<policy_name>/modules - This is the default for systems that support versions < 2.4 of libsemanage, libsepol, and policycoreutils.
  • /var/lib/selinux/<policy_name>/modules - This is the default for systems that support versions >= 2.4 of libsemanage, libsepol, and policycoreutils. The base (/var/lib/selinux) may be overridden by the store-root parameter defined in the semanage.conf file. The migration process from previous releases is described at https://github.com/SELinuxProject/selinux/wiki/Policy-Store-Migration. Note that once the policy store migration is complete, these files will no longer exist

Note: There can be multiple policy stores on a system at /etc/selinux/<policy_name>/modules.

The Policy Store files are either installed, updated or built by the semodule(8) and semanage(8) commands as a part of the build process. The resulting files will either be copied over to the Policy Configuration Files area, or used to rebuild the kernel binary policy located at /etc/selinux/<policy_name>/policy.

All files may have comments inserted where each line must have the '#' symbol to indicate the start of a comment.

The command options and outputs shown in the text are based on the current F-20 build.

modules/ Files

The policy store has two lock files that are used by libsemanage for managing the store. Their format is not relevant to policy construction:

semanage.read.LOCK
semanage.trans.LOCK

modules/active/base.pp File

This is the packaged base policy that contains the mandatory modules and policy components such as object classes, permission declarations and initial SIDs.

modules/active/base.linked File

This is only present if the save-linked is set to TRUE as described in the /etc/selinux/semanage.conf section. It contains the modules that have been linked using the semodule_link(8) command.

modules/active/commit_num File

This is a binary file used by libsemanage for managing updates to the store. The format is not relevant to policy construction.

modules/active/file_contexts.template File

This contains a copy all the modules 'Labeling Policy File' entries (e.g. the <module_name>.fc files) that have been extracted from the base.pp and the loadable modules in the modules/active/modules directory.

The entries in the file_contexts.template file are then used to build the following files as shown in the File Context Configuration Files diagram:

  1. homedir_template file that will be used to produce the file_contexts.homedirs file which will then become the policies ./contexts/files/file_contexts.homedirs file.
  2. file_contexts file that will become the policies file_contexts file.

Note that as a part of the semanage build process, these two files will also have file_contexts.bin and file_contexts.homedirs.bin files present in the Policy Configuration Files contexts/files directory. This is because semanage requires these in the Perl compatible regular expression (PCRE) internal format. They are generated by the sefcontext_compile(8) utility.

The homedir_template and file_contexts files are built is as follows:

homedir_template - Any line in the file_contexts.template file that has the keywords HOME_ROOT, HOME_DIR and/or USER are extracted and added to the homedir_template file. This is because these keywords are used to identify entries that are associated to a users home directory area. These lines may also have the ROLE keyword declared.
The homedir_template file will then be processed by genhomedircon(8)[1] to generate individual SELinux user entries in the file_contexts.homedirs file as discussed in the modules/active/file_contexts.homedirs section.

These are examples of one line being processed as described above, taken from the F-20 targeted policy:

The master file_contexts.template entry:

HOME_DIR\/.wine(/.*)? system_u:object_r:wine_home_t:s0

The homedir_template entry is created as:

HOME_DIR\/.wine(/.*)? system_u:object_r:wine_home_t:s0

The file_contexts.homedirs entries are created by genhomedircon for the SELinux users extracted from the seusers file as follows:

# Home Context for any Linux user that is assigned
# the SELinux user unconfined_u
/home/[^/]*/\.wine(/.*)? unconfined_u:object_r:wine_home_t:s0

# Home Context for user root
/root/\.wine(/.*)? unconfined_u:object_r:wine_home_t:s0

file_contexts - All other lines are extracted and added to the file_contexts file as they are files not associated to a users home directory.

The format of the file_contexts.template file is as follows:

Each line within the file consists of the following:

pathname_regexp [file_type] opt_security_context

Where:

pathname_regexp An entry that defines the pathname that may be in the form of a regular expression.

The metacharacters '^' (match beginning of line) and '$' (match end of line) are automatically added to the expression by the routines that process this file, however they can be over-ridden by using '.*' at either the beginning or end of the expression (see the example file_contexts files below).

There are also keywords of HOME_ROOT, HOME_DIR, ROLE and USER that are used by file labeling commands (see the keyword definitions below and the modules/active/homedir_template file section for their usage).

file_type One of the following optional file_type entries (note if blank means "all file types"):

'-b' - Block Device '-c' - Character Device

'-d' - Directory '-p' - Named Pipe (FIFO)

'-l' - Symbolic Link '-s' - Socket File

'--' - Ordinary file

By convention this entry is known as 'file type', however it really represents the 'file object class'.

opt_security_context This entry can be either:
  1. The security context, including the MLS / MCS level or range if applicable that will be assigned to the file.
  2. A value of <<none>> can be used to indicate that matching files should not be re-labeled.


Keywords that can be in the file_contexts.template file are:

HOME_ROOT This keyword is replaced by the GNU / Linux users root home directory, normally '/home' is the default.
HOME_DIR This keyword is replaced by the GNU / Linux users home directory, normally '/home/' is the default.
USER This keyword will be replaced by the users GNU / Linux user id.
ROLE This keyword is replaced by the 'prefix' entry from the users_extra configuration file that corresponds to the SELinux users user id. Example users_extra configuration file entries are:
user user_u prefix user;
user staff_u prefix staff;

It is used for files and directories within the users home directory area.

The prefix can be added by the semanage login command as follows (although note that the -P option is suppressed when help is displayed as it is generally it is not used (defaults to user) - see http://blog.gmane.org/gmane.linux.redhat.fedora.selinux/month=20110701 for further information):

# Add a Linux user:
adduser rch

# Modify staff_u SELinux user and prefix:
semanage user -m -R staff_r -P staff staff_u

# Associate the SELinux user to the Linux user:
semanage login -a -s staff_u rch



Example file_contexts.template contents from targeted policy:

# modules/active/file_contexts.template - These sample entries
# have been taken from the targeted policy and show the
# HOME_DIR, HOME_ROOT and USER keywords whose lines will be
# extracted and added to the homedir_template file that is
# used to manage user home directory entries.

/.*                       system_u:object_r:default_t:s0
/[^/]+                 -- system_u:object_r:etc_runtime_t:s0
/a?quota\.(user|group) -- system_u:object_r:quota_db_t:s0
/nsr(/.*)?                system_u:object_r:var_t:s0
/sys(/.*)?                system_u:object_r:sysfs_t:s0
...
/etc/ntop.*               system_u:object_r:ntop_etc_t:s0
HOME_DIR/.+               system_u:object_r:user_home_t:s0
/dev/dri/.+            -c system_u:object_r:dri_device_t:s0
...
/tmp/gconfd-USER       -d system_u:object_r:user_tmp_t:s0
...
/tmp/gconfd-USER/.*    -- system_u:object_r:gconf_tmp_t:s0
...
HOME_ROOT/\.journal       <<none>>

modules/active/file_contexts File

This file becomes the policies contexts/files/file_contexts file and is built from entries in the modules/active/file_contexts.template file as explained above and shown in the File Context Configuration Files diagram. It is then used by the file labeling utilities to ensure that files and directories are labeled according to the policy.

The format of the file_contexts file is the same as the modules/active/file_contexts.template file.

The USER keyword is replaced by the users GNU / Linux user id when the file labeling utilities are run.

Example file_contexts contents:

# modules/active/file_contexts - These sample entries have
# been taken from the targeted policy.
# The keywords HOME_DIR, HOME_ROOT, USER and ROLE have been
# removed and put in the homedir_template file.

/.*                       system_u:object_r:default_t:s0
/[^/]+                 -- system_u:object_r:etc_runtime_t:s0
/a?quota\.(user|group) -- system_u:object_r:quota_db_t:s0
/nsr(/.*)?                system_u:object_r:var_t:s0
/sys(/.*)?                system_u:object_r:sysfs_t:s0
/xen(/.*)?                system_u:object_r:xen_image_t:s0
/mnt(/[^/]*)           -l system_u:object_r:mnt_t:s0
/mnt(/[^/]*)?          -d system_u:object_r:mnt_t:s0
/bin/.*                   system_u:object_r:bin_t:s0
/dev/.*                   system_u:object_r:device_t:s0
/usr/.*                   system_u:object_r:usr_t:s0
/var/.*                   system_u:object_r:var_t:s0
/run/.*                   system_u:object_r:var_run_t:s0
/srv/.*                   system_u:object_r:var_t:s0
/tmp/.*                   <<none>>
# contexts/files/file_contexts - Sample entries from the MLS reference policy. 
# Notes:
# 1) The fixed_disk_device_t is labeled SystemHigh (s15:c0.c255)
# as it needs to be trusted. Also some logs and configuration
# files are labeled SystemHigh as they contain sensitive
# information used by trusted applications.
#
# 2) Some directories (e.g. ''/tmp'') are labeled 
# SystemLow-SystemHigh (s0-s15:c0.c255) as they will
# support polyinstantiated directories.

/.*system_u:object_r:default_t:s0
/a?quota\.(user|group) -- system_u:object_r:quota_db_t:s0
/mnt(/[^/]*)           -l system_u:object_r:mnt_t:s0
/mnt/[^/]*/.*             <<none>>
/dev/.*mouse.*         -c system_u:object_r:mouse_device_t:s0
/dev/.*tty[^/]*        -c system_u:object_r:tty_device_t:s0
/dev/[shmx]d[^/]*      -b system_u:object_r:fixed_disk_device_t:s15:c0.c255
/var/[xgk]dm(/.*)?        system_u:object_r:xserver_log_t:s0
/dev/(raw/)?rawctl     -c system_u:object_r:fixed_disk_device_t:s15:c0.c255
/tmp                   -d system_u:object_r:tmp_t:s0-s15:c0.c255
/dev/pts               -d system_u:object_r:devpts_t:s0-s15:c0.c255
/var/log               -d system_u:object_r:var_log_t:s0-s15:c0.c255
/var/tmp               -d system_u:object_r:tmp_t:s0-s15:c0.c255
/var/run               -d system_u:object_r:var_run_t:s0-s15:c0.c255
/usr/tmp               -d system_u:object_r:tmp_t:s0-s15:c0.c255
<pre>

== modules/active/homedir_template File ==
This file is built from entries in the [[#modules/active/file_contexts.template | file_contexts.template]] file (as shown in the [http://selinuxproject.org/~rhaines/NB4-diagrams/25-file_contexts.png File Context Configuration Files] diagram) and explained in the [[#modules/modules/active/file_contexts.template | modules/active/file_contexts.template]] section. 

The file is used by genhomedircon, semanage login or semanage user to generate individual user entries in the [[#modules/active/file_contexts.homedirs | file_contexts.homedirs]] file.

The homedir_template file has the same per line format as the [[#modules/active/file_contexts.template | modules/active/file_contexts.template]] file.

'''Example file contents:'''
<pre>
# modules/active/homedir_template - These sample entries have 
# been taken from the targeted policy and show the 
# HOME_DIR, HOME_ROOT and USER keywords that are used to manage 
# users home directories:

HOME_DIR/.+            system_u:object_r:user_home_t:s0
/tmp/gconfd-USER    -d system_u:object_r:user_tmp_t:s0
/tmp/gconfd-USER/.* -- system_u:object_r:gconf_tmp_t:s0
HOME_ROOT/\.journal    <<none>>

modules/active/file_contexts.homedirs File

This file becomes the policies contexts/files/file_contexts.homedirs file when building policy as shown in the File Context Configuration Files diagram. It is then used by the file labeling utilities to ensure that users home directory areas are labeled according to the policy.

The file can be built by the genhomedircon command (that just calls /usr/sbin/semodule -Bn) or if using semanage with user or login options to manage users, where it is called automatically as it is now a libsepol library function.

The file_contexts.homedirs file has the same per line format as the modules/active/file_contexts.template file, however the HOME_DIR, ROOT_DIR, ROLE and USER keywords will be replaced as explained in the keyword definitions section above.

Example file_contexts.homedirs contents:

# modules/active/file_contexts.homedirs - These sample entries 
# have been taken from the targeted policy and show that 
# the HOME_DIR, HOME_ROOT and USER keywords have been replaced
# by entries as explained above.
#
# Home Context for the default user (unconfined_u)
/home/[^/]*/.+                unconfined_u:object_r:user_home_t:s0
/home/[^/]*/.maildir(/.*)?    unconfined_u:object_r:mail_home_rw_t:s0
...
/tmp/gconfd-.*/.*          -- unconfined_u:object_r:gconf_tmp_t:s0
/tmp/gconfd-.*             -d unconfined_u:object_r:user_tmp_t:s0

# Home Context for user rch
/home/rch/.+                  staff_u:object_r:user_home_t:s0
/home/rch/.maildir(/.*)?      staff_u:object_r:mail_home_rw_t:s0
...
/tmp/gconfd-rch/.*         -- staff_u:object_r:gconf_tmp_t:s0
/tmp/gconfd-rch            -d staff_u:object_r:user_tmp_t:s0

# Home Context for user root
/root/.+                      unconfined_u:object_r:user_home_t:s0
/root/.maildir(/.*)?          unconfined_u:object_r:mail_home_rw_t:s0
...
/tmp/gconfd-root/.*        -- unconfined_u:object_r:gconf_tmp_t:s0
/tmp/gconfd-root           -d unconfined_u:object_r:user_tmp_t:s0

modules/active/netfilter_contexts & netfilter.local File

These files are not used at present. There is code to produce a netfilter_contexts file for use by the GNU/Linux iptables service[2] in the Reference Policy that would generate a file similar to the example below, however there seems much debate on how they should be managed (see bug 201573 - Secmark iptables integration for details).

modules/active/policy.kern File

This is the binary policy file built by either the semanage(8) or semodule(8) commands (depending on the configuration action), that then becomes the binary policy to be loaded into the kernel.

modules/active/seusers.final and seusers Files

The seusers.final file maps GNU / Linux users to SELinux users and becomes the policies seusers[3] file as discussed in the seusers section. The seusers.final file is built or modified when:

  • Building a policy where an optional seusers file has been included in the base package via the semodule_package(8) command (signified by the -s flag) as follows[4]:
semodule_package -o base.pp -m base.mod -s seusers ... 

The seusers file would be extracted by the subsequent semodule command when building the policy to produce the seusers.final file.

  • The semanage login command is used to map GNU / Linux users to SELinux users as follows:
semanage login -a -s staff_u rch 

This action will update the seusers file that would then be used to produce the seusers.final file with both policy and locally defined user mapping.

It is also possible to associate a GNU / Linux group of users to an SELinux user as follows:

semanage login -a -s staff_u %staff_group

The format of the seusers.final & seusers files are as follows:

[%]user_id:seuser_id[:range]

Where:

user_id Where user_id is the GNU / Linux user identity. If this is a GNU / Linux group_id then it will be preceded with the '%' sign as shown in the example below.
seuser_id The SELinux user identity.
range The optional level or range.


Example seusers.final file contents:

# modules/active/seusers.final
system_u:system_u
root:root
__default__:user_u

Example semanage login command to add a GNU / Linux user mapping:

# This command will add the rch:user_u entry in the seusers file:

semanage login -a -s user_u rch

The resulting seusers file would be:

# modules/active/seusers

rch:user_u

The seusers.final file that will become the ./<policy_name>/seusers file is as follows:

# /modules/active/seusers.final

system_u:system_u
root:root
__default__:user_u
rch:user_u

Example semanage login command to add a GNU / Linux group mapping:

# This command will add the %user_group:user_u entry in the seusers file: 

semanage login -a -s user_u %user_group

The resulting seusers file would be:

# /modules/active/seusers

rch:user_u
%user_group:user_u

The seusers.final file that will become the ./<policy_name>/seusers file is as follows:

# modules/active/seusers.final

system_u:system_u
root:root
__default__:user_u
rch:user_u
%user_group:user_u

modules/active/users_extra, users_extra.local and users.local Files

These three files work together to describe SELinux user information as follows:

  • The users_extra and users_extra.local files are used to map a prefix to users home directories as discussed in the modules/active/file_contexts.template file section, where it is used to replace the ROLE keyword. The prefix is linked to an SELinux user id and should reflect the users role. The semanage user command will allow a prefix to be added via the -P flag (although no longer used by policies as discussed in the modules/active/file_contexts.template file section).

The users_extra file contains all the policy prefix entries, and the users_extra.local file contains those generated by the semanage user command.

The users_extra file can optionally be included in the base package via the semodule_package(8) command (signified by the -u flag) as follows[5]:

semodule_package -o base.pp -m base.mod -u users_extra ... 

The users_extra file would then be extracted by a subsequent semodule command when building the policy.

  • The users.local file is used to add new SELinux users to the policy without editing the policy source itself (with each line in the file following a policy language user statement section). This is useful when only the Reference Policy headers are installed and additional users need to added. The semanage user command will allow a new SELinux user to be added that would generate the user.local file and if a -P flag has been specified, then a users_extra.local file is also updated (note: if this is a new SELinux user and a prefix is not specified a default prefix of user is generated).

The sections that follow will:

  • Define the format and show example users_extra and users_extra.local files.
  • Execute an semanage user command that will add a new SELinux user and associated prefix, and show the resulting users_extra, users_extra.local and users.local files.

Note that each line of the users.local file contains a user statement that is defined in the policy language user statement section, and will be built into the policy via the semanage command.

The format of the users_extra & users_extra.local files are as follows:

user seuser_id prefix prefix_id;

Where:

user The user keyword.
seuser_id The SELinux user identity.
prefix The prefix keyword.
prefix_id An identifier that will be used to replace the ROLE keyword within the modules/active/homedir_template file when building the ./modules/active/file_contexts.homedirs file for the relabeling utilities to set the security context on users home directories.


Example users_extra file contents:

# modules/active/users_extra entries, note that the 
# users_extra.local file contents are similar and generated by 
# the semanage user command.

user user_u prefix user;
user staff_u prefix user;
user sysadm_u prefix user;
user root prefix user;

Example semanage user command to add a new SELinux user:

# This command will add the user test_u prefix staff entry in 
# the users_extra.local file: 

semanage user -a -R staff_r -P staff test_u

The resulting users_extra.local file is as follows:

# modules/active/users_extra.local

user test_u prefix staff;

The resulting users_extra file is as follows:

# modules/active/users_extra

user user_u prefix user;
user staff_u prefix user;
user sysadm_u prefix user;
user root prefix user;
user test_u prefix staff;

The resulting users.local file is as follows:

# modules/active/users.local file entry:

user test_u roles { staff_r } level s0 range s0;

modules/active/booleans.local File

This file is created and updated by the semanage boolean command and holds boolean value as requested.

Example semanage boolean command to modify a boolean value:

# This command will add an entry in the booleans.local 
# file and set the boolean value to 'off': 

semanage boolean -m -0 ext_gateway_audit

The resulting booleans.local file would be:

# modules/active/booleans.local

ext_gateway_audit=0

modules/active/file_contexts.local File

This file is created and updated by the semanage fcontext command. It is used to hold file context information on files and directories that were not delivered by the core policy (i.e. they are not defined in any of the *.fc files delivered in the base and loadable modules).

The semanage command will add the information to the policy stores file_contexts.local file and then copy this file to the ./contexts/files/file_contexts.local file, where it will be used when the file context utilities are run.

The format of the file_contexts.local file is the same as the modules/active/file_contexts.template file.

Example semanage fcontext command to add a new entry:

# This command will add an entry in the file_contexts.local file: 

semanage fcontext -a -t user_t /usr/move_file

# Note that the type (-t flag) must exist in the policy 
# otherwise the command will fail.

The resulting file_contexts.local file would be:

# modules/active/file_contexts.local

/usr/move_filesystem_u:object_r:user_t

modules/active/interfaces.local File

This file is created and updated by the semanage interface command to hold network interface information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new interface information is then built into the policy by the semanage(8) command.

Each line of the file contains a netifcon statement that is defined along with examples in the netifcon statement section.

modules/active/nodes.local File

This file is created and updated by the semanage node command to hold network address information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new node information is then built into the policy by the semanage(8) command.

Each line of the file contains a nodecon statement that is defined along with examples in the policy language nodecon statement section.

modules/active/ports.local File

This file is created and updated by the semanage port command to hold network port information that was not delivered by the core policy (i.e. they are not defined in base.conf file). The new port information is then built into the policy by the semanage(8) command.

Each line of the file contains a portcon statement that is defined along with examples in the policy language portcon statement section.

modules/active/preserve_tunables File

This file will only exist if the policy build specified that tunables should be preserved, if so they would be converted to booleans by the policy build process.

modules/active/disable_dontaudit File

This file will only exist if the policy build specified that dontaudit rules should be disabled.

modules/active/modules Directory Contents

This directory contains loadable modules (<module_name>.pp or when disabled <module_name>.pp.disabled) that have been built by the semodule_package command and placed in the store by the semodule or semanage module -a commands as shown in the following example:

# Package the module move_file_c:

semodule_package -o move_file_c.pp -m move_file_c.mod -f move_file.fc 

# Then to install it in the store (at /etc/selinux/modular-test/
# modules/active/modules/move_file_c.pp) and build the binary 
# policy file, run the semodule command:

semodule -v -s modular-test -i move_file_c.pp
# Or:
semanage module -a -S modular-test move_file_c.pp

The modules within the policy store may be compressed or not depending on the value of the bzip-blocksize parameter in the semanage.conf file. The modules and their status can be listed using the semanage module -l command as shown below.

semanage module -l
ext_gateway    1.1.0
int_gateway    1.1.0
move_file      1.1.0
netlabel       1.0.0    Disabled


Previous
Home
Next



  1. The genhomedircon command has now been built into the libsemanage library as a function to build the file_contexts.homedirs file via semanage(8).
  2. This uses SECMARK labeling that has been utilised by SELinux as described in the SELinux Networking Support section.
  3. Many seusers make confusion: The modules/active/seusers file is used to hold initial seusers entries, the modules/active/seusers.final file holds the complete entries that then becomes the policy seusers file.
  4. The Reference Policy Makefile 'Rules.modular' script uses this method to install the initial seusers file.
  5. The Reference Policy Makefile 'Rules.modular' script uses this method to install the initial users_extra file.