<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technical Diary &#187; selinux</title>
	<atom:link href="http://andriigrytsenko.net/tag/selinux/feed/" rel="self" type="application/rss+xml" />
	<link>http://andriigrytsenko.net</link>
	<description>With Andrii Grytsenko</description>
	<lastBuildDate>Tue, 17 Aug 2010 08:25:33 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SElinux tips and tricks</title>
		<link>http://andriigrytsenko.net/2009/07/selinux-tips-and-tricks/</link>
		<comments>http://andriigrytsenko.net/2009/07/selinux-tips-and-tricks/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 13:55:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[selinux]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=358</guid>
		<description><![CDATA[Short notes about base SELinux commands.

The SELinux technology allow you to improve security level of your system. You can restrict access to the ports, files, directories, process and so on.  There are a lot of tools involved in this process and I will try to make little overview about most of they.
setenforce uses to [...]]]></description>
			<content:encoded><![CDATA[<p>Short notes about base SELinux commands.<br />
<span id="more-358"></span></p>
<p>The SELinux technology allow you to improve security level of your system. You can restrict access to the ports, files, directories, process and so on.  There are a lot of tools involved in this process and I will try to make little overview about most of they.</p>
<p><strong>setenforce</strong> uses to set SELinux mode. There are two basic mode: Enforcing and Permissive. First mode makes SELinux turn on. Another one is turn off SELinux.<br />
!!! Caution this tools doesn&#8217;t make changes at /etc/selinux/config file. Its means that SELinux will back to previous mode after reboot. To make permanent change of mode edit /etc/selinux/config directly.</p>
<p>The management mechanism of SELinuxfs (/selinux mount point by default) a slightly alike to the procfs. You can easily change any parameter just put bool value into the file. It&#8217;s an alternative way to change different options of SELinux. As example use <b>echo</b> to change SELinux mode:</p>
<pre>[root@node2 ~]# getenforce
Enforcing
[root@node2 ~]# echo 0 > /selinux/enforce
[root@node2 ~]# getenforce
Permissive</pre>
<p><strong>getenforce</strong> &#8211; check current SELinux mode.</p>
<p><strong>sestatus</strong> &#8211; output current SELinux status.  </p>
<p><strong>setroubleshootd</strong> &#8211; is located in setroubleshoot* rpm&#8217;s which is not installed by default. Use yum to install it: </p>
<pre>yum install setroubleshoot</pre>
<p>This daemon running with system from /etc/init.d/setroubleshoot and put all SELinux messages into the log file. </p>
<p><strong>secon</strong> &#8211; allow to see SELinux attributes for object(file, directory, process and so on). </p>
<p><strong>chcon</strong>  &#8211; changes SELinux attributes for object</p>
<p><strong>sealert </strong> &#8211; It&#8217;s GUI tool which works in co-operation with setroubleshootd. It&#8217;s display all SELinux message and give some explanation concerning its.</p>
<p><strong>restorecon</strong> &#8211; restore defaults attribute for given object.</p>
<p><strong>setsebool</strong> &#8211; allow to set bool variable. Use with option &#8220;-P&#8221; to make change permanently. Ex. : </p>
<pre>setsebool -P allow_ftpd_anon_write  1 </pre>
<p>This command allow anonymous user write into the ftp directory which open for write. </p>
<p><strong>getsebool</strong> &#8211; with option &#8220;-a&#8221; get all possible variables with current value for each.</p>
<p><strong>semanage</strong> &#8211; most powerful tools which can configure any element without policy sources recompilation. </p>
<p>Also SELinux writes messages into the
<pre>/var/log/messages</pre>
<p>.<br />
SELinux also update coreutils and add to this utils option &#8220;-Z&#8221;. For example we use ordinary coreutils tool <b>ls</b> to check SELinux attribtes for files:</p>
<pre>[root@node2 ~]# ls -Z
-rw-------  root root  system_u:object_r:user_home_t    anaconda-ks.cfg
-rw-r--r--  root root  root:object_r:user_home_t        install.log.syslog
.....
</pre>
<p>Every user in SELinux has at least one role. To list all SELinux roles, run : </p>
<pre>semanage user -l</pre>
<p>To make copy of existing file with new SELinux attributes, use <b>ls</b>:</p>
<pre>cp -Z user:role:type old_file new_file</pre>
<p>To find difference between current attributes and defaults one for an object: </p>
<pre>matchpathcon -V [object] </pre>
<p>To show current user attributes, type . </p>
<pre>id -Z</pre>
<p>To create user with attributes: </p>
<pre>useradd -Z ..</pre>
<p>in case user is already exist:</p>
<pre>semanage login -a -s user_roles user</pre>
<p>To change directory attributes: </p>
<pre>
semanage fcontext -a -t httpd_sys_content_t /www
restorecon -R -v /www/</pre>
<p>To list all port restriction, run </p>
<pre>semanage port -l</pre>
<p>if you want your service listen on non-ordinary port. First, check if the port is not already declared by SELinux. The command described above in cooperation with
<pre>grep</pre>
<p> can help you:</p>
<pre>semanage port -l | grep <your port></pre>
<p>If nothing is appear you can skip next step. Otherwise, delete port from existing group:</p>
<pre>semanage port -d -p tcp 9050</pre>
<p>and put it into your service&#8217;s group:</p>
<pre>semanage port -a -t httpd_port_t -p tcp 9050 </pre>
<p>, where <em>httpd_port_t</em> &#8211; your service&#8217;s group and <em>9050</em> you port.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2009/07/selinux-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
