{"id":236,"date":"2007-11-30T01:56:17","date_gmt":"2007-11-29T16:56:17","guid":{"rendered":"https:\/\/fugutabetai.com\/blog\/2007\/11\/30\/selinux-problems-solutions\/"},"modified":"2007-11-30T01:56:17","modified_gmt":"2007-11-29T16:56:17","slug":"selinux-problems-solutions","status":"publish","type":"post","link":"https:\/\/fugutabetai.com\/blog\/2007\/11\/30\/selinux-problems-solutions\/","title":{"rendered":"SELinux Problems, solutions"},"content":{"rendered":"<p>In general, I really like the idea of SELinux.&nbsp; It conceptually allows you to specify users, roles, and types for files and then checks against those conditions when something tries to access the files.&nbsp; It will only allow users that match the user condition, roles that match the role condition, and types that match the type condition to actually proceed and work with the file.<\/p>\n<p>So, for example, if you a role of &#8220;web object&#8221; which the webserver account fills, and it tries to write data into some directory that is not fit for that role, say \/bin\/, the operation will fail and the would-be hacker can&#8217;t put their trojaned ls program or whatever in there.&nbsp; That is a good thing.&nbsp; <\/p>\n<p>The problem is that the SELinux system is really kind of complicated.&nbsp; If you don&#8217;t know that it is there, you will just have things failing mysteriously, especially if you add directories in places that aren&#8217;t set up with the system already.&nbsp; Running a webserver on one of my linux machines, I ran into this problem.&nbsp; It is particularly an issue when you are trying to use executable scripts on your web server. <\/p>\n<p>Here is an instance of a problem that I had:&nbsp; I copied some scripts over from a production machine to a dev machine so I could build some more functionality based on the existing scripts.&nbsp; They went into <code>\/var\/www\/cgi-bin\/, a normal place for scripts on my system.&nbsp; To find out the attributes they should have:<br \/><\/code><\/p>\n<blockquote><p><code>$ ls -ldZ \/var\/www\/cgi-bin<\/code><br \/><code>drwxr-xr-x&nbsp; root root system_u:object_r:httpd_sys_script_exec_t:s0 \/var\/www\/cgi-bin<\/code><br \/><code><\/code>$ ls -ldZ \/var\/www\/cgi-bin\/my.cgi-rwxr-xr-x&nbsp; root root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/var\/www\/cgi-bin\/my.cgi<\/p><\/blockquote>\n<p>So that isn&#8217;t good.&nbsp; When I try to access the file, I get a 404, which isn&#8217;t really true: actually the file is there, but SELinux is preventing it from being used.&nbsp; So, what should I do?&nbsp; I need to make the files have the correct SELinux settings.&nbsp; First, I try setting the type of the file:<\/p>\n<blockquote><p>sudo chcon -t httpd_sys_script_exec_t \/var\/www\/cgi-bin\/*<br \/>chcon: can&#8217;t apply partial context to unlabeled file \/var\/www\/cgi-bin\/<\/p><\/blockquote>\n<p>Oh, that&#8217;s no good.&nbsp; What&#8217;s a partial context?&nbsp; Looks like you need to specify all the attributes of the file.&nbsp; Usually the files already have some default attributes, so it is ok, but for some reason these guys have nothing.&nbsp; I don&#8217;t know why.&nbsp; But if we apply all of the attributes that we need:<\/p>\n<blockquote><p>sudo chcon system_u:object_r:httpd_sys_script_exec_t \/var\/www\/cgi-bin\/*<\/p><\/blockquote>\n<p>And that fixed the problem.&nbsp; Also, if you need to know where SELinux error messages are, they are sometimes in \/var\/log\/messages, sometimes in dmesg output, and sometimes in \/var\/log\/audit\/audit.log or possible \/var\/log\/avc.log, depending on how your system is set up.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In general, I really like the idea of SELinux.&nbsp; It conceptually allows you to specify users, roles, and types for files and then checks against those conditions when something tries to access the files.&nbsp; It will only allow users that match the user condition, roles that match the role condition, and types that match the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/comments?post=236"}],"version-history":[{"count":0,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/posts\/236\/revisions"}],"wp:attachment":[{"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/media?parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/categories?post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugutabetai.com\/blog\/wp-json\/wp\/v2\/tags?post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}