{"id":117,"date":"2016-06-17T15:49:46","date_gmt":"2016-06-17T19:49:46","guid":{"rendered":"https:\/\/blog.beausanders.org\/?p=117"},"modified":"2017-04-29T15:58:19","modified_gmt":"2017-04-29T19:58:19","slug":"dont-forget-about-selinux","status":"publish","type":"post","link":"https:\/\/blog.beausanders.org\/index.php\/dont-forget-about-selinux\/","title":{"rendered":"Don&#8217;t Forget About SELinux"},"content":{"rendered":"<p>Recently we decided to move some of our web applications, as well as this blog, to a new cloud server provided by <a href=\"http:\/\/dreamhost.com\" target=\"_blank\" rel=\"noopener noreferrer\">DreamHost.com<\/a> and their new <a href=\"http:\/\/dreamcompute.com\" target=\"_blank\" rel=\"noopener noreferrer\">DreamCompute<\/a> OpenStack cluster in Virginia. Starting with a minimal install of CentOS7, we built a fairly standard LAMP server. Once we got the new server stable, we moved the apps over. The web apps hosted on our new server are <a href=\"http:\/\/geekglossary.com\" target=\"_blank\" rel=\"noopener noreferrer\">GeekGlossary.com<\/a> and <a href=\"https:\/\/jobs.beausanders.org\" target=\"_blank\" rel=\"noopener noreferrer\">jobs.beausanders.org<\/a>. For the sake of this post, you need to know both of these apps have similar backup routines and logging functions.<!--more--><\/p>\n<p>After moving our apps, both of them began having issues saving backup files. The logging function stopped working as well. What made this most annoying is that PHP was not throwing any errors when executing the backup or logging scripts. We checked the permissions, paths, and variable names, as we set out to solve this problem. All looked fine.<\/p>\n<p>Seasoned Linux administrators have already jumped to the end of this short story. It turns out that SELinux, which was in <strong>Enforcing<\/strong> mode, was blocking writes from httpd (Apache). We determined this by putting SELinux in <strong>Permissive<\/strong> mode with the following commands and re-running the backup and logging scripts:<\/p>\n<p><code># setenforce 0<\/code><br \/>\n<code># getenforce<br \/>\nPermissive<\/code><\/p>\n<p>With SELinux in <strong>Permissive<\/strong> mode, CentOS7 and Apache did what was expected and saved the backups and created the log entries.<\/p>\n<p>Now that the cause of the problem was confirmed, fixing it was fairly easy. In preparation, we did a little review online on SELinux. <a href=\"\/\/wiki.centos.org\/HowTos\/SELinux\" target=\"_blank\" rel=\"noopener noreferrer\">This &#8220;how-to&#8221; article on the CentOS website<\/a> is very helpful.<\/p>\n<p>Next we made sure that we had installed the CentOS7 packages to troubleshoot SELinux; these commands will install the necessary packages in CentOS7:<\/p>\n<p><code># <code class=\"plain\">yum <\/code><code class=\"functions\">install<\/code> <code class=\"plain\">setroubleshoot-server<br \/>\n# yum install policycoreutils-python<\/code><\/code><\/p>\n<p>Among other things, these packages provide <strong>semanage<\/strong> and <strong>sealert<\/strong>, two valuable SELinux command line tools needed to manage, monitor, and fix SElinux.<\/p>\n<p>In order to see in plain English what SELinux is blocking and why, run the following command; your destination file can be whatever you want:<\/p>\n<p><code># sealert -a \/var\/log\/audit\/audit.log &gt; \/path\/to\/mylogfile.txt<\/code><\/p>\n<p>Carefully read through the destination file from the command above and you will not only learn what the problems are, but also how to fix them&#8230;complete with commands. Basically, you will be instructed to change SELinux contexts for certain directories on your server, as well as create policy mods to keep the problem(s) from coming back. Cut and paste the suggested commands in to your command line interface and execute them. That&#8217;s it. Simple.<\/p>\n<p>This is one of those situations where a little bit of reading and study goes a long way. My recommendation&#8230;do an online search for <em><strong>selinux sealert<\/strong><\/em> and learn about this very helpful tool.<\/p>\n<p>After you have run the commands as instructed by <strong>sealert<\/strong>, be sure to turn SELinux <strong>Enforcing<\/strong> mode back on with these commands:<\/p>\n<p><code># setenforce 1<\/code><br \/>\n<code># getenforce<br \/>\nEnforcing<br \/>\n<\/code><\/p>\n<p>Now SELinux is protecting your server, while allowing custom web apps and other software tools you use to do their jobs. Periodically you should run <strong>sealert<\/strong> to check for any new problems related to enforcing SELinux.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently we decided to move some of our web applications, as well as this blog, to a new cloud server provided by DreamHost.com and their new DreamCompute OpenStack cluster in Virginia. Starting with a minimal install of CentOS7, we built a fairly standard LAMP server. Once we got the new server stable, we moved the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[6,18,8,7,9],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-solutions-to-problems-i-found-helpful","tag-centos7","tag-rhel7","tag-sealert","tag-selinux","tag-semanage"],"_links":{"self":[{"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":14,"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/posts\/117\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.beausanders.org\/index.php\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}