<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>mgrepl</title>
	<atom:link href="http://mgrepl.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mgrepl.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Mon, 03 Dec 2012 07:57:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mgrepl.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>mgrepl</title>
		<link>http://mgrepl.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mgrepl.wordpress.com/osd.xml" title="mgrepl" />
	<atom:link rel='hub' href='http://mgrepl.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How would tools like “paster” work with SELinux? &#8230; &#8220;Thin story&#8221;</title>
		<link>http://mgrepl.wordpress.com/2012/11/30/how-would-tools-like-paster-work-with-selinux-thin-story/</link>
		<comments>http://mgrepl.wordpress.com/2012/11/30/how-would-tools-like-paster-work-with-selinux-thin-story/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 22:48:02 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[Policy development]]></category>
		<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=249</guid>
		<description><![CDATA[I have &#8220;recently&#8221; written How would tools like “paster” work with SELinux? blog about projects which use/used a tool like the paster to create own application servers. Now let&#8217;s talk about other specific example &#8211; Thin (Ruby web server). Previously, we had all services using Thin running in the thin_t SELinux domain type. But we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=249&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have &#8220;recently&#8221; written</p>
<p><a title="http://mgrepl.wordpress.com/2012/06/20/how-would-tools-like-paster-work-with-selinux/" href="http://mgrepl.wordpress.com/2012/06/20/how-would-tools-like-paster-work-with-selinux/">How would tools like “paster” work with SELinux?</a></p>
<p>blog about projects which use/used a tool like the paster to create own application servers. Now let&#8217;s talk about other specific example &#8211; <strong>Thin</strong> (Ruby web server).</p>
<p>Previously, we had all services using Thin running in the <em>thin_t</em> SELinux domain type. But we did not realize there are many projects which use Thin in different ways and we could not treat all of them just by one SELinux domain type. So we re-wrote the thin policy to provide</p>
<p><strong><em>thin_domain_template()</em></strong></p>
<p>But how to use this interface? I will show you on AEOLUS-CONFIGSERVER example.</p>
<p><strong>AEOLUS-CONFIGSERVER scenario</strong></p>
<p><span style="color:blue;"># yum install aeolus-configserver</span><br />
<span style="color:blue;"># rpm -qi aeolus-configserver</span><br />
<span style="color:blue;">Description :</span><br />
<span style="color:blue;">The Aeolus Config Server, a service for storing and retrieving VM configurations</span></p>
<p>At First (read the previous <a href="http://mgrepl.wordpress.com/2012/06/20/how-would-tools-like-paster-work-with-selinux/">blog</a> for more details) we need to add a helper script which calls the <em>thin</em> binary from this helper script instead of either an init script or a systemd unit file.</p>
<p><span style="color:blue;"># rpm -ql aeolus-configserver |grep wrapper</span><br />
<span style="color:blue;">/usr/bin/aeolus-configserver-thinwrapper</span><br />
<span style="color:blue;"># cat /usr/bin/aeolus-configserver-thinwrapper</span></p>
<p><span style="color:blue;">#!/bin/bash</span></p>
<p><span style="color:blue;">/usr/bin/thin start -c $CONFIG_SERVER_DIR -l $THIN_LOG \<br />
-P $THIN_PID -a $THIN_IP -e $RACK_ENV \<br />
&#8211;user $AEOLUS_USER &#8211;group $AEOLUS_GROUP \<br />
-d &#8211;prefix=${PREFIX} -R $CONFIG_SERVER_RACKUP -p $CONFIG_SERVER_PORT</span></p>
<p>Now the following steps are needed to get an initial policy.</p>
<p>1. Create a new policy file.</p>
<p><span style="color:blue;"># echo &#8220;policy_module(aeolus_configserver,1.0)&#8221; &gt; aeolus_configserver.te</span></p>
<p>2. Use the template.</p>
<p><span style="color:blue;"># echo &#8220;thin_domain_template(aeolus_configserver)&#8221; &gt;&gt; aeolus_configserver.te</span></p>
<p>You can check the <em>thin_domain_template()</em> on</p>
<p><a href="http://git.fedorahosted.org/cgit/selinux-policy.git/tree/thin.if?h=master_contrib">http://git.fedorahosted.org/cgit/selinux-policy.git/tree/thin.if?h=master_contrib</a></p>
<p>3. Compile/load it.</p>
<p><span style="color:blue;"># make -f /usr/share/selinux/devel/Makefile aeolus_configserver.pp</span><br />
<span style="color:blue;"># semodule -i aeolus_configserver.pp</span></p>
<p>4. What will we get?</p>
<p>The following basic types will be created</p>
<p><span style="color:blue;"># seinfo -t |grep configserver<br />
thin_aeolus_configserver_exec_t<br />
thin_aeolus_configserver_t</span></p>
<p>by &#8220;<em>thin_domain_template(aeolus_configserver)</em>&#8220;.</p>
<p><em>* thin_aeolus_configserver_exec_t</em> type is an executable type for the aeolus-configserver-thinwrapper helper script.</p>
<p><span style="color:blue;"># ls -Z /usr/bin/aeolus-configserver-thinwrapper<br />
-rwxr-xr-x. root root system_u:object_r:thin_aeolus_configserver_exec_t:s0 /usr/bin/aeolus-configserver-thinwrapper<br />
</span></p>
<p><em>* thin_aeolus_configserver_t</em> domain type is a domain type for an aeolus-configserver thin process.</p>
<p>With these types we can see the following transition</p>
<p><em>initrc_t @ thin_aeolus_configserver_exec_t &#8211;&gt; thin_aeolus_configserver_t @ thin_exec_t &#8211;&gt; thin_aeolus_configserver_t</em></p>
<p>But without this helper script you would see</p>
<p><em>initrc_t @ thin_exec_t &#8211;&gt; thin_t</em></p>
<p>which means your project runs in the thin domain type defaultly and probably would not work. We have limited rules for the <em>thin_t</em> domain type because we want to know about this fact.</p>
<p>Now back to the <em>thin_aeolus_configserver_t</em> domain type. This type also got the <em>thin_domain</em> attribute. Basic rules are defined by the policy for all thin domains which are covered by this attribute.</p>
<p><strong>FOREMAN start point</strong></p>
<p>If you call</p>
<p><strong><em>thin_domain_template(foreman)</em></strong></p>
<p>you will get</p>
<p><span style="color:blue;"># seinfo -t |grep foreman<br />
thin_foreman_exec_t<br />
thin_foreman_t</span></p>
<p>and <em>thin_foreman_t</em> will have the <em>thin_domain</em> attribute with the following basic rules</p>
<p><a href="http://git.fedorahosted.org/cgit/selinux-policy.git/tree/thin.te?h=master_contrib">http://git.fedorahosted.org/cgit/selinux-policy.git/tree/thin.te?h=master_contrib</a></p>
<p>Check the <em>thin_domain</em> local policy section.</p>
<p>Note: You can also see the policy which has been created for <em>aeolus-configserver</em>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/249/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/249/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=249&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/11/30/how-would-tools-like-paster-work-with-selinux-thin-story/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>Help for us &#8230;. “template.te”</title>
		<link>http://mgrepl.wordpress.com/2012/10/28/help-for-us-template-te/</link>
		<comments>http://mgrepl.wordpress.com/2012/10/28/help-for-us-template-te/#comments</comments>
		<pubDate>Sun, 28 Oct 2012 23:03:55 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[Policy development]]></category>
		<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=236</guid>
		<description><![CDATA[From time to time I get questions how to write&#124;compile&#124;load own local policy module. We wrote a lot of blogs about using ausearch, audit2allow tools to generate a policy from AVC messages. We also mentioned the sepolgen tool to generate a new policy for services, applications, roles. Note: there is a new tool for this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=236&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>From time to time I get questions how to write|compile|load own local policy module. We wrote a lot of blogs about using <em>ausearch</em>, <em>audit2allow</em> tools to generate a policy from AVC messages. We also mentioned the <em>sepolgen</em> tool to generate a new policy for services, applications, roles.</p>
<p>Note: there is a new tool for this called “<a href="http://danwalsh.livejournal.com/60135.html">sepolicy</a>”.</p>
<p>But sometimes either you or I need to create a local test policy without these tools. Basically we start with</p>
<p><code># vim mypol.te</code></p>
<p>and add needed declarations for <em>mypol.te</em> policy file. For example<br />
<code><br />
# cat mypol.te<br />
policy_module(mypol,1.0)<br />
require{<br />
type ping_t;<br />
type openshift_initrc_t;<br />
}<br />
dontaudit ping_t openshift_initrc_t:fifo_file write;</code></p>
<p>Then we just compile/load this policy module.</p>
<p><code># make -f /usr/share/selinux/devel/Makefile mypol.pp</code><br />
<code># semodule -i mypol.pp</code></p>
<p>Based on this example we came up with a new VIM template for <em>*.te</em> policy file which would help us so we do not have to remember all these statements nor write them over and over. You can download this template from</p>
<p><a href="http://mgrepl.fedorapeople.org/template.te">http://mgrepl.fedorapeople.org/template.te</a></p>
<p>and execute</p>
<p><code># cp template.te /usr/share/vim/vimfiles/</code></p>
<p>After that just add the line to your /etc/vimrc file.</p>
<p><code>  autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec</code><br />
<code>+ autocmd BufNewFile *.te 0r /usr/share/vim/vimfiles/template.te</code><br />
<code>  augroup END</code></p>
<p>Now you can try to create a new local policy.</p>
<p><code># vim mypolicy.te</code></p>
<p>What do you think? Would you like to add some additional examples or comments?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=236&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/10/28/help-for-us-template-te/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>How would tools like &#8220;paster&#8221; work with SELinux?</title>
		<link>http://mgrepl.wordpress.com/2012/06/20/how-would-tools-like-paster-work-with-selinux/</link>
		<comments>http://mgrepl.wordpress.com/2012/06/20/how-would-tools-like-paster-work-with-selinux/#comments</comments>
		<pubDate>Wed, 20 Jun 2012 20:57:08 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[Info]]></category>
		<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=224</guid>
		<description><![CDATA[There are many projects which use/used a tool like the paster to create own application servers. For example, piranha, TurboGears2 and others. But what is a problem here? The paster tool is a python script. The script is called either from an init script or a systemd unit file by a project. This means we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=224&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>There are many projects which use/used a tool like the paster to create own application servers. For example, piranha, TurboGears2 and others. But what is a problem here?</p>
<p>The paster tool is a python script. The script is called either from an init script or a systemd unit file by a project. This means we can have multiple calling of this script to create running daemons. We have the following transition</p>
<p><span style="color:blue;">initrc_t @ bin_t -&gt; initrc_t</span></p>
<p>Probably you know this is wrong. We should confine daemons running in the <em>initrc_t</em> domain type. We had this issue with the piranha package. I did not know everything about the paster tool. I added the <em>piranha_web_exec_t</em> label for the paster python script and we got the following transition</p>
<p><span style="color:blue;">initrc_t @ piranha_web_exec_t -&gt; piranha_web_t</span></p>
<p>which is what we wanted. But this change caused TurboGears2 application servers running with <em>piranha_web_t</em> domain type. It was obviously wrong.</p>
<p>What happened?</p>
<p><span style="color:blue;">turbogears init script @ paster -&gt; TurboGears2 application server</span><br />
<span style="color:blue;">initrc_t @ piranha_web_exec_t -&gt; piranha_web_t</span></p>
<p>You see the problem. How could we solve issues like this? The solution is pretty easy because we know how SELinux and transitions work. We can just do</p>
<p><span style="color:blue;">initrc_t @ $1_exec_t -&gt;$1_t @ bin_t -&gt; $1_t</span></p>
<p>What is &#8220;<em>?_exec_t</em>&#8221; in this case? It can be a script which is called from either an init script or a systemd unit file and this script then calls the pastor python script with arguments. Then we get what we want</p>
<p><span style="color:blue;">initrc_t @ piranha_web_exec_t -&gt; piranha_web_t @ bin_t -&gt; piranha_web_t</span><br />
<span style="color:blue;">initrc_t @ turbogears_exec_t -&gt; turbogears_t @ bin_t -&gt; turbogears_t</span></p>
<p>and we can leave the pastor python script labeled as <em>bin_t</em>.</p>
<p>We can apply this solution for other projects.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=224&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/06/20/how-would-tools-like-paster-work-with-selinux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>How do we do selinux-policy updates?</title>
		<link>http://mgrepl.wordpress.com/2012/04/24/how-do-we-do-selinux-policy-updates/</link>
		<comments>http://mgrepl.wordpress.com/2012/04/24/how-do-we-do-selinux-policy-updates/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 22:52:31 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[Info]]></category>
		<category><![CDATA[Policy development]]></category>
		<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=204</guid>
		<description><![CDATA[Sometimes I get questions how we do selinux-policy updates. How does the process go? We go through all new bugs every day in the morning. So there are two periods per day because Dan is from USA and I am from Czech Republic. We add appropriate fixes to the selinux-policy repo on fedorahosted.org first and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=204&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Sometimes I get questions how we do selinux-policy updates. How does the process go?</p>
<p>We go through all new bugs <strong>every day</strong> in the morning. So there are two periods per day because Dan is from USA and I am from Czech Republic.</p>
<p>We add appropriate fixes to the selinux-policy repo on <a href="http://git.fedorahosted.org/git/?p=selinux-policy.git">fedorahosted.org</a> first and then we commit changes also to the selinux-policy git repo on <a href="http://pkgs.fedoraproject.org/gitweb/?p=selinux-policy.git">fedoraproject.org</a>. But this does not mean we do a new build immediately. The main reason is we want to cover as much bugs by a build as possible. So we do a new build either at the end of the day or the next day. Of course if a build is required we do it when is needed.</p>
<p>Also we are not able to do a new update with an each build. In this case, you can easily download new builds from <a href="http://koji.fedoraproject.org/koji/packageinfo?packageID=32">koji</a> and install them. So if you see</p>
<p><em>&#8220;Fixed in selinux-policy-&lt;version&gt;&#8221;</em></p>
<p>as a comment in a bug, you get a new build very soon. If not, then I have overslept and just ping me. I would like to thank all for testing/using a new builds from koji.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=204&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/04/24/how-do-we-do-selinux-policy-updates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>When should you use the “optional_policy” block statement?</title>
		<link>http://mgrepl.wordpress.com/2012/03/23/when-should-you-use-the-optional_policy-block-statement/</link>
		<comments>http://mgrepl.wordpress.com/2012/03/23/when-should-you-use-the-optional_policy-block-statement/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 07:28:43 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[Policy development]]></category>
		<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=164</guid>
		<description><![CDATA[After writing the blog on optional policy, I received the following question: “Ho do I know whether I need to use the optional_policy block or not?” When we write policy we can choose to have the policy either shipped within the base policy or as as module. We use the modules config files to specify [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=164&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>After writing the blog on <a href="http://mgrepl.wordpress.com/2011/12/04/troubles-with-policy-development-part-1/">optional policy</a>, I received the following question:</p>
<p><strong>“Ho do I know whether I need to use the optional_policy block or not?”</strong></p>
<p>When we write policy we can choose to have the policy either shipped within the base policy or as as module.</p>
<p>We use the modules config files to specify whether a policy is in the base or module.</p>
<p>We have a different modules config file for each policy type that we ship</p>
<p><em>modules-targeted.conf<br />
modules-mls.conf<br />
modules-minimum.conf</em></p>
<p>which contain statements like</p>
<p><span style="color:blue;"># Layer: kernel</span><br />
<span style="color:blue;"># Module: domain</span><br />
<span style="color:blue;"># Required in base</span><br />
<span style="color:blue;">#</span><br />
<span style="color:blue;"># Core policy for domains.</span><br />
<span style="color:blue;">#</span><br />
<span style="color:blue;">domain = base</span></p>
<p><span style="color:blue;"># Layer: system</span><br />
<span style="color:blue;"># Module: init</span><br />
<span style="color:blue;">#</span><br />
<span style="color:blue;"># System initialization programs (init and init scripts).</span><br />
<span style="color:blue;">#</span><br />
<span style="color:blue;">init = module</span></p>
<p>What does either “base” or “module” mean? The note says</p>
<p><span style="color:blue;"># For modular policies, modules set to &#8220;base&#8221; will be</span><br />
<span style="color:blue;"># included in the base module. &#8220;module&#8221; will be compiled</span><br />
<span style="color:blue;"># as individual loadable modules.</span></p>
<p>The base.pp policy module contains core policy modules which are needed for the basic confinement of your system focused on the core operating system. The base.pp module can not be removed from your policy.</p>
<p>But what about “module”. This is different. Theoretically these modules are all optional. Meaning you should be able to remove them from the policy if you wanted to.</p>
<p>You can list the modules using:</p>
<p><span style="color:blue;">$ semodule -l</span></p>
<p>There are some exceptions for modules like miscfiles, authlogin, init,<br />
systemd, sysnetwork. We define them as “module” in the <em>modules-*.conf</em><br />
file but they can not be removed.</p>
<p>Another way of looking at this would be to examine the directories in<br />
which we ship the interfaces. We ship interface files in <em>/usr/share/selinux/devel/include/</em> subdirs</p>
<p><em>system kernel roles services admin apps</em></p>
<p>Interfaces in <em>system</em> and<em> kernel</em> are core to the system, while interfaces in the other directories as optional.</p>
<p>Let&#8217;s say you write a policy and you need to use a rpm interface because your application execute <em>rpm -qi</em>. First, we need to examine that the rpm module is not a part of the base.pp policy module</p>
<p><span style="color:blue;">$ semodule -l | grep rpm</span><br />
<span style="color:blue;">rpm 1.12.0</span></p>
<p>Ok, I see it is not. So I will call a rpm interface with the <em>optional_policy</em> block.</p>
<p><span style="color:blue;">optional_policy(`</span><br />
<span style="color:blue;">rpm_exec(mydomain_t)</span><br />
<span style="color:blue;">&#8216;)</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=164&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/03/23/when-should-you-use-the-optional_policy-block-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>How to confine a new service using an available policy</title>
		<link>http://mgrepl.wordpress.com/2012/03/08/how-to-confine-a-new-service-using-an-available-policy/</link>
		<comments>http://mgrepl.wordpress.com/2012/03/08/how-to-confine-a-new-service-using-an-available-policy/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 21:56:41 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=142</guid>
		<description><![CDATA[Sometimes new services, which are a part of a project, are added. For example we could talk about cluster, cloudform, MRG services and so on. Yesterday I got a new bug with the following description &#8220;matahari-qmf-rpcd runs as initrc_t&#8221; It means that our policy does not cover the matahari-qmf-rpcd service which probably has been shipped [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=142&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Sometimes new services, which are a part of a project, are added. For example we could talk about cluster, cloudform, MRG services and so on. Yesterday I got a new bug with the following description<br />
<strong><br />
&#8220;matahari-qmf-rpcd runs as initrc_t&#8221;</strong></p>
<p>It means that our policy does not cover the matahari-qmf-rpcd service which probably has been shipped recently. I know nothing about this service and I want to confine it. I am not sure if we have a policy for Matahari project so I use the selinux-policy-doc package to check it.</p>
<p><font color="blue">$ rpm -q selinux-policy-doc</font><br />
<font color="blue">selinux-policy-doc-3.10.0-96.fc17.noarch</font></p>
<p>The package is installed and I am able to find whether a policy exists</p>
<p><font color="blue">$ grep -r matahari /usr/share/selinux/devel/include/ |wc -l</font><br />
<font color="blue">256</font></p>
<p>There is a policy which I could use. We are interested in the <em>/usr/share/selinux/devel/include/services/matahari.if</em> policy file and the <em>matahari_domain_template()</em> interface. A template interface is a special interface to create a basic set of rules for services &#8211; template interfaces generate domain, executable and file types for a service. </p>
<p>In our case I declare the following local policy.</p>
<p><font color="blue">$ cat mymatahari.te</font><br />
<font color="blue">policy_module(mymatahari,1.0)</font></p>
<p><font color="blue">matahari_domain_template(rpcd)</font></p>
<p>Then I load and install it.</p>
<p><font color="blue">$ make -f /usr/share/selinux/devel/Makefile mymatahari.pp</font><br />
<font color="blue">$ semodule -i mymatahari.pp</font></p>
<p>You can see what types were added.</p>
<p><font color="blue">$ seinfo -t |grep matahari_rpc</font><br />
   <font color="blue">matahari_rpcd_unit_file_t</font><br />
   <font color="blue">matahari_rpcd_exec_t</font><br />
   <font color="blue">matahari_rpcd_t</font></p>
<p>These three types were created by the matahari_domain_template() interface and we use them for an initial confinement. Now we need to tell SELinux that the matahari-qmf-rpcd service started by systemd should end up in the matahari_rpcd_t domain.</p>
<p><font color="blue">$ chcon -t matahari_rpcd_exec_t `which matahari-qmf-rpcd`</font><br />
<font color="blue">$ systemctl restart matahari-rpc.service</font><br />
<font color="blue">$ ps -eZ |grep matahari</font><br />
<font color="blue">system_u:system_r:matahari_rpcd_t:s0 3338 ?    00:00:00 matahari-qmf-rp</font></p>
<p>You are done and you have this new service running in the proper domain. Now you can use ausearch/audit2allow tools to check AVC messages</p>
<p><font color="blue">$ ausearch -m avc -ts recent |audit2allow</font><br />
<font color="blue">#============= matahari_rpcd_t ==============</font><br />
<font color="blue">allow matahari_rpcd_t bin_t:file getattr;</font><br />
<font color="blue">allow matahari_rpcd_t passwd_file_t:file { read getattr open };</font><br />
<font color="blue">allow matahari_rpcd_t usr_t:file { read getattr open };</font></p>
<p>The next step would be either file a new bug with these AVC messages and with the local policy or use the audit2allow tool to generate rules for the mymatahari.te policy file.</p>
<p><font color="blue">$ ausearch -m avc -ts recent |audit2allow -R |grep \(matahari &gt;&gt; mymatahari.te</font><br />
<font color="blue">$ make -f /usr/share/selinux/devel/Makefile mymatahari.pp</font><br />
<font color="blue">$ semodule -i mymatahari.pp</font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=142&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/03/08/how-to-confine-a-new-service-using-an-available-policy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>Cool stuff &#8211; sftp+chroot+SELinux</title>
		<link>http://mgrepl.wordpress.com/2012/02/09/cool-stuff-sftpchrootselinux/</link>
		<comments>http://mgrepl.wordpress.com/2012/02/09/cool-stuff-sftpchrootselinux/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 15:27:35 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/2012/02/09/cool-stuff-sftpchrootselinux/</guid>
		<description><![CDATA[Petr Lautrbach (openssh package maintainer) wrote a great blog about cool stuff &#8211; sftp+chroot+SELinux<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=139&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Petr Lautrbach (openssh package maintainer) wrote a great blog about cool stuff &#8211; <a href="http://bachradsusi.livejournal.com/2239.html">sftp+chroot+SELinux</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=139&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/02/09/cool-stuff-sftpchrootselinux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>Can we use SELinux for debugging of an application?</title>
		<link>http://mgrepl.wordpress.com/2012/02/06/can-we-use-selinux-for-debugging-of-an-application/</link>
		<comments>http://mgrepl.wordpress.com/2012/02/06/can-we-use-selinux-for-debugging-of-an-application/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 21:24:15 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=105</guid>
		<description><![CDATA[From time to time I am not able to find out a solution for a bug simply. I need to know if an access is really needed and which command or function causes it. This is the time for debugging. I guess you know tools like strace, gdb, which help us with debugging. Today I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=105&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>From time to time I am not able to find out a solution for a bug simply. I need to know if an access is really needed and which command or function causes it. This is the time for debugging.</p>
<p>I guess you know tools like <em>strace</em>, <em>gdb</em>, which help us with debugging. Today I would like to show you how SELinux could help us to understand what an application, a script or a command does.</p>
<p>I have recently got the following AVC msg:</p>
<p><em>type=AVC msg=audit(1328313263.274:55): avc:  denied  { read } for  pid=869 comm=&#8221;smartdnotify&#8221; name=&#8221;group&#8221; dev=(removed) ino=293602 scontext=system_u:system_r:fsdaemon_t:s0 tcontext=system_u:object_r:passwd_file_t:s0 tclass=filenode=(removed)</em></p>
<p>which tells me that the fsdaemon_t domain is trying to access to the /etc/group file with the passwd_file_t label.</p>
<p><font color="blue">$ grep -r passwd_file_t /etc/selinux/targeted/contexts/files/</font></p>
<p>So I need to find a part of code which needs this access. Usually we see a similar AVC message if a getpw* function is called. That is the time for <em>nm</em> and <em>grep</em> commands.</p>
<p><font color="blue">$ nm -D PATHTO_BINARY |grep getpw</font><br />
<font color="blue">$ grep -r getpw SOURCE_CODE</font></p>
<p>If you get a result, you will be happy. If not, you need to continue with finding.</p>
<p>Our issue is a case where the smartdnotify command, which causes AVC message, is a shell script. I looked at this script and I got it.</p>
<p><font color="blue">$ cat /usr/libexec/smartmontools/smartdnotify |grep who</font><br />
<font color="blue">for t in $(who | awk &#8216;{ print $2; }&#8217; | grep -e &#8216;^tty&#8217; -e &#8216;^pts/&#8217;)</font></p>
<p>But what to do if you don&#8217;t know that the &#8220;who&#8221; command reads the /etc/group file? You could try to use SELinux to find out an answer. Everything what you need to do is to use SELinux tools.</p>
<p>1. Turn on full auditing system.<br />
<font color="blue">$ echo &#8220;-w /etc/shadow -p w&#8221; &gt;&gt; /etc/audit/audit.rules</font><br />
<font color="blue">$ service auditd restart</font></p>
<p>2. Generate a local test policy for the &#8220;who&#8221; command (or your application).<br />
<font color="blue">$ sepolgen -n debugwho -t 0 PATHTO/who</font></p>
<p>3. Remove the context declaration from the debugwho.fc policy file. It might cause a problem with a duplicate declaration.<br />
<font color="blue">$ echo &#8220;#no context&#8221; &gt; debugwho.fc</font><br />
<font color="blue">$ sh debugwho.sh</font><br />
<font color="blue">$ chcon -t debugwho_exec_t PATHTO/who</font></p>
<p>Now you have loaded debug policy and you need to run the &#8220;who&#8221; command in this domain.</p>
<p><font color="blue">$ runcon -t system_u -r system_r -t initrc_t &#8212; runcon debugwho_t &#8212; who</font></p>
<p>The following transition will happen:</p>
<p>unconfined_t -&gt; initrc_t -&gt; debugwho_t</p>
<p><font color="blue">$ ausearch -m avc -ts recet |grep passwd</font></p>
<p><em>type=AVC msg=audit(1328540990.575:125): avc:  denied  { read } for  pid=2258 comm=&#8221;who&#8221; name=&#8221;group&#8221; dev=&#8221;dm-1&#8243; ino=527060 scontext=system_u:system_r:debugwho_t:s0-s0:c0.c1023 tcontext=system_u:object_r:passwd_file_t:s0 tclass=file</em></p>
<p>and you won. </p>
<p>Imagine you use it for more complicated applications, services which use python bindings for example.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=105&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2012/02/06/can-we-use-selinux-for-debugging-of-an-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>Troubles with policy development, part #1</title>
		<link>http://mgrepl.wordpress.com/2011/12/04/troubles-with-policy-development-part-1/</link>
		<comments>http://mgrepl.wordpress.com/2011/12/04/troubles-with-policy-development-part-1/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 22:38:05 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[Policy development]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=72</guid>
		<description><![CDATA[Some time ago I got a question from a guy about some troubles with his policy development . I decided to write a set of blogs related to common troubles which either we or other folks could have in policy development. Now back to the problem. This guy got a similar error message: &#8220;/usr/bin/semodule_link: loading [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=72&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Some time ago I got a question from a guy about some troubles with his policy development . I decided to write a set of blogs related to common troubles which either we or other folks could have in policy development.</p>
<p>Now back to the problem. This guy got a similar error message:</p>
<p><em>&#8220;/usr/bin/semodule_link: loading package libsepol.print_missing_requirements: rhcs&#8217;s global requirements were not met: type/attribute corosync_exec_t<br />
/usr/bin/semodule_link: Error while linking packages&#8221;</em></p>
<p>through building of his custom policy.</p>
<p>We use &#8220;<em>optional_policy</em>&#8221; statement to declare a rule which could be invalid if an appropriate module (module containing a declaration of an interface) is disabled/removed or is not declared. Probably the following example is better than my definition.</p>
<p><font color="blue">optional_policy(`<br />
corosync_exec(fenced_t)<br />
&#8216;)</font></p>
<p>allows the fenced binary to execute the Corosync Cluster Engine. Now how could this rule become invalid? Easily by disabling of the corosync policy module which contains this interface definition.</p>
<p><font color="blue"># semodule -d corosync</font></p>
<p>This is a way how we do the policy really modular. You can remove a module from the policy and everything should work fine, only a daemon or a user program will be without SELinux protection. You can check this out and make your policy being as minimal as you wish. Just be careful with removing of the unconfineduser policy module (see <a href="http://danwalsh.livejournal.com/42394.html">http://danwalsh.livejournal.com/42394.html</a>).</p>
<p>So if you use an interface without &#8220;optional&#8221; statement and you disable/remove or do not add a module declaration into the <em>module-*.conf</em> file, you will get exactly the same error message.</p>
<p>Note: If the &#8220;<em>optional_policy</em>&#8221; declaration contains more rules then all these rules will become invalid for this block.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=72&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2011/12/04/troubles-with-policy-development-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
		<item>
		<title>Making a domain &#8220;unconfined&#8221;</title>
		<link>http://mgrepl.wordpress.com/2011/10/19/making-a-domain-unconfined/</link>
		<comments>http://mgrepl.wordpress.com/2011/10/19/making-a-domain-unconfined/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 13:29:51 +0000</pubDate>
		<dc:creator>mgrepl</dc:creator>
				<category><![CDATA[SELinux in daily using]]></category>

		<guid isPermaLink="false">http://mgrepl.wordpress.com/?p=68</guid>
		<description><![CDATA[Dan describes other cool SELinux stuff.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=68&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Dan describes <a href="http://danwalsh.livejournal.com/47066.html">other cool SELinux stuff</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mgrepl.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mgrepl.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mgrepl.wordpress.com&#038;blog=26699041&#038;post=68&#038;subd=mgrepl&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mgrepl.wordpress.com/2011/10/19/making-a-domain-unconfined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6f016fc47a45877b3db46e459e7d5b85?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mgrepl</media:title>
		</media:content>
	</item>
	</channel>
</rss>
