From Fedora Project Wiki
(Created page with '{{admon/important | Comments and Explanations | The page source contains comments providing guidance to fill out each section. They are invisible when viewing this page. To rea...')
 
(moved out of readyforfesco - not sure why this was missed?)
 
(27 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{admon/important | Comments and Explanations | The page source contains comments providing guidance to fill out each section.  They are invisible when viewing this page.  To read it, choose the "edit" link.<br/> '''Copy the source to a ''new page'' before making changes!  DO NOT EDIT THIS TEMPLATE FOR YOUR FEATURE.'''}}
{{admon/important | Set a Page Watch| Make sure you click ''watch'' on your new page so that you are notified of changes to it by others, including the Feature Wrangler}}
{{admon/note | All sections of this template are required for review by FESCo.  If any sections are empty it will not be reviewed }}
<!-- All fields on this form are required to be accepted by FESCo.
We also request that you maintain the same order of sections so that all of the feature pages are uniform.  -->
<!-- The actual name of your feature page should look something like: Features/YourFeatureName.  This keeps all features in the same namespace -->
= Feature Name <!-- The name of your feature --> =
= Feature Name <!-- The name of your feature --> =
SELinux File Name Transition
SELinux File Name Transition
== Summary ==
== Summary ==
<!-- A sentence or two summarizing what this feature is and what it will do.  This information is used for the overall feature summary page for each release. -->
<!-- A sentence or two summarizing what this feature is and what it will do.  This information is used for the overall feature summary page for each release. -->
This change allows us to write a rule in policy that states if a process labeled A_t creates a file in a directory labeled B_t and the file is named "filename", it will get the label C_t.
This change allows us to write a rule in policy that states if a process labelled A_t creates a specified object class in a directory labelled B_t and the specified object class is named "objectname", it will get the label C_t.


An example of this would be the administrator going into the /root directory and creating the .ssh directory.  In previous versions of Fedora, the directory would get created admin_home_t, even though the policy requires it to be labelled ssh_home_t.
An example of this would be the administrator going into the /root directory and creating the .ssh directory.  In previous versions of Fedora, the directory would get created admin_home_t, even though the policy requires it to be labelled ssh_home_t.


Now we can write a rule in policy that states, if the unconfined_t process creates the ".ssh" directory in a directory labelled admin_home_t, then it will get created with the label ssh_home_t.
Now we can write a rule in policy that states, if the unconfined_t process creates the ".ssh" directory in a directory labelled admin_home_t, then it will get created with the label ssh_home_t.
 
== Owner ==
== Owner ==
<!--This should link to your home wiki page so we know who you are-->
<!--This should link to your home wiki page so we know who you are-->
Line 30: Line 18:
== Current status ==
== Current status ==
* Targeted release: [Fedora 16]  
* Targeted release: [Fedora 16]  
* Last updated: (DATE)
* Last updated: July 11 2011
* Percentage of completion: 90%
* Percentage of completion: 100%


<!-- CHANGE THE "FedoraVersion" TEMPLATES ABOVE TO PLAIN NUMBERS WHEN YOU COMPLETE YOUR PAGE. -->
<!-- CHANGE THE "FedoraVersion" TEMPLATES ABOVE TO PLAIN NUMBERS WHEN YOU COMPLETE YOUR PAGE. -->
Line 39: Line 27:
SELinux has always had a problem of how to get the default labels on an object when the object is created.  Up until now, their have been three ways of getting the initial label on an object.
SELinux has always had a problem of how to get the default labels on an object when the object is created.  Up until now, their have been three ways of getting the initial label on an object.


The default way an object gets labelled is to inherit the label of the parent directory.  If you create a file named foo in a directory labelled etc_t, then foo will be labeled etc_t.
The default way an object gets labelled is to inherit the label of the parent directory.  If you create a file named foo in a directory labelled etc_t, then foo will be labelled etc_t.


This works well in most cases, but in some cases you want to have multiple files within a directory with different labels.
This works well in most cases, but in some cases you want to have multiple files within a directory with different labels.
Line 45: Line 33:
Policy writers have the ability to overwrite this by writing a rule in policy that states, if a process with type a_t creates a object of class "file" in a directory labelled b_t, the object will get created c_t.  One problem with this is that you might have a single program that is going to create multiple objects in the same directory where each object requires a separate directory.
Policy writers have the ability to overwrite this by writing a rule in policy that states, if a process with type a_t creates a object of class "file" in a directory labelled b_t, the object will get created c_t.  One problem with this is that you might have a single program that is going to create multiple objects in the same directory where each object requires a separate directory.


Some applications have SELinux awareness in them that allow them to ask the system what the label of a certain path should be and then they request from the kernel that the object be created with this label.  Examples of applications with SELinux awareness are obviously rpm, restorecon, and udev.  Another less known example of an application with SELinux is the password command.  passwd recreates the /etc/passwd and /etc/shadow file.  /etc/passwd should be labelled etc_t, and shadow should be labeled shadow_t.  Because of this and some other concerns, the passwd command has SELinux awareness built into it, and it asks the kernel to create the /etc/passwd and /etc/shadow file with the correct default label.
Some applications have SELinux awareness in them that allow them to ask the system what the label of a certain path should be and then they request from the kernel that the object be created with this label.  Examples of applications with SELinux awareness are obviously rpm, restorecon, and udev.  Another less known example of an application with SELinux is the password command.  passwd recreates the /etc/passwd and /etc/shadow file.  /etc/passwd should be labelled etc_t, and shadow should be labelled shadow_t.  Because of this and some other concerns, the passwd command has SELinux awareness built into it, and it asks the kernel to create the /etc/passwd and /etc/shadow file with the correct default label.


But we can not instrument every application that creates a file/directory on the system with SELinux awareness.  So a user creating the public_html directory in his home directory using mkdir will create the directory with the label user_home_t instead of the correct httpd_user_content_t.  An administrator creating the /etc/resolv.conf with sed will create the file labeled etc_t rather then net_conf_t.  Or even the kernel creating /dev/rfcomm0 with the label device_t rather then tty_device_t.  In these cases we have either required the user/administrator to run the restorecon command on the newly created object "restorecon ~/public_html", or we have added racy tools like restorecond or udev which watch for the creation of objects using inotify, and then relabel them with the correct label.  All three of these end up creating an AVC for a confined domain, if not fixed before a confined domain tries to use the object.
But we can not instrument every application that creates a file/directory on the system with SELinux awareness.  So a user creating the public_html directory in his home directory using mkdir will create the directory with the label user_home_t instead of the correct httpd_user_content_t.  An administrator creating the /etc/resolv.conf with sed will create the file labelled etc_t rather then net_conf_t.  Or even the kernel creating /dev/rfcomm0 with the label device_t rather then tty_device_t.  In these cases we have either required the user/administrator to run the restorecon command on the newly created object "restorecon ~/public_html", or we have added racy tools like restorecond or udev which watch for the creation of objects using inotify, and then relabel them with the correct label.  All three of these end up creating an AVC for a confined domain, if not fixed before a confined domain tries to use the object.


With File Name Transitions Features, policy writers can write rules that take into account the file name, not the file path.  This is the basename of the file path.  Since the kernel knows at the time of object creation the label of the containing directory, the label of the process creating the object and the objects Name. we can now write a policy rule that states,
With File Name Transitions Features, policy writers can write rules that take into account the file name, not the file path.  This is the basename of the file path.  Since the kernel knows at the time of object creation the label of the containing directory, the label of the process creating the object and the objects Name. we can now write a policy rule that states,
if an unconfined_t process creates a file named resolv.conf in a directory labelled etc_t, the file should get labeled resolv.conf.
if an unconfined_t process creates a file named resolv.conf in a directory labelled etc_t, the file should get labelled resolv.conf.
 
* Examples of policy rule:
**  filetrans_pattern(kernel_t, device_t, xserver_misc_device_t, chr_file, "nvidia0")
**  filetrans_pattern(puppet_t, etc_t, krb5_conf_t, file, "krb5.conf")


We have also added rules that state:
We also added various rules, including:


* kernel_t creating a chr_file named rfconmm0 in a directory labelled device_t should create it labelled tty_device_t.
* kernel_t creating a chr_file named rfconmm0 in a directory labelled device_t should create it labelled tty_device_t.
** For Example /dev/rfcomm
** For Example /dev/rfcomm
* sysadm_t creating a directory named .ssh in a directory labeled admin_home_t should create it labelled ssh_home_t.  
* sysadm_t creating a directory named .ssh in a directory labelled admin_home_t should create it labelled ssh_home_t.  
** Example: /root/.ssh
** Example: /root/.ssh
* staff_t creating a directory named .public_html in a directory labeled user_home_dir_t should create it labelled http_user_content_t.   
* staff_t creating a directory named public_html in a directory labelled user_home_dir_t should create it labelled http_user_content_t.   
** For Example /home/dwalsh/.public_html
** For Example /home/dwalsh/public_html


Note: this feature is just about initial file creation. Objects with the wrong label on them will not be magically be fixed with this feature.  This feature does not use the path to determine the label, since the path can be variable in the kernel.  (Hard/Soft Links, Bind Mounts, Namespacing can all effect the path).  
''Note: File Name Transition is just about initial file creation. Objects with the wrong label on them will not be magically be fixed with this feature.  This feature does not use the path to determine the label, since the path can be variable in the kernel.  (Hard/Soft Links, Bind Mounts, Namespacing can all effect the path).''
''Note 2: The kernel team wants me to point out that this is an exact strcmp match.  No regex, no glob, and no hope of that ever changing.''


== Benefit to Fedora ==
== Benefit to Fedora ==
<!-- What is the benefit to the platform?  If this is a major capability update, what has changed?  If this is a new feature, what capabilities does it bring? Why will Fedora become a better distribution or project because of this feature?-->
<!-- What is the benefit to the platform?  If this is a major capability update, what has changed?  If this is a new feature, what capabilities does it bring? Why will Fedora become a better distribution or project because of this feature?-->
The major benefit to Fedora is the decrease of SELinux labelling errors, these policy changes will fix a large number of issues SELinux users have with SELinux.  Over the years the largest amount of SELinux errors come down to incorrectly labeled files/directories, if we can work to make sure most of them are labelled correctly without the user or admin needing to understand how SELinux works, then the less likely for SELinux to create problems.  This feature also has the potential to make the system more secure, because a badly labelled file might give other confined objects the chance to read/write the content.  For example most confined applications should not be reading the contents of the .ssh directory, but if it gets the label of the users home directory by default (As it does in current Fedoras), a confined application may be allowed to read the private key file.
The major benefit to Fedora is the decrease of SELinux labelling errors, these policy changes will fix a large number of issues SELinux users have with SELinux.  Over the years the largest amount of SELinux errors come down to incorrectly labelled files/directories, if we can work to make sure most of them are labelled correctly without the user or admin needing to understand how SELinux works, then the less likely for SELinux to create problems.  This feature also has the potential to make the system more secure, because a badly labelled file might give other confined objects the chance to read/write the content.  For example most confined applications should not be reading the contents of the .ssh directory, but if it gets the label of the users home directory by default (As it does in current Fedoras), a confined application may be allowed to read the private key file.


== Scope ==
== Scope ==
Line 92: Line 86:
yum remove policycoreutils-restorecond
yum remove policycoreutils-restorecond


useradd test
# Public_html test.
mkdir ~test/.public_html
  # useradd test
Verify ~/test/.public_html is labeled correctly
  # mkdir /home/test/public_html
restorecon -v ~/test/.public_html  # No output expected
  Verify /home/test/public_html is labelled correctly
Now login graphically to test account.
  # restorecon -v /home/test/public_html  # No output expected
restorecon -R -v ~/test  #Hopefully no output...


mv /root/.ssh /root/.ssh.old
# Verify all files created when you graphically login are created with the correct label.
mkdir /root/.ssh
  Now login graphically to test account.
restorecon -v /root/.public_html # No output expected
  # restorecon -R -v ~/test #Hopefully no output...
rmdir /root/.ssh
mv /root/.ssh.old /root/.ssh


mv /etc/resolv.conf /tmp
# Creating /root/.ssh test
cp /tmp/resolv.conf /etc
  # mv /root/.ssh /root/.ssh.old
restorecon -v /tmp/resolv.conf # No output expected
  # mkdir /root/.ssh
  # restorecon -v /root/.ssh  # No output expected
  # rmdir /root/.ssh
  # mv /root/.ssh.old /root/.ssh


Plugin in bluetooth device, no avc about bluetooth_t trying to interact with a device_t chr_file.
# Creating /etc/resolv.conf
  # mv /etc/resolv.conf /tmp
  # cp /tmp/resolv.conf /etc
  # restorecon -v /tmp/resolv.conf # No output expected


Setup nfs to share a users homedir, mount the homedir on a remote client and create the .public_html directory.
# Bluetooth having the kernel create the device with the correct label
Make sure on the server the directory gets created with the correct label.
  Plugin in bluetooth device, no avc about bluetooth_t trying to interact with a device_t chr_file.
 
# Verify the kernel will create files in the users home directory on the server with the correct label when shared over NFS.
  Setup nfs to share a users homedir, mount the homedir on a remote client and create the .public_html directory.
  Make sure on the server the directory gets created with the correct label.


If you find other objects that could use this feature, open a bugzilla and we can discuss.
If you find other objects that could use this feature, open a bugzilla and we can discuss.
Line 119: Line 120:
<!-- If this feature is noticeable by its target audience, how will their experiences change as a result?  Describe what they will see or notice. -->
<!-- If this feature is noticeable by its target audience, how will their experiences change as a result?  Describe what they will see or notice. -->
It really should not be noticed by the user, unless they are looking for it, although hopefully they will notice that SELinux is working better.
It really should not be noticed by the user, unless they are looking for it, although hopefully they will notice that SELinux is working better.
== Dependencies ==
<!-- What other packages (RPMs) depend on this package?  Are there changes outside the developers' control on which completion of this feature depends?  In other words, completion of another feature owned by someone else and might cause you to not be able to finish on time or that you would need to coordinate?  Other upstream projects like the kernel (if this is not a kernel feature)? -->
== Contingency Plan ==
<!-- If you cannot complete your feature by the final development freeze, what is the backup plan?  This might be as simple as "None necessary, revert to previous release behaviour."  Or it might not.  If you feature is not completed in time we want to assure others that other parts of Fedora will not be in jeopardy.  -->


== Documentation ==
== Documentation ==
<!-- Is there upstream documentation on this feature, or notes you have written yourself?  Link to that material here so other interested developers can get involved. -->
<!-- Is there upstream documentation on this feature, or notes you have written yourself?  Link to that material here so other interested developers can get involved. -->
*
*
With File Name Transitions Features, policy writers can write rules that take into account the file name, not the file path. The basename of the file path. The kernel knows at the time of object creation the label of the containing directory, the label of the process creating the object and the objects Name, policy writers can take advantage of this and write a policy rule that states, if an unconfined_t process creates a file named resolv.conf in a directory labelled etc_t, the file should get labelled resolv.conf.


== Release Notes ==
== Release Notes ==
<!-- The Fedora Release Notes inform end-users about what is new in the release.  Examples of past release notes are here: http://docs.fedoraproject.org/release-notes/ -->
<!-- The Fedora Release Notes inform end-users about what is new in the release.  Examples of past release notes are here: http://docs.fedoraproject.org/release-notes/ -->
<!-- The release notes also help users know how to deal with platform changes such as ABIs/APIs, configuration or data file formats, or upgrade concerns.  If there are any such changes involved in this feature, indicate them here.  You can also link to upstream documentation if it satisfies this need.  This information forms the basis of the release notes edited by the documentation team and shipped with the release. -->
<!-- The release notes also help users know how to deal with platform changes such as ABIs/APIs, configuration or data file formats, or upgrade concerns.  If there are any such changes involved in this feature, indicate them here.  You can also link to upstream documentation if it satisfies this need.  This information forms the basis of the release notes edited by the documentation team and shipped with the release. -->
*
*The only thing a user should notice is instead of file objects almost always being created with the default label of the containing directory, some file objects will get a different label as specified in policy.  The user will probably not notice this.  In some cases he will no longer need to run restorecon to make sure the label is correct.  The kernel will just label the file object correctly at creation.


== Comments and Discussion ==
== Comments and Discussion ==
* See [[Talk:Features/YourFeatureName]]  <!-- This adds a link to the "discussion" tab associated with your page.  This provides the ability to have ongoing comments or conversation without bogging down the main feature page -->
* See [[Talk:Features/SELinuxFileNameTransition]]  <!-- This adds a link to the "discussion" tab associated with your page.  This provides the ability to have ongoing comments or conversation without bogging down the main feature page -->





Latest revision as of 11:26, 12 July 2012

Feature Name

SELinux File Name Transition

Summary

This change allows us to write a rule in policy that states if a process labelled A_t creates a specified object class in a directory labelled B_t and the specified object class is named "objectname", it will get the label C_t.

An example of this would be the administrator going into the /root directory and creating the .ssh directory. In previous versions of Fedora, the directory would get created admin_home_t, even though the policy requires it to be labelled ssh_home_t.

Now we can write a rule in policy that states, if the unconfined_t process creates the ".ssh" directory in a directory labelled admin_home_t, then it will get created with the label ssh_home_t.

Owner

  • Email: dwalsh@redhat.com

Current status

  • Targeted release: [Fedora 16]
  • Last updated: July 11 2011
  • Percentage of completion: 100%


Detailed Description

SELinux has always had a problem of how to get the default labels on an object when the object is created. Up until now, their have been three ways of getting the initial label on an object.

The default way an object gets labelled is to inherit the label of the parent directory. If you create a file named foo in a directory labelled etc_t, then foo will be labelled etc_t.

This works well in most cases, but in some cases you want to have multiple files within a directory with different labels.

Policy writers have the ability to overwrite this by writing a rule in policy that states, if a process with type a_t creates a object of class "file" in a directory labelled b_t, the object will get created c_t. One problem with this is that you might have a single program that is going to create multiple objects in the same directory where each object requires a separate directory.

Some applications have SELinux awareness in them that allow them to ask the system what the label of a certain path should be and then they request from the kernel that the object be created with this label. Examples of applications with SELinux awareness are obviously rpm, restorecon, and udev. Another less known example of an application with SELinux is the password command. passwd recreates the /etc/passwd and /etc/shadow file. /etc/passwd should be labelled etc_t, and shadow should be labelled shadow_t. Because of this and some other concerns, the passwd command has SELinux awareness built into it, and it asks the kernel to create the /etc/passwd and /etc/shadow file with the correct default label.

But we can not instrument every application that creates a file/directory on the system with SELinux awareness. So a user creating the public_html directory in his home directory using mkdir will create the directory with the label user_home_t instead of the correct httpd_user_content_t. An administrator creating the /etc/resolv.conf with sed will create the file labelled etc_t rather then net_conf_t. Or even the kernel creating /dev/rfcomm0 with the label device_t rather then tty_device_t. In these cases we have either required the user/administrator to run the restorecon command on the newly created object "restorecon ~/public_html", or we have added racy tools like restorecond or udev which watch for the creation of objects using inotify, and then relabel them with the correct label. All three of these end up creating an AVC for a confined domain, if not fixed before a confined domain tries to use the object.

With File Name Transitions Features, policy writers can write rules that take into account the file name, not the file path. This is the basename of the file path. Since the kernel knows at the time of object creation the label of the containing directory, the label of the process creating the object and the objects Name. we can now write a policy rule that states, if an unconfined_t process creates a file named resolv.conf in a directory labelled etc_t, the file should get labelled resolv.conf.

  • Examples of policy rule:
    • filetrans_pattern(kernel_t, device_t, xserver_misc_device_t, chr_file, "nvidia0")
    • filetrans_pattern(puppet_t, etc_t, krb5_conf_t, file, "krb5.conf")

We also added various rules, including:

  • kernel_t creating a chr_file named rfconmm0 in a directory labelled device_t should create it labelled tty_device_t.
    • For Example /dev/rfcomm
  • sysadm_t creating a directory named .ssh in a directory labelled admin_home_t should create it labelled ssh_home_t.
    • Example: /root/.ssh
  • staff_t creating a directory named public_html in a directory labelled user_home_dir_t should create it labelled http_user_content_t.
    • For Example /home/dwalsh/public_html

Note: File Name Transition is just about initial file creation. Objects with the wrong label on them will not be magically be fixed with this feature. This feature does not use the path to determine the label, since the path can be variable in the kernel. (Hard/Soft Links, Bind Mounts, Namespacing can all effect the path).

Note 2: The kernel team wants me to point out that this is an exact strcmp match. No regex, no glob, and no hope of that ever changing.

Benefit to Fedora

The major benefit to Fedora is the decrease of SELinux labelling errors, these policy changes will fix a large number of issues SELinux users have with SELinux. Over the years the largest amount of SELinux errors come down to incorrectly labelled files/directories, if we can work to make sure most of them are labelled correctly without the user or admin needing to understand how SELinux works, then the less likely for SELinux to create problems. This feature also has the potential to make the system more secure, because a badly labelled file might give other confined objects the chance to read/write the content. For example most confined applications should not be reading the contents of the .ssh directory, but if it gets the label of the users home directory by default (As it does in current Fedoras), a confined application may be allowed to read the private key file.

Scope

This change only effects Policy writers and the kernel. No other applications should be effected by this change.

How To Test

This initial policy work has been done and effects the following directories, /root, $HOME, /dev, /etc.

Things I would like to see checked. First make sure restorecond is not running. killall -9 restorecond.

yum remove policycoreutils-restorecond

  1. Public_html test.
 # useradd test
 # mkdir /home/test/public_html
 Verify /home/test/public_html is labelled correctly
 # restorecon -v /home/test/public_html  # No output expected
  1. Verify all files created when you graphically login are created with the correct label.
 Now login graphically to test account.
 # restorecon -R -v ~/test  #Hopefully no output...
  1. Creating /root/.ssh test
 # mv /root/.ssh /root/.ssh.old
 # mkdir /root/.ssh
 # restorecon -v /root/.ssh  # No output expected
 # rmdir /root/.ssh
 # mv /root/.ssh.old /root/.ssh
  1. Creating /etc/resolv.conf
 # mv /etc/resolv.conf /tmp
 # cp /tmp/resolv.conf /etc
 # restorecon -v /tmp/resolv.conf # No output expected
  1. Bluetooth having the kernel create the device with the correct label
 Plugin in bluetooth device, no avc about bluetooth_t trying to interact with a device_t chr_file.
  1. Verify the kernel will create files in the users home directory on the server with the correct label when shared over NFS.
 Setup nfs to share a users homedir, mount the homedir on a remote client and create the .public_html directory.
 Make sure on the server the directory gets created with the correct label.

If you find other objects that could use this feature, open a bugzilla and we can discuss.

User Experience

It really should not be noticed by the user, unless they are looking for it, although hopefully they will notice that SELinux is working better.

Documentation

With File Name Transitions Features, policy writers can write rules that take into account the file name, not the file path. The basename of the file path. The kernel knows at the time of object creation the label of the containing directory, the label of the process creating the object and the objects Name, policy writers can take advantage of this and write a policy rule that states, if an unconfined_t process creates a file named resolv.conf in a directory labelled etc_t, the file should get labelled resolv.conf.

Release Notes

  • The only thing a user should notice is instead of file objects almost always being created with the default label of the containing directory, some file objects will get a different label as specified in policy. The user will probably not notice this. In some cases he will no longer need to run restorecon to make sure the label is correct. The kernel will just label the file object correctly at creation.

Comments and Discussion