<?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>olivetalks &#187; SELinux</title>
	<atom:link href="http://www.olivetalks.com/tag/selinux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.olivetalks.com</link>
	<description>The Olive has arrived and it has things to say…</description>
	<lastBuildDate>Tue, 20 Jul 2010 06:27:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting up UPS on CentOS 5.2 with SELinux, part 2</title>
		<link>http://www.olivetalks.com/2009/02/21/ups-on-centos-with-selinux-part-2/</link>
		<comments>http://www.olivetalks.com/2009/02/21/ups-on-centos-with-selinux-part-2/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 06:00:10 +0000</pubDate>
		<dc:creator>ZoltarStark</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[UPS]]></category>

		<guid isPermaLink="false">http://www.olivetalks.com/2009/02/21/ups-on-centos-with-selinux-part-2/</guid>
		<description><![CDATA[After setting up UPS monitoring software on a computer it would be good to allow access to this information via a web browser.]]></description>
			<content:encoded><![CDATA[<p>In the <a href="/2009/02/19/ups-on-centos-with-selinux-part-1/" title="Setting up UPS on CentOS 5.2 with SELinux, part 1">previous post</a> I have described how to setup monitoring of UPS battery status with <a href="http://www.networkupstools.org/" title="Network UPS Tools">Network UPS Tools</a> so your computer can shut down gracefully in case of power loss. At the end we configured a CGI script to allow checking the UPS status via a web browser. Unfortunately this didn&#8217;t work very well because of a missing SELinux policy. This post will explain how to install the required policy module.</p>
<p><strong>Step one: Define the policy module</strong></p>
<p>To define the policy module for nut CGI create a text file nutcgi.te with the following content:</p>
<p><code>module nutcgi 1.0.8;</code></p>
<p><code>require {</code><br />
<code>type unlabeled_t;</code><br />
<code>type xend_var_log_t;</code><br />
<code>type httpd_sys_script_exec_t;</code><br />
<code>type default_t;</code><br />
<code>type procmail_t;</code><br />
<code>type ping_t;</code><br />
<code>type httpd_t;</code><br />
<code>type httpd_sys_script_t;</code><br />
<code>type port_t;</code><br />
<code>class tcp_socket { write name_connect connect shutdown read create };</code><br />
<code>class lnk_file { read getattr };</code><br />
<code>class file append;</code><br />
<code>class dir search;</code><br />
<code>class packet { recv send };</code><br />
<code>}</code></p>
<p><code>#============= httpd_sys_script_t ==============</code><br />
<code># src="httpd_sys_script_t" tgt="port_t" class="tcp_socket", perms="name_connect"</code><br />
<code># comm="upsstats.cgi" exe="" path=""</code><br />
<code>allow httpd_sys_script_t port_t:tcp_socket name_connect;</code><br />
<code># src="httpd_sys_script_t" tgt="httpd_sys_script_t" class="tcp_socket", perms="{ write read create connect shutdown }"</code><br />
<code># comm="upsstats.cgi" exe="" path=""</code><br />
<code>allow httpd_sys_script_t self:tcp_socket { write read create connect shutdown };</code><br />
<code># src="httpd_sys_script_t" tgt="unlabeled_t" class="packet", perms="{ recv send }"</code><br />
<code># comm="upsstats.cgi" exe="" path=""</code><br />
<code>allow httpd_sys_script_t unlabeled_t:packet { recv send };</code></p>
<p><code>#============= httpd_t ==============</code><br />
<code># src="httpd_t" tgt="httpd_sys_script_exec_t" class="lnk_file", perms="{ read getattr }"</code><br />
<code># comm="httpd" exe="" path=""</code><br />
<code>allow httpd_t httpd_sys_script_exec_t:lnk_file { read getattr };</code></p>
<p>Save the file somewhere.</p>
<p><strong>Step two :  Compile the policy module</strong></p>
<p>Execute the command:</p>
<p><code>checkmodule -M -m nutcgi.te -o nutcgi.mod</code></p>
<p>This will generate a binary file representing the policy module.</p>
<p><strong>Step three: Create a SELinux policy module package</strong></p>
<p>Execute the command:</p>
<p><code>semodule_package -o nutcgi.pp -m nutcgi.mod</code></p>
<p>This will create a SELinux policy module package which can then be installed.</p>
<p><strong>Step four: Install the SELinux policy module package</strong></p>
<p>Execute the command:</p>
<p><code>semodule -i nutcgi.pp</code></p>
<p>Now the policy module is installed. You can refresh the web page with UPS status in your web browser <font color="#000080">http://localhost/cgi-bin/upsstats.cgi</font></p>
<p><a href="http://www.olivetalks.com/wp-content/uploads/2009/02/ups-status-selinux-configured.jpg" title="UPS status in web browser after installing SELinux policy module"></a></p>
<p style="text-align: center"><a href="http://www.olivetalks.com/wp-content/uploads/2009/02/ups-status-selinux-configured.jpg" title="UPS status in web browser after installing SELinux policy module"><img src="http://www.olivetalks.com/wp-content/uploads/2009/02/ups-status-selinux-configured-small.jpg" alt="UPS status in web browser after installing SELinux policy module" /></a></p>
<p>You can also verify that access to this web page from other machines works as intended. SELinux policy module installation is persistent &#8211; you don&#8217;t have to do it again if the system reboots.</p>
<h3>Related post(s)</h3><ul class="related_post"><li><a href="http://www.olivetalks.com/2009/02/19/ups-on-centos-with-selinux-part-1/" title="Setting up UPS on CentOS 5.2 with SELinux, part 1">Setting up UPS on CentOS 5.2 with SELinux, part 1 (0)</a></li><li><a href="http://www.olivetalks.com/2009/06/24/skype-40-for-windows-is-out-pros-and-cons-compared-with-linux-skype-20/" title="Skype 4.0 for Windows is out: Pros and cons (compared with Linux Skype 2.0) ">Skype 4.0 for Windows is out: Pros and cons (compared with Linux Skype 2.0)  (1)</a></li><li><a href="http://www.olivetalks.com/2009/02/17/big-eee/" title="Eee PC 901 &#8211; aka Big Eee">Eee PC 901 &#8211; aka Big Eee (0)</a></li><li><a href="http://www.olivetalks.com/2009/02/15/find-changes-with-rpm-verify/" title="What files did I change?">What files did I change? (2)</a></li><li><a href="http://www.olivetalks.com/2008/06/17/too-much-success-and-popularity/" title="Too much success and popularity?">Too much success and popularity? (0)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.olivetalks.com/2009/02/21/ups-on-centos-with-selinux-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setting up UPS on CentOS 5.2 with SELinux, part 1</title>
		<link>http://www.olivetalks.com/2009/02/19/ups-on-centos-with-selinux-part-1/</link>
		<comments>http://www.olivetalks.com/2009/02/19/ups-on-centos-with-selinux-part-1/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 07:00:57 +0000</pubDate>
		<dc:creator>ZoltarStark</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[UPS]]></category>

		<guid isPermaLink="false">http://www.olivetalks.com/2009/02/19/ups-on-centos-with-selinux-part-1/</guid>
		<description><![CDATA[Power failure for a computer can cause data loss and require many hours to undo the damage. That can be especially bad if the computer acts as a server. At the minimum, servers must have a chance to perform an proper shut down to avoid damage to data or hardware.]]></description>
			<content:encoded><![CDATA[<p>My home fileserver is connected to a UPS in order to be able to shut down properly when there&#8217;s a problem with the electricity supply. Of course, just connecting a computer to a UPS won&#8217;t help if the power is cut off for more than a few minutes since the machine won&#8217;t turn itself off before the battery runs out of juice. To guarantee that the OS is aware of the current state of the battery some software needs to be installed and configured. I use for that purpose <a href="http://www.networkupstools.org/" title="Network UPS Tools">Network UPS Tools</a>. If your system is running with SELinux enabled and you want to enable checking of the UPS via a web browser then you also need to install an appropriate SELinux policy module.</p>
<p><strong>Let&#8217;s start with the installation.</strong></p>
<p>First things first &#8211; make sure the UPS is running and connected to the computer. Both power and a serial cable of some kind should be connected. The serial connection can be either via RS-232 or USB.</p>
<p>To install the software execute the following command:</p>
<p><code># yum install nut nut-client nut-cgi</code></p>
<p>or if you&#8217;re running a 64 bit OS and don&#8217;t want 32-bit packages to be installed:</p>
<p><code># yum install nut nut-client.x86_64 nut-cgi</code></p>
<p><strong>Next step: Basic configuration</strong></p>
<p>After the software is installed we need to configure it. Fire up your favourite text editor and open these files:</p>
<ul>
<li>/etc/ups/ups.conf</li>
<li>/etc/ups/upsd.users</li>
<li>/etc/ups/upsmon.conf</li>
<li>/etc/ups/hosts.conf (only if you have installed nut-cgi)</li>
</ul>
<p>In <em>/etc/ups/ups.conf</em> add at the end the following section:</p>
<p><code>user = nut                       # execute the UPS driver as user nut - otherwise the upsd program won't be able to connect to the device </code></p>
<p><code>[pw3105]                                                   # name of the UPS device</code><br />
<code>driver = bcmxcp_usb                  # driver used to access the UPS device</code><br />
<code>port = auto                                          # serial port where the UPS is connected, bcmxcp_usb driver allows to enter 'auto' here</code><br />
<code>shutdown_delay = 0                     # additional parameter supported by bcmxcp_usb driver, see 'man bcmxcp_usb'</code></p>
<p>The comments explain what is the purpose of each line. More details can be found in man page for <a href="http://linux.die.net/man/5/ups.conf" title="ups.conf(5) - Linux man page">ups.conf</a>. The actual name of the UPS device and parameters for it depend on the UPS model you&#8217;re using. I have Powerware 3105 UPS which uses the <a href="http://linux.die.net/man/8/bcmxcp_usb" title="bcmxcp_usb(8) - Linux man page">bcmxcp_usb driver</a>.</p>
<p>Second file to edit is <em>/etc/ups/upsd.users</em> where you should append these lines:</p>
<p><code>[server]                                                    # create a user 'server'</code><br />
<code>password = ups                                  # with password 'ups'</code><br />
<code>allowfrom = localhost             # allowing access only from this machine</code><br />
<code>instcmds = ALL                                  # user can execute all instant commands</code><br />
<code>upsmon master                                    # add actions necessary for a 'upsmon' process to work</code></p>
<p>Again the purpose of each line is explained in the comments. More information as usual in man page for <a href="http://linux.die.net/man/5/upsd.users" title="upsd.users(5) - Linux man page">upsd.users</a>.</p>
<p>If you use different values in <em>/etc/ups/upsd.users</em> you have to make sure that you&#8217;ll use the same values also in the next file we&#8217;re going to edit, which is <em>/etc/ups/upsmon.conf</em>. Here add these lines at the end:</p>
<p><code>FINALDELAY 0                                                                                                          # don't wait before shutting down, allowed values depend on the UPS model</code><br />
<code>RUN_AS_USER nut                                                                                                 # don't run as root to avoid security issues</code><br />
<code>MONITOR pw3105@localhost 1 server ups master          # which UPS to monitor</code></p>
<p>The last line requires a bit of explanation:</p>
<ul>
<li> <em>pw3105@localhost</em> is the identifier of the UPS we want to monitor. <em>pw3105</em> is the same name we have used before in <em>/etc/ups/ups.conf</em> so make sure it matches. <em>@localhost</em> indicates that we&#8217;re monitoring a UPS connected directly to the machine on which <em>upsmon</em> program is running. <em>upsmon</em> can also monitor UPSes connected to other machines on the network.</li>
<li><em>1</em> indicates that this particular UPS feeds 1 power supply on this system. That&#8217;s the usual value for this parameter.</li>
<li><em>server</em> and <em>ups</em> are the user name and password we have defined previously in <em>/etc/ups/upsd.users</em></li>
<li><em>master</em><em> </em>indicates relationship with <em>upsd</em> daemon and again must match what is defined in <em>/etc/ups/upsd.users</em></li>
</ul>
<p>More explanations can be found in man page for <a href="http://linux.die.net/man/5/upsmon.conf" title="upsmon.conf(5) - Linux man page">upsmon.conf</a>.</p>
<p>After these modifications verify the permissions and ownership of the configuration files matches this:</p>
<p><code># ll /etc/ups/ups.conf /etc/ups/upsd.users /etc/ups/upsmon.conf</code><br />
<code>-rw-r----- 1 root nut  3735 Jan 22 00:33 /etc/ups/ups.conf</code><br />
<code>-rw-r----- 1 root nut  2307 Jan 22 00:08 /etc/ups/upsd.users</code><br />
<code>-rw-r----- 1 root nut 11194 Jan 22 00:09 /etc/ups/upsmon.conf</code></p>
<p>and then you can start the software:</p>
<p><code># service ups start</code></p>
<p>You should see this output:</p>
<p><code><font color="#000000">Starting UPS driver controller:             [  </font>OK<font color="#000000">  ]</font></code><br />
<code><font color="#000000">Starting upsd:                              [  </font>OK<font color="#000000">  ]</font></code><br />
<code><font color="#000000">Starting UPS monitor (master):              [  </font>OK<font color="#000000">  ]</font></code></p>
<p>And make sure that UPS software will start automatically after system reboots:</p>
<p><code># chkconfig nut on</code></p>
<p>Verify that the UPS is accessible by executing:</p>
<p><code># upsc pw3105@localhost</code></p>
<p>which should print something like this:</p>
<p><code>driver.name: bcmxcp_usb</code><br />
<code>driver.parameter.pollinterval: 2</code><br />
<code>driver.parameter.port: auto</code><br />
<code>driver.parameter.shutdown_delay: 0</code><br />
<code>driver.version: 2.2.0-</code><br />
<code>driver.version.internal: 0.11</code><br />
<code>output.phases: 1</code><br />
<code>ups.alarm:</code><br />
<code>ups.firmware: Cont:00.80 Inve:00.60</code><br />
<code>ups.model: POWERWARE UPS    500VA</code><br />
<code>ups.power.nominal: 500</code><br />
<code>ups.serial:</code><br />
<code>ups.status: OL</code><br />
<code>ups.voltage.nominal: 230</code></p>
<p>The actual values depend on the UPS model.</p>
<p>At this point the system is configured to automatically shut down when the UPS will indicate that the battery is low on power. You should test this scenario on your system to make sure that it will work when you really need it.</p>
<p><strong>Last step:  Configure web access to upsmon</strong></p>
<p>The last step is to configure monitoring of UPS status via a web browser. We have already installed <em>nut-cgi</em> package which contains the necessary CGI scripts. This package includes a file <em>/var/www/nut-cgi-bin/upsstats.cgi</em> which you should copy to <em>/var/www/cgi-bin/</em> directory:</p>
<p><code># cp /var/www/nut-cgi-bin/upsstats.cgi /var/www/cgi-bin/</code></p>
<p>After that modify file /etc/ups/hosts.conf by appending this line:</p>
<p><code>MONITOR pw3105@localhost "Local UPS"</code></p>
<p>As before <em>pw3105@localhost</em> is the name of UPS to monitor. &#8220;Local UPS&#8221; defines the name which will appear in the web page.</p>
<p>Now start your web server if it&#8217;s not running yet and (optionally) configure the firewall to allow access to port 80 from other machines.</p>
<p>You can now check status of the UPS via a web browser by typing the following in the address bar <font color="#000080">http://localhost/cgi-bin/upsstats.cgi</font></p>
<p>Unfortunately if you&#8217;re running with SELinux enabled then you won&#8217;t see much:</p>
<p><a href="http://www.olivetalks.com/wp-content/uploads/2009/02/ups-status-selinux-not-configured.png"></a></p>
<p style="text-align: center"><a href="http://www.olivetalks.com/wp-content/uploads/2009/02/ups-status-selinux-not-configured.png"><img src="http://www.olivetalks.com/wp-content/uploads/2009/02/ups-status-selinux-not-configured-small.jpg" title="UPS status in web browser before installing SELinux policy module" alt="UPS status in web browser before installing SELinux policy module" /></a></p>
<p>The reason for this is a missing SELinux policy module. Because of that you&#8217;ll see errors in <em>/var/log/audit/audit.log</em> and the web page won&#8217;t provide any useful information. How to install the missing SELinux policy module? This will be described in the <a href="/2009/02/21/ups-on-centos-with-selinux-part-2/" title="Setting up UPS on CentOS 5.2 with SELinux, part 2">follow up post</a> coming soon.</p>
<h3>Related post(s)</h3><ul class="related_post"><li><a href="http://www.olivetalks.com/2009/02/21/ups-on-centos-with-selinux-part-2/" title="Setting up UPS on CentOS 5.2 with SELinux, part 2">Setting up UPS on CentOS 5.2 with SELinux, part 2 (1)</a></li><li><a href="http://www.olivetalks.com/2009/06/24/skype-40-for-windows-is-out-pros-and-cons-compared-with-linux-skype-20/" title="Skype 4.0 for Windows is out: Pros and cons (compared with Linux Skype 2.0) ">Skype 4.0 for Windows is out: Pros and cons (compared with Linux Skype 2.0)  (1)</a></li><li><a href="http://www.olivetalks.com/2009/02/17/big-eee/" title="Eee PC 901 &#8211; aka Big Eee">Eee PC 901 &#8211; aka Big Eee (0)</a></li><li><a href="http://www.olivetalks.com/2009/02/15/find-changes-with-rpm-verify/" title="What files did I change?">What files did I change? (2)</a></li><li><a href="http://www.olivetalks.com/2008/06/17/too-much-success-and-popularity/" title="Too much success and popularity?">Too much success and popularity? (0)</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.olivetalks.com/2009/02/19/ups-on-centos-with-selinux-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
