<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Selinux on Major Hayden</title><link>https://major.io/tags/selinux/</link><description>Recent content in Selinux on Major Hayden</description><generator>Hugo</generator><language>en</language><managingEditor>major@mhtx.net (Major Hayden)</managingEditor><webMaster>major@mhtx.net (Major Hayden)</webMaster><copyright>All content licensed &lt;a href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;CC BY-SA 4.0&lt;/a&gt;</copyright><lastBuildDate>Wed, 05 Aug 2026 12:23:48 -0500</lastBuildDate><atom:link href="https://major.io/tags/selinux/index.xml" rel="self" type="application/rss+xml"/><item><title>What I learned while securing Ubuntu</title><link>https://major.io/p/what-i-learned-while-securing-ubuntu/</link><pubDate>Wed, 14 Oct 2015 20:53:12 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/what-i-learned-while-securing-ubuntu/</guid><description>&lt;p&gt;The blog posts have slowed down a bit lately because I&amp;rsquo;ve been heads down on a security project at work. I&amp;rsquo;m working with people in the OpenStack community to create a new Ansible role called &lt;a href="http://specs.openstack.org/openstack/openstack-ansible-specs/specs/mitaka/security-hardening.html"&gt;openstack-ansible-security&lt;/a&gt;. The role aims to improve host security by using hardening standards to improve the configuration of various parts of the operating system.&lt;/p&gt;
&lt;p&gt;This means applying security hardening to Ubuntu 14.04 systems since that&amp;rsquo;s the only host operating system supported by &lt;a href="https://github.com/openstack/openstack-ansible"&gt;openstack-ansible&lt;/a&gt; at the moment. I have plenty of experience with securing Red Hat-based systems like Red Hat Enteprise Linux, CentOS and Fedora; but Ubuntu is new territory entirely. The rest of this post is full of lessons learned along the way.&lt;/p&gt;
&lt;h2 id="searching-for-hardening-standards"&gt;Searching for hardening standards&lt;/h2&gt;
&lt;p&gt;Finding a complete hardening standard for Ubuntu 14.04 is challenging. The &lt;a href="http://www.cisecurity.org/"&gt;Center for Internet Security&lt;/a&gt; offers &lt;a href="https://benchmarks.cisecurity.org/downloads/browse/?category=benchmarks.os.linux.ubuntu"&gt;Ubuntu security benchmarks&lt;/a&gt; with two big caveats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;There are very few controls to apply (relative to what&amp;rsquo;s available for RHEL)&lt;/li&gt;
&lt;li&gt;The terms of use are highly restrictive (no derivative works allowed)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With that idea off the table, I examined the other options that meet Requirement 2.2 of PCI-DSS 3.1 &lt;a href="https://www.pcisecuritystandards.org/documents/PCI_DSS_v3-1.pdf"&gt;[PDF]&lt;/a&gt;. Anther choice was &lt;a href="https://en.wikipedia.org/wiki/ISO/IEC_27002"&gt;ISO 27002&lt;/a&gt;, but it&amp;rsquo;s not terribly specific or easy to automate with scripts. The same goes for &lt;a href="https://en.wikipedia.org/wiki/NIST_Special_Publication_800-53"&gt;NIST 800-53&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After plenty of searching, the decision was made to go forth with the &lt;a href="https://public.cyber.mil/stigs/"&gt;Security Technical Implementation Guide (STIG)&lt;/a&gt; from the &lt;a href="http://www.disa.mil/"&gt;Defense Information Systems Agency (DISA)&lt;/a&gt; (part of the US Department of Defense). The STIGs aren&amp;rsquo;t licensed and they&amp;rsquo;re in the public domain. The only downside is that the closest STIG for use with Ubuntu 14.04 is the &lt;a href="https://www.stigviewer.com/stig/red_hat_enterprise_linux_6/"&gt;RHEL 6 STIG&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Using the RHEL 6 STIG meant that plenty of things will need to be translated for the different tools, configuration files, and package names that come with Ubuntu. It was frustrating to search all over for a hardening standard that applies well to Ubuntu and comes with decent auditing tools, but this was the best we could find.&lt;/p&gt;
&lt;h2 id="automatically-starting-daemons"&gt;Automatically starting daemons&lt;/h2&gt;
&lt;p&gt;The standard Ubuntu and Debian practice of automatically starting daemons has &lt;a href="https://major.io/2014/06/26/install-debian-packages-without-starting-daemons/"&gt;perplexed me before&lt;/a&gt; and it still continues to do so. Starting a daemon before I&amp;rsquo;ve had a chance to configure it makes little sense. The main argument is that the daemons come up with a highly secure configuration, so starting it automatically shouldn&amp;rsquo;t be a big deal. I&amp;rsquo;d prefer to install a package, have a look at the configuration, alter the configuration, and then start the daemon. Also, it had better not start after a reboot unless I explicitly ask it to do so.&lt;/p&gt;
&lt;p&gt;There are plenty of examples where automatically starting a daemon with its default configuration is a bad idea. Take the postfix package as an example. If you install the package in non-interactive mode (as Ansible does by default), postfix will come online wth the following configuration option set:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;inet_interfaces = all
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Since Ubuntu doesn&amp;rsquo;t come with a firewall enabled by default, your postfix server is listening on all interfaces for mail immediately. The &lt;code&gt;mynetworks&lt;/code&gt; configuration should prevent relaying, but any potential vulnerabilities in your postfix daemon are exposed to the network without your consent. I would prefer to configure postfix first before I ever allow it to run on my server.&lt;/p&gt;
&lt;h2 id="verifying-packages"&gt;Verifying packages&lt;/h2&gt;
&lt;p&gt;Say what you will about RPM packages and the &lt;code&gt;rpm&lt;/code&gt; command, but the verification portions of the &lt;code&gt;rpm&lt;/code&gt; command are quite helpful. Here&amp;rsquo;s an example of verifying the aide RPM in Fedora:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# rpm -Vv aide
......... c /etc/aide.conf
......... c /etc/logrotate.d/aide
......... /usr/sbin/aide
......... /usr/share/doc/aide
......... d /usr/share/doc/aide/AUTHORS
......... d /usr/share/doc/aide/COPYING
......... d /usr/share/doc/aide/ChangeLog
......... d /usr/share/doc/aide/NEWS
......... d /usr/share/doc/aide/README
......... d /usr/share/doc/aide/README.quickstart
......... /usr/share/doc/aide/contrib
......... d /usr/share/doc/aide/contrib/aide-attributes.sh
......... d /usr/share/doc/aide/contrib/bzip2.sh
......... d /usr/share/doc/aide/contrib/gpg2_check.sh
......... d /usr/share/doc/aide/contrib/gpg2_update.sh
......... d /usr/share/doc/aide/contrib/gpg_check.sh
......... d /usr/share/doc/aide/contrib/gpg_update.sh
......... d /usr/share/doc/aide/contrib/sshaide.sh
......... d /usr/share/doc/aide/manual.html
......... d /usr/share/man/man1/aide.1.gz
......... d /usr/share/man/man5/aide.conf.5.gz
......... /var/lib/aide
......... /var/log/aide
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If the verification finds that nothing in the package has changed, it won&amp;rsquo;t print anything. I&amp;rsquo;ve added the &lt;code&gt;-v&lt;/code&gt; here to ensure that everything is printed to the console. In the output, you can see that everything is checked. That includes configuration files, log directories, libraries, and documentation. If I change the content of the &lt;code&gt;aide.conf&lt;/code&gt; by adding a comment, I see that change:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# echo &amp;#34;# Comment&amp;#34; &amp;gt;&amp;gt; /etc/aide.conf
# rpm -V aide
S.5....T. c /etc/aide.conf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;5&lt;/code&gt; denotes that the MD5 checksum on the file has changed since the package was installed. What happens if I change the owner, group, and mode of the &lt;code&gt;aide.conf&lt;/code&gt;?&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# chown major:major /etc/aide.conf
# rpm -V aide
S.5..UGT. c /etc/aide.conf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now I have a &lt;code&gt;UG&lt;/code&gt; there that denotes a user/group ownership change. Similar messages appear for changes to the permissions on files or directories. The &lt;code&gt;restorecon&lt;/code&gt; command even lets you figure out when SELinux contexts have changed. If you set a file to have the wrong ownership or permission, one &lt;code&gt;rpm&lt;/code&gt; command gets you back to normal:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# rpm --setperms --setugids aide
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;On the Ubuntu side, you can use the &lt;code&gt;debsums&lt;/code&gt; package to help with some verification:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# debsums aide
/usr/bin/aide OK
/usr/share/doc/aide/NEWS.Debian.gz OK
/usr/share/doc/aide/changelog.Debian.gz OK
...
# debums aide-common
/usr/bin/aide-attributes OK
/usr/bin/aide.wrapper OK
/usr/sbin/aideinit OK
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But wait — where are the configuration files? Where are the log and library directories? If you type these commands on an Ubuntu system, you&amp;rsquo;ll see that the configuration files and directories aren&amp;rsquo;t checked. In addition, there&amp;rsquo;s not a method for querying whether a particular file in a package has changed ownership or has had its mode changed. There&amp;rsquo;s also no option to restore the right permissions and ownership after an errant &lt;code&gt;chown -R&lt;/code&gt; or &lt;code&gt;chmod -R&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="managing-aide"&gt;Managing AIDE&lt;/h2&gt;
&lt;p&gt;The &lt;a href="http://aide.sourceforge.net/"&gt;AIDE&lt;/a&gt; package is critical for secure deployments since it helps administrators monitor for file integrity on a regular basis. However, Ubuntu ships with some interesting configuration files and wrappers for AIDE.&lt;/p&gt;
&lt;p&gt;One of the unique configuration files is this one:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# cat /etc/aide/aide.conf.d/99_aide_root
/ Full
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This causes AIDE to wander all over the system, indexing all types of files. It&amp;rsquo;s best to limit AIDE to a small number of directories whenever possible so that the AIDE runs complete quickly and the database file remains relatively small. Plenty of disk I/O can be used during AIDE runs, so it&amp;rsquo;s best to limit the scope.&lt;/p&gt;
&lt;p&gt;Also, trying to initialize the database provides an unhelpful error:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# aide --init
Couldn&amp;#39;t open file /var/lib/aide/please-dont-call-aide-without-parameters/aide.db.new for writing
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That path doesn&amp;rsquo;t exist, and I&amp;rsquo;m confused because I did pass a parameter to &lt;code&gt;aide&lt;/code&gt;. Long story short, you must use the &lt;code&gt;aideinit&lt;/code&gt; command to initialize the aide database. That&amp;rsquo;s actually a bash script which then calls on &lt;code&gt;aide.wrapper&lt;/code&gt; (another bash script) to actually run the &lt;code&gt;aide&lt;/code&gt; binary for you. Better yet, &lt;code&gt;aideinit&lt;/code&gt; is in &lt;code&gt;/usr/sbin&lt;/code&gt; while &lt;code&gt;aide.wrapper&lt;/code&gt; is in &lt;code&gt;/usr/bin&lt;/code&gt;. This leads to plenty of confusion.&lt;/p&gt;
&lt;h2 id="linux-security-modules"&gt;Linux Security Modules&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s possible to run SELinux on Ubuntu, but the policies aren&amp;rsquo;t as well maintained as they are on other distributions. AppArmor is the recommended LSM on Ubuntu, but it doesn&amp;rsquo;t provide the granularity of SELinux. For example, SELinux confines almost every single process on a minimal Fedora system, but AppArmor confines almost nothing on a minimal Ubuntu-based system. AppArmor policies aren&amp;rsquo;t terribly restrictive and it&amp;rsquo;s possible to work around them due to their reliance on path names.&lt;/p&gt;
&lt;p&gt;Fortunately, both LSM&amp;rsquo;s provide decent coverage with virtual machines and containers (using libvirt&amp;rsquo;s sVirt capability).&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;The upside is that there is plenty of room for security improvements, especially around usability, in Ubuntu. Ubuntu-centric hardening standards are difficult to find and challenging to apply. Every distribution has its quirks and differences, but it seems like securing Ubuntu comes with more unusual hoops to jump through relative to Red Hat-based distributions, OpenSUSE, and even Arch.&lt;/p&gt;
&lt;p&gt;I plan to open some bugs for some of these smaller issues in the coming days. However, some of the larger philosophical issues (like automatically starting daemons) will be tougher to tackle.&lt;/p&gt;</description></item><item><title>systemd in Fedora 22: Failed to restart service: Access Denied</title><link>https://major.io/p/systemd-in-fedora-22-failed-to-restart-service-access-denied/</link><pubDate>Fri, 18 Sep 2015 19:43:35 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/systemd-in-fedora-22-failed-to-restart-service-access-denied/</guid><description>&lt;p&gt;&lt;a href="https://major.io/wp-content/uploads/2012/01/fedorainfinity.png"&gt;&lt;img src="https://major.io/wp-content/uploads/2012/01/fedorainfinity.png" alt="Fedora Infinity Logo" width="105" height="102" class="alignright size-full wp-image-2712" /&gt;&lt;/a&gt;If you&amp;rsquo;re running Fedora 22 and you&amp;rsquo;ve recently updated to &lt;a href="https://bodhi.fedoraproject.org/updates/FEDORA-2015-15821"&gt;systemd-219-24.fc22&lt;/a&gt;, you might see errors like these:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# systemctl restart postfix
Failed to restart postfix.service: Access denied
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Your audit logs will have entries like these:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;type=USER_AVC msg=audit(1442602150.292:763): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=&amp;#39;avc: denied { start } for auid=n/a uid=0 gid=0 path=&amp;#34;/run/systemd/system/session-4.scope&amp;#34; cmdline=&amp;#34;/usr/lib/systemd/systemd-logind&amp;#34; scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:object_r:systemd_unit_file_t:s0 tclass=service exe=&amp;#34;/usr/lib/systemd/systemd&amp;#34; sauid=0 hostname=? addr=? terminal=?&amp;#39;
type=USER_AVC msg=audit(1442602150.437:768): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=&amp;#39;avc: denied { start } for auid=n/a uid=0 gid=0 path=&amp;#34;/usr/lib/systemd/system/user@.service&amp;#34; cmdline=&amp;#34;/usr/lib/systemd/systemd-logind&amp;#34; scontext=system_u:system_r:systemd_logind_t:s0 tcontext=system_u:object_r:systemd_unit_file_t:s0 tclass=service exe=&amp;#34;/usr/lib/systemd/systemd&amp;#34; sauid=0 hostname=? addr=? terminal=?&amp;#39;
type=USER_AVC msg=audit(1442602150.440:769): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg=&amp;#39;avc: denied { start } for auid=n/a uid=0 gid=0 path=&amp;#34;/run/systemd/system/session-4.scope&amp;#34; cmdline=&amp;#34;/usr/lib/systemd/systemd-logind&amp;#34; scontext=system_u:system_r:systemd_logind_t:s0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There&amp;rsquo;s a &lt;a href="https://bugzilla.redhat.com/show_bug.cgi?id=1224211"&gt;very active bug&lt;/a&gt; under review to get it fixed. As a workaround, you can re-execute systemd with the following command:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;systemctl daemon-reexec
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That should allow you to stop, start, and restart services properly again. Also, you&amp;rsquo;ll be able to switch runlevels for reboots and shutdowns.&lt;/p&gt;
&lt;p&gt;Keep an eye on the bug for more details as they develop. Kudos to &lt;a href="https://fedoraproject.org/wiki/User:Kevin"&gt;Kevin Fenzi&lt;/a&gt; for the workaround!&lt;/p&gt;</description></item><item><title>Chronicles of SELinux: Dealing with web content in unusual directories</title><link>https://major.io/p/chronicles-of-selinux-dealing-with-web-content-in-unusual-directories/</link><pubDate>Thu, 10 Sep 2015 13:40:35 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/chronicles-of-selinux-dealing-with-web-content-in-unusual-directories/</guid><description>&lt;p&gt;&lt;img src="https://major.io/wp-content/uploads/2013/07/selinux-penguin-new_medium.png" alt="1"&gt;&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve decided to start a series of posts called &amp;ldquo;Chronicles of SELinux&amp;rdquo; where I hope to educate more users on how to handle SELinux denials with finesse rather than simply &lt;a href="http://stopdisablingselinux.com/"&gt;disabling it entirely&lt;/a&gt;. To kick things off, I&amp;rsquo;ll be talking about dealing with web content in the first post.&lt;/p&gt;
&lt;h2 id="first-steps"&gt;First steps&lt;/h2&gt;
&lt;p&gt;If you&amp;rsquo;d like to follow along, simply hop onto a system running Fedora 21 (or later), CentOS 7 or Red Hat Enterprise Linux 7. We need SELinux in enforcing mode on the host, so be sure to check the status with &lt;code&gt;getenforce&lt;/code&gt;. Depending on what &lt;code&gt;getenforce&lt;/code&gt; returns, you&amp;rsquo;ll need to make adjustments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Enforcing&lt;/em&gt;: No adjustments needed - you&amp;rsquo;re all set!&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Permissive&lt;/em&gt;: Run &lt;code&gt;setenforce 1&lt;/code&gt; and adjust SELinux configuration file (see below)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Disabled&lt;/em&gt;: Adjust the SELinux configuration file and reboot (see below)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To enable enforcing mode in the SELinux configuration file, edit &lt;code&gt;/etc/selinux/config&lt;/code&gt; and ensure your &lt;code&gt;SELINUX&lt;/code&gt; line has &lt;code&gt;enforcing&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If &lt;code&gt;getenforce&lt;/code&gt; returned &lt;em&gt;Disabled&lt;/em&gt; earlier, you will need to reboot to get SELinux working. Also be sure that the &lt;code&gt;selinux-policy-targeted&lt;/code&gt; package is installed and run &lt;code&gt;fixfiles onboot -B&lt;/code&gt; to relabel the system on reboot &lt;em&gt;(&lt;a href="#comment-2246455243"&gt;thanks to immanetize for the comment&lt;/a&gt;)&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s install httpd and create a developer user:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# For Fedora
dnf -y install httpd
# For CentOS/RHEL
yum -y install httpd

useradd developer
systemctl enable httpd
systemctl start httpd
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;On to the guide!&lt;/p&gt;
&lt;h2 id="hosting-content-in-an-unique-directory"&gt;Hosting content in an unique directory&lt;/h2&gt;
&lt;p&gt;On Red Hat-based systems, httpd expects to find its content in &lt;code&gt;/var/www/html&lt;/code&gt;, but some system administrators prefer to have content stored elsewhere on the system. It could be on a SAN or other remote storage, but it could also just be in a different directory to make things easier for the business.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s consider a situation where the web content is hosted from &lt;code&gt;/web/&lt;/code&gt;. We can create the directory:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[root@fedora22 ~]# mkdir -v /web
mkdir: created directory &amp;#39;/web&amp;#39;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can edit &lt;code&gt;/etc/httpd/conf/httpd.conf&lt;/code&gt; and set our new &lt;code&gt;DocumentRoot&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot &amp;#34;/web&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&amp;rsquo;s reload the httpd configuration:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;systemctl reload httpd
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And now we can add some amazing web content:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; /web/index.html
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It&amp;rsquo;s time to test our web server:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# curl -i localhost/index.html
HTTP/1.1 403 Forbidden
Date: Thu, 10 Sep 2015 12:54:19 GMT
Server: Apache/2.4.16 (Fedora)
Content-Length: 219
Content-Type: text/html; charset=iso-8859-1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Oh, come on. What&amp;rsquo;s with this 403 error?&lt;/p&gt;
&lt;h2 id="investigating-the-403"&gt;Investigating the 403&lt;/h2&gt;
&lt;p&gt;The first step for any situation like this is to review some logs. Let&amp;rsquo;s check the logs for httpd:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[Thu Sep 10 12:55:04.541789 2015] [core:error] [pid 16597] (13)Permission denied: [client ::1:49860] AH00035: access to /index.html denied (filesystem path &amp;#39;/web/index.html&amp;#39;) because search permissions are missing on a component of the path
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Search permissions are missing? What? Let&amp;rsquo;s check the permissions on our web directory:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ls -al /web
total 12
drwxr-xr-x. 2 root root 4096 Sep 10 12:53 .
dr-xr-xr-x. 19 root root 4096 Sep 10 12:51 ..
-rw-r--r--. 1 root root 21 Sep 10 12:54 index.html
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The httpd user has the ability to get into the directory (&lt;code&gt;o+x&lt;/code&gt; is set on &lt;code&gt;/web/&lt;/code&gt;) and the httpd user can read the file (&lt;code&gt;o+r&lt;/code&gt; is set on &lt;code&gt;/web/index.html&lt;/code&gt;). Let&amp;rsquo;s check the system journal just in case:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# journalctl -n 1 | tail
-- Logs begin at Thu 2015-09-10 12:31:37 UTC, end at Thu 2015-09-10 12:55:04 UTC. --
Sep 10 12:55:04 fedora22 audit[16597]: &amp;lt;audit-1400&amp;gt; avc: denied { getattr } for pid=16597 comm=&amp;#34;httpd&amp;#34; path=&amp;#34;/web/index.html&amp;#34; dev=&amp;#34;xvda1&amp;#34; ino=524290 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s quite a long log line. Let&amp;rsquo;s break it into pieces:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;avc: denied { getattr } for pid=16597 comm=&amp;quot;httpd&amp;quot;&lt;/code&gt;: httpd tried to do something and was denied&lt;/li&gt;
&lt;li&gt;&lt;code&gt;path=&amp;quot;/web/index.html&amp;quot; dev=&amp;quot;xvda1&amp;quot; ino=524290&lt;/code&gt;: path to the file (index.html) involved in the denial&lt;/li&gt;
&lt;li&gt;&lt;code&gt;scontext=system_u:system_r:httpd_t:s0&lt;/code&gt;: the SELinux context of the httpd process&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tcontext=unconfined_u:object_r:default_t:s0&lt;/code&gt;: the SELinux contect that is actually applied to our index.html&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tclass=file&lt;/code&gt;: the denial came from accessing a file (index.html)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;permissive=0&lt;/code&gt;: we&amp;rsquo;re in enforcing mode, not permissive mode&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Long story short, when httpd tried to access our &lt;code&gt;/web/index.html&lt;/code&gt; file, the httpd process was labeled with &lt;code&gt;httpd_t&lt;/code&gt;, but the kernel found that the HTML file was labeled with &lt;code&gt;default_t&lt;/code&gt;. The httpd process (labeled with &lt;code&gt;httpd_t&lt;/code&gt;) isn&amp;rsquo;t allowed to read files that are labeled as &lt;code&gt;default_t&lt;/code&gt;, so the access is denied.&lt;/p&gt;
&lt;h2 id="fixing-it-the-right-way"&gt;Fixing it the right way&lt;/h2&gt;
&lt;p&gt;Since we know what SELinux expects for this file (from the log line in the journal), we can apply the right context and re-test. The &lt;code&gt;chcon&lt;/code&gt; command has a handy argument that allows you to reference a file or directory, and apply the contexts from there. Since we know that &lt;code&gt;/var/www/html&lt;/code&gt; has the right contexts already, we can use it as a reference:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# chcon -v -R --reference=/var/www/html /web
changing security context of &amp;#39;/web/index.html&amp;#39;
changing security context of &amp;#39;/web&amp;#39;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we see some different contexts on &lt;code&gt;/web&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ls -alZ /web/
total 12
drwxr-xr-x. 2 root root system_u:object_r:httpd_sys_content_t:s0 4096 Sep 10 13:19 .
dr-xr-xr-x. 19 root root system_u:object_r:root_t:s0 4096 Sep 10 13:19 ..
-rw-r--r--. 1 root root system_u:object_r:httpd_sys_content_t:s0 21 Sep 10 13:19 index.html
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&amp;rsquo;s test again:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# curl -I localhost/index.html
HTTP/1.1 403 Forbidden
Date: Thu, 10 Sep 2015 13:21:22 GMT
Server: Apache/2.4.16 (Fedora)
Content-Type: text/html; charset=iso-8859-1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Darn! What&amp;rsquo;s in the httpd logs?&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[Thu Sep 10 13:21:22.267719 2015] [authz_core:error] [pid 16593] [client ::1:49861] AH01630: client denied by server configuration: /web/index.html
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ah, we cleared the SELinux problem but now httpd is upset. Just below the &lt;code&gt;DocumentRoot&lt;/code&gt; line that we edited earlier, look for two &lt;code&gt;Directory&lt;/code&gt; blocks. Change &lt;code&gt;/var/www/&lt;/code&gt; and &lt;code&gt;/var/www/html&lt;/code&gt; to &lt;code&gt;/web&lt;/code&gt; in those blocks. Reload the httpd configuration and try once more:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# systemctl reload httpd
# curl -I localhost/index.html
HTTP/1.1 200 OK
Date: Thu, 10 Sep 2015 13:25:16 GMT
Server: Apache/2.4.16 (Fedora)
Last-Modified: Thu, 10 Sep 2015 13:19:47 GMT
ETag: &amp;#34;15-51f6474064d50&amp;#34;
Accept-Ranges: bytes
Content-Length: 21
Content-Type: text/html; charset=UTF-8
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Success!&lt;/p&gt;
&lt;h2 id="long-term-fix"&gt;Long term fix&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;chcon&lt;/code&gt; method is good for fixing one-off issues and for testing, but we need a good long term fix. SELinux has some file contexts already configured for certain directories, but not for our custom web directory. You can examine the defaults here:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# semanage fcontext -l | grep ^/var/www/html
/var/www/html(/.*)?/sites/default/files(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/sites/default/settings\.php regular file system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/uploads(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html(/.*)?/wp-content(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html/[^/]*/cgi-bin(/.*)? all files system_u:object_r:httpd_sys_script_exec_t:s0
/var/www/html/cgi/munin.* all files system_u:object_r:munin_script_exec_t:s0
/var/www/html/configuration\.php all files system_u:object_r:httpd_sys_rw_content_t:s0
/var/www/html/munin(/.*)? all files system_u:object_r:munin_content_t:s0
/var/www/html/munin/cgi(/.*)? all files system_u:object_r:munin_script_exec_t:s0
/var/www/html/owncloud/data(/.*)? all files system_u:object_r:httpd_sys_rw_content_t:s0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;SELinux&amp;rsquo;s tools have a concept of &lt;em&gt;equivalency&lt;/em&gt;. This allows you to say that one directory is &lt;em&gt;equivalent&lt;/em&gt; to another one in the long term. We already used &lt;code&gt;chcon&lt;/code&gt; to apply contexts with a reference to a directory with valid contexts, but this equivalency concept gives us a longer term fix. Here&amp;rsquo;s the command to use:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;semanage fcontext --add --equal /var/www /web
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If we break this down, we&amp;rsquo;re saying we want to add a new file context where &lt;code&gt;/web&lt;/code&gt; is equal to &lt;code&gt;/var/www&lt;/code&gt;. This means we want the same SELinux contexts applied in the same places and want them treated equally. After running the &lt;code&gt;semanage&lt;/code&gt; command, let&amp;rsquo;s make an &lt;code&gt;index2.html&lt;/code&gt; file to test:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; /web/index2.html
# curl -I localhost/index2.html
HTTP/1.1 200 OK
Date: Thu, 10 Sep 2015 13:35:24 GMT
Server: Apache/2.4.16 (Fedora)
Last-Modified: Thu, 10 Sep 2015 13:34:11 GMT
ETag: &amp;#34;15-51f64a78266c8&amp;#34;
Accept-Ranges: bytes
Content-Length: 21
Content-Type: text/html; charset=UTF-8
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Great! We didn&amp;rsquo;t have to use &lt;code&gt;chcon&lt;/code&gt; this time around because we configured &lt;code&gt;/web&lt;/code&gt; as an equivalent directory to &lt;code&gt;/var/www&lt;/code&gt;. Let&amp;rsquo;s double check the contexts:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ls -alZ /web
total 16
drwxr-xr-x. 2 root root unconfined_u:object_r:httpd_sys_content_t:s0 4096 Sep 10 13:34 .
dr-xr-xr-x. 19 root root system_u:object_r:root_t:s0 4096 Sep 10 13:33 ..
-rw-r--r--. 1 root root unconfined_u:object_r:httpd_sys_content_t:s0 21 Sep 10 13:34 index2.html
-rw-r--r--. 1 root root unconfined_u:object_r:httpd_sys_content_t:s0 21 Sep 10 13:33 index.html
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Perfect! We now have all of the security benefits of SELinux in a completely custom web directory.&lt;/p&gt;</description></item><item><title>AVC: denied dyntransition from sshd</title><link>https://major.io/p/avc-denied-dyntransition-from-sshd/</link><pubDate>Thu, 03 Jul 2014 19:52:51 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/avc-denied-dyntransition-from-sshd/</guid><description>&lt;p&gt;I&amp;rsquo;ve been working with some Fedora environments in chroots and I ran into a peculiar SELinux AVC denial a short while ago:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;avc: denied { dyntransition } for pid=809 comm=&amp;#34;sshd&amp;#34; scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:system_r:sshd_net_t:s0 tclass=process
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The ssh daemon is running on a non-standard port but I verified that the port is allowed with &lt;code&gt;semanage port -l&lt;/code&gt;. The target context of &lt;em&gt;sshd_net_t&lt;/em&gt; from the AVC seems sensible for the ssh daemon. I started to wonder if a context wasn&amp;rsquo;t applied correctly to the sshd excutable itself, so I checked within the chroot:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ls -alZ /usr/sbin/sshd
-rwxr-xr-x. 1 root root system_u:object_r:sshd_exec_t:SystemLow 652816 May 15 03:56 /usr/sbin/sshd
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s what it should be. I double-checked my running server (which booted a squashfs containing the chroot) and saw something wrong:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ls -alZ /usr/sbin/sshd
-rwxr-xr-x. root root system_u:object_r:file_t:s0 /usr/sbin/sshd
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;How did &lt;em&gt;file_t&lt;/em&gt; get there? It turns out that I was using rsync to drag data out of the chroot and I forgot to use the &lt;code&gt;--xattrs&lt;/code&gt; argument with rsync.&lt;/p&gt;</description></item><item><title>Fixing broken DNS lookups in spamassassin</title><link>https://major.io/p/fixing-broken-dns-lookups-in-spamassassin/</link><pubDate>Fri, 20 Jun 2014 13:20:56 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/fixing-broken-dns-lookups-in-spamassassin/</guid><description>&lt;p&gt;I talked about the &lt;a href="https://twitter.com/majorhayden/status/479250665311457281"&gt;joys of running my own mail server&lt;/a&gt; last week only to find that my mail server was broken yesterday. Spamassassin stopped doing DNS lookups for &lt;a href="https://en.wikipedia.org/wiki/DNSBL"&gt;RBL&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Sender_Policy_Framework"&gt;SPF&lt;/a&gt; checks.&lt;/p&gt;
&lt;p&gt;I had one of these moments:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://major.io/wp-content/uploads/2014/06/neil_patrick_harris_sigh.gif"&gt;&lt;img src="https://major.io/wp-content/uploads/2014/06/neil_patrick_harris_sigh.gif" alt="Neil Patrick Harris Sigh" width="500" height="233" class="aligncenter size-full wp-image-4968" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;My logs looked like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;plugin: eval failed: available_nameservers: No DNS servers available!
plugin: eval failed: available_nameservers: No DNS servers available!
rules: failed to run NO_DNS_FOR_FROM RBL test, skipping:
 (available_nameservers: [...] No DNS servers available!)
 (available_nameservers: [...] No DNS servers available!
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;My /etc/resolv.conf was correct and had two valid DNS servers listed. Also, the permissions set on /etc/resolv.conf were reasonable (0644) and the SELinux context applied to the file was appropriate (net_conf_t). Everything else on the system was able to resolve DNS records properly. Even an strace on the spamd process showed it reading /etc/resolv.conf successfully!&lt;/p&gt;
&lt;p&gt;It was Google time. I put some snippets of my error output into the search bar and found a &lt;a href="https://issues.apache.org/SpamAssassin/show_bug.cgi?id=7057"&gt;spamassassin bug report&lt;/a&gt;. Mark Martinec found the root cause of the bug:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Net::DNS version 0.76 changed the field name holding a set of nameservers in a Net::DNS::Resolver object: it used to be &amp;rsquo;nameservers&amp;rsquo;, but is now split into two fields: &amp;rsquo;nameserver4&amp;rsquo; and &amp;rsquo;nameserver6'.&lt;/p&gt;
&lt;p&gt;Mail/SpamAssassin/DnsResolver.pm relied on the internal field name of a Net::DNS::Resolver object to obtain a default list of recursive name servers, so the change in Net::DNS broke that.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The &lt;a href="https://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm?r1=1603518&amp;amp;r2=1603517&amp;amp;pathrev=1603518"&gt;patch from the bug report&lt;/a&gt; worked just fine on my Fedora 20 mail server. Be sure to restart spamd after making the change.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a &lt;a href="https://bugzilla.redhat.com/show_bug.cgi?id=1111586"&gt;Fedora bug report&lt;/a&gt; as well.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If anyone is interested, I plan to write up my email configuration on Fedora soon for other folks to use. I might even make some ansible playbooks for it. ;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Fedora update: Fedora&amp;rsquo;s spamassassin package has been updated to 3.4.0-7 and it fixes two bugs. You&amp;rsquo;ll find it in the stable repositories in a few days.&lt;/em&gt;&lt;/p&gt;</description></item><item><title>Text missing in chrome on Linux</title><link>https://major.io/p/text-missing-in-chrome-on-linux/</link><pubDate>Sun, 18 May 2014 04:33:14 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/text-missing-in-chrome-on-linux/</guid><description>&lt;p&gt;I&amp;rsquo;m in the process of trying Fedora 20 on my retina MacBook and I ran into a peculiar issue with Chrome. Some sites would load up normally and I could read everything on the page. Other sites would load up and only some of the text would be displayed. Images were totally unaffected.&lt;/p&gt;
&lt;p&gt;It wasn&amp;rsquo;t this way on the initial installation of Fedora but it cropped up somewhere along the way as I installed software. Changing the configuration within Chrome wasn&amp;rsquo;t an option - I couldn&amp;rsquo;t even see any text on the configuration pages!&lt;/p&gt;
&lt;p&gt;The only commonality I could find is that all pages that specified their own web fonts (like the pages on this site) loaded up perfectly. Everything was visible. However, on sites that tend to use whatever font is available in the browser (sites that specify a font family), the text was missing. A good example was &lt;a href="http://avherald.com/"&gt;The Aviation Herald&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I remembered installing some Microsoft core fonts via &lt;a href="https://satya164.github.io/fedy/"&gt;Fedy&lt;/a&gt; and I added in some patched powerline fonts to work with tmux. A quick check of the SELinux troubleshooter alerted me to the problem: the new fonts had the wrong SELinux labels applied and Chrome wasn&amp;rsquo;t allowed to access them.&lt;/p&gt;
&lt;p&gt;I decided to relabel the whole filesystem:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;restorecon -Rv /
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The restorecon output was line after line of fonts that I had installed earlier in the evening. Once it finished running, I started Chrome and it was working just as I had expected.&lt;/p&gt;</description></item><item><title>Launch secure LXC containers on Fedora 20 using SELinux and sVirt</title><link>https://major.io/p/launch-secure-lxc-containers-on-fedora-20-using-selinux-and-svirt/</link><pubDate>Tue, 22 Apr 2014 04:11:00 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/launch-secure-lxc-containers-on-fedora-20-using-selinux-and-svirt/</guid><description>&lt;p&gt;&lt;img src="https://major.io/wp-content/uploads/2013/07/selinux-penguin-new_medium.png" alt="1"&gt;&lt;/p&gt;
&lt;p&gt;Getting started with &lt;a href="https://en.wikipedia.org/wiki/LXC"&gt;LXC&lt;/a&gt; is a bit awkward and I&amp;rsquo;ve assembled this guide for anyone who wants to begin experimenting with LXC containers in Fedora 20. As an added benefit, you can follow almost every step shown here when creating LXC containers on &lt;a href="https://access.redhat.com/site/products/Red_Hat_Enterprise_Linux/Get-Beta"&gt;Red Hat Enterprise Linux 7&lt;/a&gt; Beta (which is based on Fedora 19).&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll need a physical machine or a VM running Fedora 20 to get started. &lt;span style="color: #888888"&gt;(You could put a container in a container, but things get a little dicey with that setup. Let&amp;rsquo;s just avoid talking about nested containers for now. No, really, I shouldn&amp;rsquo;t have even brought it up. Sorry about that.)&lt;/span&gt;&lt;/p&gt;
&lt;h3 id="prep-work"&gt;Prep Work&lt;/h3&gt;
&lt;p&gt;Start by updating all packages to the latest versions available:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y upgrade
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Verify that SELinux is in enforcing mode by running &lt;code&gt;getenforce&lt;/code&gt;. If you see &lt;em&gt;Disabled&lt;/em&gt; or &lt;em&gt;Permissive&lt;/em&gt;, get SELinux into enforcing mode with a quick configuration change:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sed -i &amp;#39;s/^SELINUX=.*/SELINUX=enforcing/&amp;#39; /etc/selinux/config
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I recommend installing &lt;code&gt;setroubleshoot-server&lt;/code&gt; to make it easier to find the root cause of AVC denials:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code class="language-yum" data-lang="yum"&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Reboot now. This will ensure that SELinux comes up in enforcing mode (verify that with &lt;code&gt;getenforce&lt;/code&gt; after reboot) and it ensures that auditd starts up sedispatch (for setroubleshoot).&lt;/p&gt;
&lt;h3 id="install-management-libraries-and-utilities"&gt;Install management libraries and utilities&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s grab libvirt along with LXC support and a basic NAT networking configuration.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y install libvirt-daemon-lxc libvirt-daemon-config-network
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Launch libvirtd via systemd and ensure that it always comes up on boot. This step will also adjust firewalld for your containers and ensure that dnsmasq is serving up IP addresses via DHCP on your default NAT network.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;systemctl start libvirtd.service
systemctl enable libvirtd.service
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="bootstrap-our-container"&gt;Bootstrap our container&lt;/h3&gt;
&lt;p&gt;Installing packages into the container&amp;rsquo;s filesystem will take some time.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y --installroot=/var/lib/libvirt/filesystems/fedora20 --releasever=20 --nogpg install systemd passwd yum fedora-release vim-minimal openssh-server procps-ng iproute net-tools dhclient
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This step fills in the filesystem with the necessary packages to run a Fedora 20 container. We now need to tell libvirt about the container we&amp;rsquo;ve just created.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;virt-install --connect lxc:// --name fedora20 --ram 512 --filesystem /var/lib/libvirt/filesystems/fedora20/,/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At this point, libvirt will know enough about the container to start it and you&amp;rsquo;ll be connected to the console of the container! We need to adjust some configuration files within the container to use it properly. Detach from the console with CTRL-].&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s stop the container so we can make some adjustments.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;virsh -c lxc:// shutdown fedora20
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="get-the-container-ready-for-production"&gt;Get the container ready for production&lt;/h3&gt;
&lt;p&gt;Hop into your container and set a root password.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;chroot /var/lib/libvirt/filesystems/fedora20 /bin/passwd root
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We will be logging in as root via the console occasionally and we need to allow that access.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;echo &amp;#34;pts/0&amp;#34; &amp;gt;&amp;gt; /var/lib/libvirt/filesystems/fedora20/etc/securetty
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Since we will be using our NAT network with our auto-configured dnsmasq server (thanks to libvirt), we can configure a simple DHCP setup for eth0:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;cat &amp;lt; &amp;lt; EOF &amp;gt; /var/lib/libvirt/filesystems/fedora20/etc/sysconfig/network
NETWORKING=yes
EOF
cat &amp;lt; &amp;lt; EOF &amp;gt; /var/lib/libvirt/filesystems/fedora20/etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
ONBOOT=yes
DEVICE=eth0
EOF
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using ssh makes the container a lot easier to manage, so let&amp;rsquo;s ensure that it starts when the container boots. (You could do this via systemctl after logging in at the console, but I&amp;rsquo;m lazy.)&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;chroot /var/lib/libvirt/filesystems/fedora20/
ln -s /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/
exit
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="launch"&gt;Launch!&lt;/h3&gt;
&lt;p&gt;Cross your fingers and launch the container.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;virsh -c lxc:// start --console fedora20
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;ll be attached to the console during boot but don&amp;rsquo;t worry, hold down CTRL-] to get back to your host prompt. Check the dnsmasq leases to find your container&amp;rsquo;s IP address and you can login as root over ssh.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;cat /var/lib/libvirt/dnsmasq/default.leases
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="security"&gt;Security&lt;/h3&gt;
&lt;p&gt;After logging into your container via ssh, check the process labels within the container:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ps aufxZ
LABEL USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 1 0.0 1.3 47444 3444 ? Ss 03:18 0:00 /sbin/init
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 18 0.0 2.0 43016 5368 ? Ss 03:18 0:00 /usr/lib/systemd/systemd-journald
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 38 0.4 7.8 223456 20680 ? Ssl 03:18 0:00 /usr/bin/python -Es /usr/sbin/firewalld -
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 40 0.0 0.7 26504 2084 ? Ss 03:18 0:00 /usr/sbin/smartd -n -q never
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 41 0.0 0.4 19268 1252 ? Ss 03:18 0:00 /usr/sbin/irqbalance --foreground
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 44 0.0 0.6 34696 1636 ? Ss 03:18 0:00 /usr/lib/systemd/systemd-logind
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 46 0.0 1.8 267500 4832 ? Ssl 03:18 0:00 /sbin/rsyslogd -n
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 dbus 47 0.0 0.6 26708 1680 ? Ss 03:18 0:00 /bin/dbus-daemon --system --address=syste
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 rpc 54 0.0 0.5 41992 1344 ? Ss 03:18 0:00 /sbin/rpcbind -w
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 55 0.0 0.3 25936 924 ? Ss 03:18 0:00 /usr/sbin/atd -f
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 56 0.0 0.5 22728 1488 ? Ss 03:18 0:00 /usr/sbin/crond -n
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 60 0.0 0.2 6412 784 pts/0 Ss+ 03:18 0:00 /sbin/agetty --noclear -s console 115200
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 74 0.0 3.2 339808 8456 ? Ssl 03:18 0:00 /usr/sbin/NetworkManager --no-daemon
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 394 0.0 5.9 102356 15708 ? S 03:18 0:00 \_ /sbin/dhclient -d -sf /usr/libexec/nm
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 polkitd 83 0.0 4.4 514792 11548 ? Ssl 03:18 0:00 /usr/lib/polkit-1/polkitd --no-debug
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 rpcuser 110 0.0 0.6 46564 1824 ? Ss 03:18 0:00 /sbin/rpc.statd
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 111 0.0 1.3 82980 3620 ? Ss 03:18 0:00 /usr/sbin/sshd -D
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 409 0.0 1.9 131576 5084 ? Ss 03:18 0:00 \_ sshd: root@pts/1
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 413 0.0 0.9 115872 2592 pts/1 Ss 03:18 0:00 \_ -bash
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 438 0.0 0.5 123352 1344 pts/1 R+ 03:19 0:00 \_ ps aufxZ
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 411 0.0 0.8 44376 2252 ? Ss 03:18 0:00 /usr/lib/systemd/systemd --user
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 412 0.0 0.5 66828 1328 ? S 03:18 0:00 \_ (sd-pam)
system_u:system_r:virtd_lxc_t:s0-s0:c0.c1023 root 436 0.0 0.4 21980 1144 ? Ss 03:19 0:00 /usr/lib/systemd/systemd-hostnamed
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;ll notice something interesting if you run &lt;code&gt;getenforce&lt;/code&gt; now within the container — SELinux is disabled. Actually, it&amp;rsquo;s not really disabled. The processing of SELinux policy is done on the host. The container isn&amp;rsquo;t able to see what&amp;rsquo;s going on outside of its own files and processes. The &lt;a href="http://libvirt.org/drvlxc.html#security"&gt;libvirt documentation for LXC&lt;/a&gt; hints at the importance of this isolation:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A suitably configured UID/GID mapping is a pre-requisite to making containers secure, in the absence of sVirt confinement.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;In the absence of the “user” namespace being used, containers cannot be considered secure against exploits of the host OS. The sVirt SELinux driver provides a way to secure containers even when the “user” namespace is not used. The cost is that writing a policy to allow execution of arbitrary OS is not practical. The SELinux sVirt policy is typically tailored to work with an simpler application confinement use case, as provided by the “libvirt-sandbox” project.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This leads to something really critical to understand:&lt;/p&gt;
&lt;h3 id="containers-dont-contain"&gt;Containers don&amp;rsquo;t contain&lt;/h3&gt;
&lt;p&gt;Dan Walsh has a &lt;a href="https://danwalsh.livejournal.com/30565.html"&gt;great post&lt;/a&gt; that goes into the need for sVirt and the protections it can provide when you need to be insulated from potentially dangerous virtual machines or containers. If a user is root inside a container, they&amp;rsquo;re root on the host as well. &lt;span style="color: #888888"&gt;(There&amp;rsquo;s an exception: &lt;a href="https://lwn.net/Articles/436445/"&gt;UID namespaces&lt;/a&gt;. But let&amp;rsquo;s not talk about that now. Oh great, first it was nested containers and now I brought up UID namespaces. Sorry again.)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Dan&amp;rsquo;s talk about securing containers hasn&amp;rsquo;t popped up on the &lt;a href="http://www.redhat.com/summit/2014/presentations/"&gt;Red Hat Summit presentations&lt;/a&gt; page quite yet but here are some notes that I took and then highlighted:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Containers don&amp;rsquo;t contain. The kernel doesn&amp;rsquo;t know about containers. Containers simply use kernel subsystems to carve up namespaces for applications.&lt;/li&gt;
&lt;li&gt;Containers on Linux aren&amp;rsquo;t complete. Don&amp;rsquo;t compare directly to Solaris zones yet.&lt;/li&gt;
&lt;li&gt;Running containers without Mandatory Access Control (MAC) systems like SELinux or AppArmor opens the door for full system compromise via untrusted applications and users within containers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using MAC gives you one extra barrier to keep a malicious container from getting higher levels of access to the underlying host. There&amp;rsquo;s always a chance that a kernel exploit could bypass MAC but it certainly raises the level of difficulty for an attacker and allows server operators extra time to react to alerts.&lt;/p&gt;</description></item><item><title>Confine untrusted users (including your children) with SELinux</title><link>https://major.io/p/confine-untrusted-users-including-your-children-with-selinux/</link><pubDate>Fri, 05 Jul 2013 18:50:43 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/confine-untrusted-users-including-your-children-with-selinux/</guid><description>&lt;p&gt;&lt;a href="https://major.io/wp-content/uploads/2011/09/selinux-penguin-125.png"&gt;&lt;img src="https://major.io/wp-content/uploads/2011/09/selinux-penguin-125.png" alt="SELinux Penguin" width="125" height="113" class="alignright size-full wp-image-2532" /&gt;&lt;/a&gt;The &lt;a href="https://danwalsh.livejournal.com/10461.html?thread=88029"&gt;confined user support in SELinux&lt;/a&gt; is handy for ensuring that users aren&amp;rsquo;t able to do something that they shouldn&amp;rsquo;t. It seems more effective and easier to use than most of the other methods I&amp;rsquo;ve seen before. Thanks to Dan for reminding me about this during his &lt;a href="https://rhsummit.files.wordpress.com/2013/06/summitselinuxenterprise.pdf"&gt;SELinux in the Enterprise&lt;/a&gt; talk from this year&amp;rsquo;s Red Hat Summit.&lt;/p&gt;
&lt;p&gt;There are five main SELinux user types (and a &lt;a href="https://docs.fedoraproject.org/en-US/Fedora/12/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Targeted_Policy-Confined_and_Unconfined_Users.html"&gt;handy chart&lt;/a&gt; in the Fedora documentation):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;guest_u:&lt;/strong&gt; - no X windows, no sudo, and no networking&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;xguest_u:&lt;/strong&gt; - same as guest_u, but X is allowed and connectivity is allowed to web ports only (handy for kiosks)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;user_u:&lt;/strong&gt; - same as xguest_u, but networking isn&amp;rsquo;t restricted&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;staff_u:&lt;/strong&gt; - same as user_u, but sudo is allowed (su isn&amp;rsquo;t allowed)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;unconfined_u:&lt;/strong&gt; - full access (this is the default)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One interesting thing to note is that all users are allowed to execute binary applications within their home directories by default. This can be switch off via some booleans (which I&amp;rsquo;ll demonstrate in a moment).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s kick off a demonstration to show the power of these restrictions. First off, let&amp;rsquo;s get a list of the default configuration:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# semanage login -l

Login Name SELinux User MLS/MCS Range Service

__default__ unconfined_u s0-s0:c0.c1023 *
root unconfined_u s0-s0:c0.c1023 *
system_u system_u s0-s0:c0.c1023 *
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;By default, all new users come with no restrictions (as shown by unconfined_u). I&amp;rsquo;ll create a new user called selinuxtest and set a password. If I ssh to the server as the selinuxtest user, I see that I&amp;rsquo;m unconfined:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s what we expected. Let&amp;rsquo;s apply the strongest restrictions to this user and apply guest_u:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# semanage login -a -s guest_u selinuxtest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I&amp;rsquo;ll start a new ssh session as selinuxtest and try out some commands that I&amp;rsquo;d normally expect to work on a Linux server:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ ping google.com
ping: icmp open socket: Permission denied
$ curl google.com
curl: (7) Failed to connect to 74.125.225.129: Permission denied
$ sudo su -
sudo: unable to change to sudoers gid: Operation not permitted
$ ./hello
Hello world
$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x5ffb25a7171c3338d6c76147cccc666ddc752dde, not stripped
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The networking and sudo restrictions applied as we expected. However, I was able to compile a small &amp;ldquo;Hello World&amp;rdquo; binary in C and run it. That could become a problem for some servers. Let&amp;rsquo;s adjust a boolean that will restrict this activity:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# getsebool -a | grep exec_content
auditadm_exec_content --&amp;gt; on
guest_exec_content --&amp;gt; on
secadm_exec_content --&amp;gt; on
staff_exec_content --&amp;gt; on
sysadm_exec_content --&amp;gt; on
user_exec_content --&amp;gt; on
xguest_exec_content --&amp;gt; on
# setsebool guest_exec_content off
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now I try running the binary again as my selinuxtest user:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ ./hello
-bash: ./hello: Permission denied
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I can&amp;rsquo;t execute binary content in my home directory or in /tmp any longer after adjusting the boolean. Let&amp;rsquo;s switch selinuxtest to xguest_u:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# semanage login -a -s xguest_u selinuxtest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And now I&amp;rsquo;ll re-test as the selinuxtest user:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ curl -si google.com | head -1
HTTP/1.1 301 Moved Permanently
$ ping google.com
ping: icmp open socket: Permission denied
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I have full web connectivity but I can&amp;rsquo;t do anything else on the network. Now for a switch to user_u:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# semanage login -a -s user_u selinuxtest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And testing user_u with selinuxtest reveals:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ ping -c 1 google.com
PING google.com (74.125.225.134) 56(84) bytes of data.
64 bytes from ord08s09-in-f6.1e100.net (74.125.225.134): icmp_seq=1 ttl=57 time=29.3 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 29.332/29.332/29.332/0.000 ms
$ curl -si google.com | head -n1
HTTP/1.1 301 Moved Permanently
$ sudo su -
sudo: PERM_SUDOERS: setresuid(-1, 1, -1): Operation not permitted
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Networking is wide open but I still don&amp;rsquo;t have sudo. Let&amp;rsquo;s try staff_u:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# semanage login -a -s staff_u selinuxtest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Testing staff_u with selinuxtest gives me the expected results:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ sudo su -
[sudo] password for selinuxtest:
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I didn&amp;rsquo;t add selinuxtest to sudoers, so this command would fail. However, I&amp;rsquo;m actually allowed to execute it now.&lt;/p&gt;
&lt;p&gt;These restrictions could be very helpful when dealing with users that you don&amp;rsquo;t fully trust on your system. You could use these restrictions to add a kiosk user to a Linux machine and allow family members or coworkers to surf the web using your device. In addition, you could use the restrictions as an extra layer of protection on heavily shared servers to prevent users from consuming resources or generating malicious traffic.&lt;/p&gt;</description></item><item><title>Installing the Xen hypervisor on Fedora 19</title><link>https://major.io/p/installing-the-xen-hypervisor-on-fedora-19/</link><pubDate>Mon, 03 Jun 2013 04:27:43 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/installing-the-xen-hypervisor-on-fedora-19/</guid><description>&lt;p&gt;It&amp;rsquo;s been a little while &lt;a href="https://major.io/2011/08/05/xen-4-1-on-fedora-15-with-linux-3-0/"&gt;since I last posted about installing Xen on Fedora&lt;/a&gt;, so I figured that Fedora 19&amp;rsquo;s beta release was as good a time as any to write a new post. To get started, you&amp;rsquo;ll need to get Fedora 19 installed on your favorite hardware (or virtual machine).&lt;/p&gt;
&lt;p&gt;Install the Xen hypervisor and tools. Also, ensure that both of the necessary daemons are running on each boot:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y install xen xen-hypervisor xen-libs xen-runtime
chkconfig xend on
chkconfig xendomains on
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;ll notice that I didn&amp;rsquo;t start the daemons quite yet. We will need the xen hypervisor running before they will be of any use.&lt;/p&gt;
&lt;p&gt;Now, let&amp;rsquo;s configure GRUB2. I wrote a &lt;a href="https://major.io/2012/07/16/boot-the-xen-hypervisor-by-default-in-fedora-17-with-grub-2/"&gt;quick post about these steps&lt;/a&gt; last year. The Xen kernel entry should already be configured (by grubby), but it&amp;rsquo;s not the default. Fixing that is a quick process:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# grep ^menuentry /boot/grub2/grub.cfg | cut -d &amp;#34;&amp;#39;&amp;#34; -f2
Fedora, with Linux 3.9.4-300.fc19.x86_64
Fedora, with Linux 0-rescue-4ea51ecfff4f4e64a5ec903c495ee5b6
Fedora, with Xen hypervisor
# grub2-set-default &amp;#39;Fedora, with Xen hypervisor&amp;#39;
# grub2-editenv list
saved_entry=Fedora, with Xen hypervisor
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;At this point, you&amp;rsquo;re ready to reboot. After the reboot, verify that Xen is running:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# xm dmesg | head
 __ __ _ _ ____ ____ ____ __ _ ___
 \ \/ /___ _ __ | || | |___ \ |___ \ | ___| / _| ___/ |/ _ \
 \ // _ \ &amp;#39;_ \ | || |_ __) | __) |_|___ \ | |_ / __| | (_) |
 / \ __/ | | | |__ _| / __/ _ / __/|__|__) || _| (__| |\__, |
 /_/\_\___|_| |_| |_|(_)_____(_)_____| |____(_)_| \___|_| /_/

(XEN) Xen version 4.2.2 (mockbuild@phx2.fedoraproject.org) (gcc (GCC) 4.8.0 20130412 (Red Hat 4.8.0-2)) Fri May 17 19:39:53 UTC 2013
(XEN) Latest ChangeSet: unavailable
(XEN) Bootloader: GRUB 2.00
(XEN) Command line: placeholder
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you&amp;rsquo;re adventurous on the command line, you&amp;rsquo;re done here. However, I enjoy using virt-manager for quick access to virtual machines and I also like all of the scripting and remote administration capabilities that libvirt delivers. Let&amp;rsquo;s get the tools and daemons installed and running:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y install virt-manager dejavu* xorg-x11-xauth
yum -y install libvirt-daemon-driver-network libvirt-daemon-driver-storage libvirt-daemon-xen
chkconfig libvirtd on
service libvirtd start
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;re now ready to use virt-manager to manage your virtual machines. Simply ssh to your hypervisor with X forwarding enabled (&lt;code&gt;ssh -X hypervisor.mydomain.com&lt;/code&gt;) and run &lt;code&gt;virt-manager&lt;/code&gt;. You won&amp;rsquo;t have a virtual network or bridge to use for virtual machines quite yet. You have two options: NAT your VM&amp;rsquo;s or configure a network bridge. I prefer the bridge but you may require something different in your environment.&lt;/p&gt;
&lt;p&gt;For the NAT option (the easiest for beginners):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y install libvirt-daemon-config-network libvirt-daemon-config-nwfilter
service libvirtd restart
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For the network-bridge option, you&amp;rsquo;ll need to adjust your network scripts to create a bridge and add your primary network interface to the bridge. That&amp;rsquo;s a bit outside the scope of this post, but the &lt;a href="http://fedoraproject.org/wiki/Networking/Bridging"&gt;Fedora Wiki&lt;/a&gt; and &lt;a href="http://www.howtoforge.com/virtualization-with-kvm-on-a-fedora-17-server"&gt;HowtoForge&lt;/a&gt; (ignore the KVM parts of their guide).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You now have a working Xen installation on Fedora 19!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong style="color: #D42020;"&gt;FOR THOSE WHO EMBRACE SECURITY:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you run SELinux in Enforcing mode, there&amp;rsquo;s still a lingering issue where SELinux prevents python (running under xend) from talking to block devices (like logical volumes). I &lt;a href="https://bugzilla.redhat.com/show_bug.cgi?id=839287"&gt;opened a bug&lt;/a&gt; about a similar problem before but I need to open another one for the block device issue. If you&amp;rsquo;re itching for a workaround, you can force SELinux into permissive mode for the xend_t context only:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum -y install selinux-policy-devel
semanage permissive -a xend_t
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;rsquo;s not the best option for now, but it&amp;rsquo;s certainly better than &lt;code&gt;setenforce 0&lt;/code&gt;. ;)&lt;/p&gt;</description></item><item><title>Presentation: Demystifying SELinux</title><link>https://major.io/p/presentation-demystifying-selinux/</link><pubDate>Wed, 29 May 2013 01:01:09 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/presentation-demystifying-selinux/</guid><description>&lt;p&gt;While rolling through my RSS feeds, I found a great presentation by David Quigley titled &amp;ldquo;Demystifying SELinux&amp;rdquo;. He makes come good comparisons between discretionary/mandatory access controls and dives into what makes SELinux useful. Basic troubleshooting commands are covered within the presentation as well.&lt;/p&gt;
&lt;p&gt;You can find the presentation over on &lt;a href="https://speakerdeck.com/dpquigl/demystifying-selinux"&gt;Speaker Deck&lt;/a&gt;. I&amp;rsquo;ve also mirrored a &lt;a href="https://major.io/wp-content/uploads/2013/05/demystifying_selinux.pdf"&gt;PDF copy&lt;/a&gt; here on the site.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; If you&amp;rsquo;re going to &lt;a href="https://www.oscon.com/oscon2013"&gt;OSCON 2013&lt;/a&gt; this year, it appears that &lt;a href="https://www.oscon.com/oscon2013/public/schedule/speaker/151833"&gt;David&lt;/a&gt; will be &lt;a href="https://www.oscon.com/oscon2013/public/schedule/detail/29473"&gt;presenting this topic&lt;/a&gt; during the event.&lt;/p&gt;</description></item><item><title>Reprint: Stop Disabling SELinux!</title><link>https://major.io/p/reprint-stop-disabling-selinux/</link><pubDate>Fri, 19 Apr 2013 05:52:23 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/reprint-stop-disabling-selinux/</guid><description>&lt;p&gt;&lt;em&gt;This article appeared in &lt;a href="http://www.scmagazine.com.au/News/340475,stop-disabling-selinux.aspx"&gt;SC Magazine&lt;/a&gt; and I&amp;rsquo;ve posted it here as well. For those of you who were left wanting more from my &lt;a href="https://major.io/2013/04/15/seriously-stop-disabling-selinux/"&gt;previous SELinux post&lt;/a&gt;, this should help. If it doesn&amp;rsquo;t help, leave a comment. ;)&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;The push to cloud transforms the way we apply information security principles to systems and applications. Perimeters of the past, secured heavily with traditional network devices in the outermost ring, lose effectiveness day by day. Shifting the focus to &amp;ldquo;defense in depth&amp;rdquo; brings the perimeter down to the individual cloud instances running your application. Security-Enhanced Linux, or SELinux, forms an effective part of that perimeter.&lt;/p&gt;
&lt;p&gt;SELinux operates in the realm of mandatory access control, or MAC. The design of MAC involves placing constraints on what a user (a &lt;em&gt;subject&lt;/em&gt;) can do to a particular object (a &lt;em&gt;target&lt;/em&gt;) on the system. In contrast, discretionary access control, or DAC, allows a user with certain access to use discretion to limit or allow access to certain files, directories, or devices. You can set any file system permissions that you want but SELinux can override them with ease at the operating system level.&lt;/p&gt;
&lt;p&gt;Consider a typical server running a web application. An attacker compromises the web application and executes malicious code via the web server daemon itself. SELinux has default policies that prevent the daemon from initiating communication on the network. That limits the attacker’s options to attack other services or servers.&lt;/p&gt;
&lt;p&gt;In addition, SELinux sets policies on which files and directories the web server can access, regardless of any file system permissions. This protection limits the attacker’s access to other sensitive parts of the file system even if the administrator set the files to be readable to the world.&lt;/p&gt;
&lt;p&gt;This is where SELinux shines. Oddly enough, this is the point where many system administrators actually &lt;em&gt;disable SELinux&lt;/em&gt; on their systems.&lt;/p&gt;
&lt;p&gt;Troubleshooting these events, called AVC denials, without some helpful tools is challenging and frustrating. Each denial flows into to your audit log as a cryptic message. Most administrators will check the usual suspects, like firewall rules and file system permissions. As frustration builds, they disable SELinux and notice that their application begins working as expected. SELinux remains disabled and hundreds of helpful policies lie dormant solely because one policy caused a problem.&lt;/p&gt;
&lt;p&gt;Disabling SELinux without investigation frustrated me to the point where I started a site at &lt;a href="http://stopdisablingselinux.com"&gt;stopdisablingselinux.com&lt;/a&gt;. The site is a snarky response to Linux administrators who reach for the disable switch as soon as SELinux gets in their way.&lt;/p&gt;
&lt;p&gt;All jokes aside, here are some helpful tips to use SELinux effectively:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Use the &lt;em&gt;setroubleshoot&lt;/em&gt; helpers to understand denials&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Working through denials is easy with the &lt;em&gt;setroubleshoot-server&lt;/em&gt; package. When a denial occurs, you still receive a cryptic log message in your audit logs. However, you also receive a message via syslog that is very easy to read. Your server can email you these messages as well. The message contains guidance about adjusting SELinux booleans, setting contexts, or generating new SELinux policies to work around a really unusual problem. When I say guidance, I mean that the tools give you commands to copy and paste to adjust your policies, booleans and contexts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Review SELinux booleans for quick adjustments&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Although the myriad of SELinux user-space tools isn’t within the scope of this article, &lt;em&gt;getsebool&lt;/em&gt; and &lt;em&gt;togglesebool&lt;/em&gt; deserve a mention. Frequently adjusted policies are controlled by booleans that are toggled on and off with &lt;em&gt;togglesebool&lt;/em&gt;. Start with &lt;em&gt;getsebool –a&lt;/em&gt; for a full list of booleans and then use &lt;em&gt;togglesebool&lt;/em&gt; to enable or disable the policy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Quickly restore file or directory contexts&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Shuffling files or directories around a server can cause SELinux denials due to contexts not matching their original values. This happens to me frequently if I move a configuration file from one system to another. Correcting the context problem involves one of two simple commands. The &lt;em&gt;restorecon&lt;/em&gt; command applies the default contexts specific to the file or directory. If you have a file in the directory with the correct context, use &lt;em&gt;chcon&lt;/em&gt; to fix the context on the wrong file by giving it the path to the file with the correct context.&lt;/p&gt;
&lt;p&gt;Here are some additional links with helpful SELinux documentation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://selinuxproject.org/page/Main_Page"&gt;SELinux Project Wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/"&gt;Red Hat Enterprise Linux 6 SELinux Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://danwalsh.livejournal.com/"&gt;Dan Walsh&amp;rsquo;s Blog&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Seriously, stop disabling SELinux</title><link>https://major.io/p/seriously-stop-disabling-selinux/</link><pubDate>Tue, 16 Apr 2013 04:40:10 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/seriously-stop-disabling-selinux/</guid><description>&lt;p&gt;After many discussions with fellow Linux users, I&amp;rsquo;ve come to realize that most seem to disable SELinux rather than understand why it&amp;rsquo;s denying access. In an effort to turn the tide, I&amp;rsquo;ve created a new site as a public service to SELinux cowards everywhere: &lt;a href="http://stopdisablingselinux.com/"&gt;stopdisablingselinux.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here are some relatively useful SELinux posts from the blog:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://major.io/2012/01/25/getting-started-with-selinux/"&gt;Getting started with SELinux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://major.io/2011/09/15/receive-e-mail-reports-for-selinux-avc-denials/"&gt;Receive email reports for SELinux AVC denials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; The goal of the post was to poke some fun at system administrators who disable SELinux immediately without learning how it works or why they&amp;rsquo;re seeing certain operations being denied. Obviously, if your particular workload or demands don&amp;rsquo;t allow for the use of SELinux, then I&amp;rsquo;m going to be the last person to encourage you to use it. Many system administrators have found that it doesn&amp;rsquo;t provide a good ratio of work required to benefit gained, which I totally understand.&lt;/p&gt;</description></item><item><title>SELinux, Xen, and block devices in Fedora 17</title><link>https://major.io/p/selinux-xen-and-block-devices-in-fedora-17/</link><pubDate>Tue, 10 Jul 2012 05:05:33 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/selinux-xen-and-block-devices-in-fedora-17/</guid><description>&lt;p&gt;If you try to run Xen without libvirt on Fedora 17 with SELinux in enforcing mode, you&amp;rsquo;ll be butting heads with SELinux in no time. You&amp;rsquo;ll probably be staring at something like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# xm create -c fedora17
Using config file &amp;#34;/etc/xen/fedora17&amp;#34;.
Error: Disk isn&amp;#39;t accessible
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you have &lt;code&gt;setroubleshoot&lt;/code&gt; and &lt;code&gt;setroubleshoot-server&lt;/code&gt; installed, you should have a friendly message in /var/log/messages telling you the source of the problem:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;setroubleshoot: SELinux is preventing /usr/bin/python2.7 from read access on the blk_file dm-1.
For complete SELinux messages. run sealert -l 4d890105-d9a4-4b3e-a674-ba7e952942dc
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The Xen daemon (the python process mentioned in the SELinux denial) is running with a context type of &lt;code&gt;xend_t&lt;/code&gt; but the block device I&amp;rsquo;m trying to use for the VM has &lt;code&gt;fixed_disk_device_t&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ps axZ | grep xend
system_u:system_r:xend_t:s0 953 ? SLl 0:40 /usr/bin/python /usr/sbin/xend
# ls -alZ /dev/dm-1
brw-rw----. root disk system_u:object_r:fixed_disk_device_t:s0 /dev/dm-1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;SELinux isn&amp;rsquo;t going to allow this to work. However, even if we fix this, SELinux will balk about three additional issues and we&amp;rsquo;ll need to adjust the contexts on every new fixed block device we make. To get over the hump, change the context type on your block device to &lt;code&gt;xen_image_t&lt;/code&gt; and re-run the &lt;code&gt;xm create&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# chcon -t xen_image_t /dev/dm-1
# ls -alZ /dev/dm-1
brw-rw----. root disk system_u:object_r:xen_image_t:s0 /dev/dm-1
# xm create -c fedora17
Using config file &amp;#34;/etc/xen/fedora17&amp;#34;.
Error: out of pty devices
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;ll find three new denials in /var/log/messages:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;setroubleshoot: SELinux is preventing /usr/bin/python2.7 from read access on the file group.
For complete SELinux messages. run sealert -l b1392df4-dda4-4b82-914c-1e20c62fc898
setroubleshoot: SELinux is preventing /usr/bin/python2.7 from setattr access on the chr_file 1.
For complete SELinux messages. run sealert -l 3e09edc3-aeb7-49f5-96e1-d8148afda48f
setroubleshoot: SELinux is preventing /usr/bin/python2.7 from execute access on the file pt_chown.
For complete SELinux messages. run sealert -l 86395f09-5f33-4f66-8d02-519b61e54139
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;As much as it pains me to suggest it, you can create a custom module to allow all four of these operations by xend:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# grep xend /var/log/audit/audit.log | audit2allow -M custom_xen
WARNING: Policy would be downgraded from version 27 to 26.
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i custom_xen.pp

# semodule -i custom_xen.pp
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You should now be able to start your VM without any complaints from SELinux. I&amp;rsquo;ll reiterate that this isn&amp;rsquo;t ideal, but it&amp;rsquo;s the best balance of security and convenience that I&amp;rsquo;ve found so far.&lt;/p&gt;</description></item><item><title>Getting started with SELinux</title><link>https://major.io/p/getting-started-with-selinux/</link><pubDate>Thu, 26 Jan 2012 04:28:41 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/getting-started-with-selinux/</guid><description>&lt;p&gt;I used to be one of those folks who would install Fedora, CentOS, Scientific Linux, or Red Hat and disable SELinux during the installation. It always seemed like SELinux would get in my way and keep me from getting work done.&lt;/p&gt;
&lt;p&gt;Later on, I found that one of my servers (which I&amp;rsquo;d previously secured quite thoroughly) had some rogue processes running that were spawned through httpd. Had I actually been using SELinux in enforcing mode, those processes would have probably never even started.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re trying to get started with SELinux but you&amp;rsquo;re not sure how to do it without completely disrupting your server&amp;rsquo;s workflow, these tips should help:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Get some good reporting and monitoring&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Two of the most handy SELinux tools are &lt;a href="https://fedorahosted.org/setroubleshoot/"&gt;setroubleshoot and setroubleshoot-server&lt;/a&gt;. If you&amp;rsquo;re running a server without X, you can use &lt;a href="https://major.io/2011/09/15/receive-e-mail-reports-for-selinux-avc-denials/"&gt;my guide for configuring setroubleshoot-server&lt;/a&gt;. You will receive email alerts within seconds of an AVC denial and the emails should contain tips on how to resolve the denial if the original action should be allowed. If the AVC denial caught something you didn&amp;rsquo;t expect, you&amp;rsquo;ll know about the potential security breach almost immediately.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Start out with SELinux in permissive mode&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re overly concerned about SELinux getting in your way, or if you&amp;rsquo;re enabling SELinux on a server that has been running without SELinux since it was installed, start out with SELinux in permissive mode. To make the change effective immediately, just run:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# setenforce 0
# getenforce
Permissive
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Edit &lt;code&gt;/etc/sysconfig/selinux&lt;/code&gt; to make it persistent across reboots:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Adjust booleans before adding your own custom modules&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are a lot of booleans you can toggle to get the functionality you need without adding your own custom SELinux modules with &lt;code&gt;audit2allow&lt;/code&gt;. If you wanted to see all of the applicable booleans for &lt;code&gt;httpd&lt;/code&gt;, just use &lt;code&gt;getsebool&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# getsebool -a | grep httpd
httpd_builtin_scripting --&amp;gt; on
httpd_can_check_spam --&amp;gt; off
httpd_can_network_connect --&amp;gt; on
httpd_can_network_connect_cobbler --&amp;gt; off
httpd_can_network_connect_db --&amp;gt; off
httpd_can_network_memcache --&amp;gt; off
httpd_can_network_relay --&amp;gt; on
httpd_can_sendmail --&amp;gt; on
... and so on ...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Toggling booleans is easy with &lt;code&gt;togglesebool&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# togglesebool httpd_can_network_memcache
httpd_can_network_memcache: active
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now &lt;code&gt;httpd&lt;/code&gt; can talk to &lt;code&gt;memcache&lt;/code&gt;. You can also use &lt;code&gt;setsebool&lt;/code&gt; if you want to be specific about your setting (this is good for scripts):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# setsebool httpd_can_network_memcache on
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Tracking your history of AVC denials&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;All of your AVC denals are logged by &lt;code&gt;auditd&lt;/code&gt; in &lt;code&gt;/var/log/audit/audit.log&lt;/code&gt; but it&amp;rsquo;s not the easiest file to read and parse. That&amp;rsquo;s where &lt;code&gt;aureport&lt;/code&gt; comes in:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# aureport --avc | tail -n 5
45. 01/24/2012 04:23:29 postdrop unconfined_u:system_r:httpd_t:s0 4 fifo_file getattr system_u:object_r:postfix_public_t:s0 denied 1061
46. 01/24/2012 04:23:29 postdrop unconfined_u:system_r:httpd_t:s0 2 fifo_file write system_u:object_r:postfix_public_t:s0 denied 1062
47. 01/24/2012 04:23:29 postdrop unconfined_u:system_r:httpd_t:s0 2 fifo_file open system_u:object_r:postfix_public_t:s0 denied 1062
48. 01/24/2012 14:01:58 sendmail unconfined_u:system_r:httpd_t:s0 160 process setrlimit unconfined_u:system_r:httpd_t:s0 denied 1123
49. 01/24/2012 14:01:58 postdrop unconfined_u:system_r:httpd_t:s0 4 dir search system_u:object_r:postfix_public_t:s0 denied 1124
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s no need to be scared of or be annoyed by SELinux in your server environment. While it takes some getting used to (and what new software doesn&amp;rsquo;t?), you&amp;rsquo;ll have an extra layer of security and access restrictions which should let you sleep a little better at night.&lt;/p&gt;</description></item><item><title>SELinux and .forward files</title><link>https://major.io/p/selinux-and-forward-files/</link><pubDate>Mon, 02 Jan 2012 22:44:43 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/selinux-and-forward-files/</guid><description>&lt;p&gt;If you want to forward e-mail from root to another user, you can usually place a &lt;code&gt;.forward&lt;/code&gt; file in root&amp;rsquo;s home directory and your mail server will take care of the rest:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; /root/.forward
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With SELinux, you&amp;rsquo;ll end up getting an AVC denial each time your mail server tries to read the contents of the &lt;code&gt;.forward&lt;/code&gt; file:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;type=AVC msg=audit(1325543823.787:7416): avc: denied { open } for pid=9850
 comm=&amp;#34;local&amp;#34; name=&amp;#34;.forward&amp;#34; dev=md0 ino=17694734
 scontext=system_u:system_r:postfix_local_t:s0
 tcontext=unconfined_u:object_r:admin_home_t:s0 tclass=file
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The reason is that your &lt;code&gt;.forward&lt;/code&gt; file doesn&amp;rsquo;t have the right SELinux contexts. You can set the correct contest quickly with &lt;code&gt;restorecon&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# ls -Z /root/.forward
-rw-r--r--. root root unconfined_u:object_r:admin_home_t:s0 /root/.forward
# restorecon -v /root/.forward
restorecon reset /root/.forward context unconfined_u:object_r:admin_home_t:s0-&amp;gt;system_u:object_r:mail_forward_t:s0
# ls -Z /root/.forward
-rw-r--r--. root root system_u:object_r:mail_home_t:s0 /root/.forward
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Try to send another e-mail to root and you should see the mail server forward the e-mail properly without any additional AVC denials.&lt;/p&gt;</description></item><item><title>Receive e-mail reports for SELinux AVC denials</title><link>https://major.io/p/receive-e-mail-reports-for-selinux-avc-denials/</link><pubDate>Fri, 16 Sep 2011 04:17:04 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/receive-e-mail-reports-for-selinux-avc-denials/</guid><description>&lt;p&gt;SELinux isn&amp;rsquo;t a technology that&amp;rsquo;s easy to tackle for newcomers. However, there&amp;rsquo;s been a lot of work to smooth out the rough edges while still keeping a tight grip on what applications and users are allowed to do on a Linux system. One of the biggest efforts has been around &lt;a href="https://fedorahosted.org/setroubleshoot/wiki/SETroubleShoot%20Overview"&gt;setroubleshoot&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The purpose behind setroubleshoot is to let users know when access has been denied, help them resolve it if necessary, and to reduce overall frustration while working through tight security restrictions in the default SELinux policies. The GUI frontend for setroubleshoot is great for users who run Linux desktops or those who run servers with a display attached. Don&amp;rsquo;t worry, you can configure setroubleshoot on remote servers to send alerts elsewhere when a GUI alert isn&amp;rsquo;t an option.&lt;/p&gt;
&lt;p&gt;Install a few packages to get started:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;yum install setroubleshoot{-server,-plugins,-doc}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Open &lt;code&gt;/etc/setroubleshoot/setroubleshoot.conf&lt;/code&gt; in your favorite text editor and adjust the &lt;code&gt;[email]&lt;/code&gt; section to fit your server:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;recipients_filepath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;/var/lib/setroubleshoot/email_alert_recipients&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;smtp_port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;25&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;smtp_host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;localhost&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;from_address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;selinux@myserver.com&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;subject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;[MyServer] SELinux AVC Alert&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You could probably see it coming, but you need to put the e-mail addresses for your recipients into &lt;code&gt;/var/lib/setroubleshoot/email_alert_recipients&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;echo &amp;#34;selinux@mycompany.com&amp;#34; &amp;gt;&amp;gt; /var/lib/setroubleshoot/email_alert_recipients
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You&amp;rsquo;ll notice that setroubleshoot doesn&amp;rsquo;t have an init script and it doesn&amp;rsquo;t exist in systemd in Fedora 15. It runs through the &lt;a href="http://en.wikipedia.org/wiki/D-Bus"&gt;dbus-daemon&lt;/a&gt; and a quick bounce of the messagebus via its init script brings in the necessary components to run setroubleshoot:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;service messagebus restart
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A really easy (and safe) test is to ask sshd to bind to a non-standard port. Simply define an additional port on in your &lt;code&gt;/etc/ssh/sshd_config&lt;/code&gt; like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Port 22
Port 222
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you restart sshd, it will bind to port 22 with success, but it won&amp;rsquo;t be allowed to bind to port 222 (since that&amp;rsquo;s blocked by SELinux as a non-standard port for the &lt;code&gt;ssh_port_t&lt;/code&gt; port type). &lt;strong&gt;DON&amp;rsquo;T WORRY!&lt;/strong&gt; Your sshd server will still be listening on port 22. If you wait a moment, you&amp;rsquo;ll get an e-mail (perhaps two) that not only notify you of the denial, but they make suggestions for how to fix it:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;SELinux is preventing /usr/sbin/sshd from name_bind access on the tcp_socket port 222.

***** Plugin bind_ports (99.5 confidence) suggests *************************

If you want to allow /usr/sbin/sshd to bind to network port 222
Then you need to modify the port type.
Do
# semanage port -a -t PORT_TYPE -p tcp 222
 where PORT_TYPE is one of the following: ...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For this particular example, the quick fix would be to run:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;semanage port -a -t ssh_port_t -p tcp 222
&lt;/code&gt;&lt;/pre&gt;&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Much of this post&amp;rsquo;s information was gathered from the detailed documentation on &lt;a href="http://fedoraproject.org/wiki/Docs/Drafts/SELinux/SETroubleShoot/UserFAQ"&gt;Fedora&amp;rsquo;s setroubleshoot User&amp;rsquo;s FAQ&lt;/a&gt; as well as &lt;a href="http://danwalsh.livejournal.com/20931.html"&gt;Dan Walsh&amp;rsquo;s setroubleshoot blog post&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description></item><item><title>Getting apache, PHP, and memcached working with SELinux</title><link>https://major.io/p/getting-apache-php-and-memcached-working-with-selinux/</link><pubDate>Thu, 08 Sep 2011 03:55:00 +0000</pubDate><author>major@mhtx.net (Major Hayden)</author><guid>https://major.io/p/getting-apache-php-and-memcached-working-with-selinux/</guid><description>&lt;p&gt;&lt;img src="https://major.io/wp-content/uploads/2011/09/selinux-penguin-125.png" alt="1"&gt;&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m using SELinux more often now on my Fedora 15 installations and I came up against a peculiar issue today on a new server. My PHP installation is configured to store its sessions in memcached and I brought over some working configurations from another server. However, each time I accessed a page which tried to initiate a session, the page load would hang for about a minute and I&amp;rsquo;d find this in my apache error logs:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[Thu Sep 08 03:23:40 2011] [error] [client 11.22.33.44] PHP Warning:
Unknown: Failed to write session data (memcached). Please verify that
the current setting of session.save_path is correct (127.0.0.1:11211)
in Unknown on line 0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I ran through my usual list of checks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;netstat showed memcached bound to the correct ports/interfaces&lt;/li&gt;
&lt;li&gt;memcached was running and I could reach it via telnet&lt;/li&gt;
&lt;li&gt;memcached-tool could connect and pull stats from memcached&lt;/li&gt;
&lt;li&gt;double-checked my php.ini&lt;/li&gt;
&lt;li&gt;tested memcached connectivity via a PHP and ruby script - they worked&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even after all that, I still couldn&amp;rsquo;t figure out what was wrong. I ran strace on memcached while I ran a curl against the page which creates a session and I found something significant - memcached wasn&amp;rsquo;t seeing any connections whatsoever at that time. A quick check of the lo interface with tcpdump showed the same result. Just before I threw a chair, I remembered one thing:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;SELinux.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A quick check for AVC denials showed the problem:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# aureport --avc | tail -n 1
4021. 09/08/2011 03:23:38 httpd system_u:system_r:httpd_t:s0 42 tcp_socket name_connect system_u:object_r:memcache_port_t:s0 denied 31536
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I&amp;rsquo;m far from being a guru on SELinux, so I leaned on audit2allow for help:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# grep memcache /var/log/audit/audit.log | audit2allow

#============= httpd_t ==============
#!!!! This avc can be allowed using one of the these booleans:
# httpd_can_network_relay, httpd_can_network_memcache, httpd_can_network_connect

allow httpd_t memcache_port_t:tcp_socket name_connect;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The boolean we&amp;rsquo;re looking for is &lt;code&gt;httpd_can_network_memcache&lt;/code&gt;. Flipping the boolean can be done in a snap:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# setsebool -P httpd_can_network_memcache 1
# getsebool httpd_can_network_memcache
httpd_can_network_memcache --&amp;gt; on
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After adjusting the boolean, apache was able to make connections to memcached without a hitch. My page which created sessions loaded quickly and I could see data being stored in memcached. If you want to check the status of all of the apache-related SELinux booleans, just use getsebool:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# getsebool -a | grep httpd | grep off$
allow_httpd_anon_write --&amp;gt; off
allow_httpd_mod_auth_ntlm_winbind --&amp;gt; off
allow_httpd_mod_auth_pam --&amp;gt; off
allow_httpd_sys_script_anon_write --&amp;gt; off
httpd_can_check_spam --&amp;gt; off
httpd_can_network_connect_cobbler --&amp;gt; off
httpd_can_network_connect_db --&amp;gt; off
httpd_can_network_relay --&amp;gt; off
httpd_can_sendmail --&amp;gt; off
httpd_dbus_avahi --&amp;gt; off
httpd_enable_ftp_server --&amp;gt; off
httpd_enable_homedirs --&amp;gt; off
httpd_execmem --&amp;gt; off
httpd_read_user_content --&amp;gt; off
httpd_setrlimit --&amp;gt; off
httpd_ssi_exec --&amp;gt; off
httpd_tmp_exec --&amp;gt; off
httpd_unified --&amp;gt; off
httpd_use_cifs --&amp;gt; off
httpd_use_gpg --&amp;gt; off
httpd_use_nfs --&amp;gt; off
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you&amp;rsquo;re interested in SELinux, a good way to get your feet wet is to head over to the CentOS Wiki and review their &lt;a href="http://wiki.centos.org/HowTos/SELinux"&gt;SELinux Howtos&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>