<font face="courier new,monospace"><br></font><br><div class="gmail_quote">On Fri, Feb 14, 2014 at 9:43 AM, Daniel J Walsh <span dir="ltr">&lt;<a href="mailto:dwalsh@redhat.com" target="_blank">dwalsh@redhat.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
</div><div class="">On 02/14/2014 09:17 AM, Fulko Hew wrote:<br>
&gt; On Fri, Feb 14, 2014 at 8:58 AM, Daniel J Walsh &lt;<a href="mailto:dwalsh@redhat.com">dwalsh@redhat.com</a><br>
</div><div class="">
&gt; On 02/14/2014 08:42 AM, Fulko Hew wrote:<br>
&gt;&gt; I made a package a long time ago, and over the years I&#39;ve been adding<br>
&gt;&gt; new features, but the correct? support of SELinux has always eluded me.<br>
&gt;&gt; Occasionally I encounter problems with new versions of Fedora and RHEL.<br>
&gt;&gt; Recently I was asked to support the installation of my RPM on RHEL 6<br>
&gt;&gt; systems, and I find that there are new SELinux feature/requirements.<br>
&gt;&gt;<br>
&gt;&gt; Its probably me, but I haven&#39;t found any instructions/how-tos that have<br>
&gt;&gt; really helped (me) in providing the steps for testing and making a<br>
&gt;&gt; package SELinux compatible.  I have something that works on older<br>
&gt;&gt; releases, but I&#39;ve probably done it wrong.<br>
&gt;&gt;<br>
&gt;&gt; There&#39;s lots of documentation about its concepts, but not anything that<br>
&gt;&gt; has helped me in porting.<br>
&gt;&gt;<br>
&gt;&gt; Scenario:<br>
&gt;&gt;<br>
&gt;&gt; Given a working RPM (with SELinux disabled)... what would the process be<br>
&gt;&gt; (with examples) of turning SELinux on, attempting to install and run the<br>
&gt;&gt; various applications, viewing security logs, and turning any errors<br>
&gt;&gt; detected into correct config files/commands that can be included in a<br>
&gt;&gt; spec-file/package.<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt;<br>
&gt;&gt; Fulko<br></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
&gt; SELinux is a labeling system. You need to make sure any content that you<br>
&gt; provide to confined services is labeled correctly.  The way you do this is<br>
&gt; by using a command like semanage fcontext ...  in a post install and then<br>
&gt; using restorecon to fix the labels.<br>
&gt;<br>
&gt; SELinux also has the concept of booleans which allow users to modify the<br>
&gt; policy on the system.  Depending on what you app wants to do you might need<br>
&gt; to modify a boolean.<br>
&gt;<br>
&gt; Finally SELinux expects network ports to match some defaults.  If you want<br>
&gt; to change the default Network Port then you have to tell SELinux about<br>
&gt; this.<br>
&gt;<br>
&gt; semanage port ...<br>
&gt;<br>
&gt; SELinux error messages are stored in /var/log/audit/audit.log and called<br>
&gt; avc messages.<br>
&gt;<br>
&gt; ausearch -m avc -ts recent<br>
&gt;<br>
&gt; Can show you recent avc messages that your system received.<br>
&gt;<br>
&gt; For now, my spec file has a bunch of semanage/restorecon command pairs, for<br>
&gt; such things as:<br>
&gt;<br>
&gt; semanage fcontext -a -t httpd_sys_script_exec_t   myFile semanage fcontext<br>
&gt; -a -t httpd_sys_rw_content_t    myOtherFile semanage fcontext -a -t<br>
&gt; httpd_sys_content_t       yetOtherFiles<br>
&gt;<br>
&gt; a) Is this the &#39;right&#39; way to do it?<br>
&gt;<br>
</div>Well you can combine these into a single transaction, which would speed it up.<br>
<br>
semanage -S targeted -i - &lt;&lt; _EOF<br>
boolean -m --on allow_polyinstantiation<br>
boolean -m --on xguest_connect_network<br>
boolean -m --on xguest_mount_media<br>
boolean -m --on xguest_use_bluetooth<br>
_EOF<br>
<br>
This is what the xguest package does.<br><div class=""></div></blockquote><div><font face="courier new,monospace"><br>I&#39;m sorry, but I don&#39;t understand how to map your example into my values/example.<br><br>I also have a new problem.  I&#39;ve been testing against F20 Live (KDE) and the<br>

package (policycoreutils-python) that provides semanage isn&#39;t installed<br>so semanage isn&#39;t available when my RPM is installed.<br>What is the recommended approach?<br><br>a) should I make my package/.spec &#39;require&#39; policycoreutils-python?<br>

   (It would seem unusual to place that burden on package maintainers.)<br>b) Use some other technique to configure/distribute security info.<br>   (Is this where policy files come into play?)<br>   1. Where can I find a good example of how to create policy files<br>

      given the contents of a .spec<br>   2. And, what needs to be added to a .spec so that the &#39;policy&#39; is installed?<br><br></font><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="">
&gt; b) an example of the new error/warning is:<br>
&gt;<br>
&gt; Feb 13 14:37:58 livecd kernel: type=1400 audit(1392320278.129:151): avc:<br>
&gt; denied  { name_connect } for  pid=4517 comm=&quot;<a href="http://view_status.pl" target="_blank">view_status.pl</a><br>
</div>&gt; &lt;<a href="http://view_status.pl" target="_blank">http://view_status.pl</a>&gt;&quot; dest=27395<br>
<div class="">&gt; scontext=unconfined_u:system_r:httpd_sys_script_t:s0<br>
&gt; tcontext=system_u:object_r:port_t:s0 tclass=tcp_socket<br>
&gt;<br>
</div>Well in a perfect world you would write policy for your cgi script. using a<br>
tool like sepolgen or sepolicy generate, depending on whether you are shipping<br>
in RHEL6 or Fedora.<br>
<br>
You could also turn on the httpd_can_network_connect boolean which would allow<br>
apache processes to connect to any ports.<br></blockquote><div><span style="font-family:courier new,monospace"><br>I turns out that I did have code in the %post portion of my .spec to set<br>that boolean, but due to a bug on my part, the boolean wasn&#39;t being set<br>

under certain conditions.<br> </span><br></div></div>