SELinux阻止Perl CGI脚本访问Oracle库

我试图在运行Apache 2.2.15和Perl 5.10.1的Red Hat Enterprise Linux 6.2 Web服务器上configurationSELinux,并连接到远程Oracle数据库。 Oracle 11.2g客户端已安装。 访问Oracle的PHP脚本正在工作,但Perl脚本不能。 当SELinux执行时,我尝试通过我的Web浏览器访问Perl脚本,Apache的错误日志显示这个消息:

Can't load '/usr/local/lib64/perl5/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.11.1: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 200. 

奇怪的是,审计日志不logging任何相应的消息。 但是,当我将SELinux设置为permissive模式时,Perl脚本完美地工作。

这是libclntsh.so.11.1上的ls -lZ的输出:

 -rwxr-xr-x. oracle oracle system_u:object_r:textrel_shlib_t:s0 /path/to/oracle/product/11.2.0/client/lib/libclntsh.so.11.1 

有没有人有任何build议来解决这个问题? 我希望能够通过SELinux运行Web服务器。

更新:selinux设置为dontaudit之后,我在audit.log中获得了更多的输出。 但是,我使用audit2allow创build的模块不能安装。 semodule -i的输出是: semodule: Failed on cgi_oracle!

cgi_oracle.te包含:

 module cgi_oracle 1.0; require { type httpd_log_t; type httpd_t; type httpd_sys_script_t; class process { siginh noatsecure rlimitinh }; class file { read write }; } #============= httpd_sys_script_t ============== allow httpd_sys_script_t httpd_log_t:file { read write }; #============= httpd_t ============== allow httpd_t httpd_sys_script_t:process { siginh rlimitinh noatsecure }; 

一些SELinux策略被标记为dontaudit以便它们不会在审计日志中留下消息 。 这通常是因为他们的政策只是垃圾邮件日志无用的条目,但有时开发商dontaudit拒绝而不是解决底层的问题。 您碰到的策略几乎可以肯定是其中之一,因为您没有在audit.log中logging任何消息。

您可以通过运行暂时禁用dontaudit

 semodule -DB 

在发现问题的原因后,重新启用dontaudit

 semodule -B 

一旦你生成了你的策略,运行:

 make -f /usr/share/selinux/devel/Makefile 

要正确识别问题 – 您必须使用SELinux许可模式运行testing,否则您将需要逐个运行testing,可能需要一些时间。 之后,停止Web服务,确保您的审计日志为空或轮换,运行Web服务,运行脚本/testing,检查审计日志和写入新策略。 据我所知你的脚本要访问oracle库进行读取,所以你需要在你的应用程序中添加“system_u:object_r:textrel_shlib_t:s0”的读权限。 我不知道oracle的标签结构是什么,但我相信你可以find。 检查audit2allow。

你也可以尝试setroubleshoot ..它也会给你线索什么是限制和命令来解决这个问题。 大部分时间你所要做的就是复制和粘贴给定的东西。

 yum install -y setroubleshoot 

然后

 grep setrouble /var/log/messages 

例如:

 Aug 6 12:36:11 cnt3 setroubleshoot: [avc.ERROR] Plugin Exception catchall_boolean #012Traceback (most recent call last):#012 File "/usr/lib/python2.6/site-packages/setroubleshoot/analyze.py", line 191, in analyze_avc#012 report = plugin.analyze(avc)#012 File "/usr/share/setroubleshoot/plugins/catchall_boolean.py", line 90, in analyze#012 man_page = self.check_for_man(b)#012 File "/usr/share/setroubleshoot/plugins/catchall_boolean.py", line 76, in check_for_man#012 man_page = name.split("_")[0] + "_selinux"#012AttributeError: 'tuple' object has no attribute 'split' Aug 6 12:36:11 cnt3 setroubleshoot: SELinux is preventing /usr/libexec/gdm-session-worker from read access on the directory /root. For complete SELinux messages. run sealert -l 721b07e3-e0e2-4a0e-a676-8eb622f7ce01 sealert -l 721b07e3-e0e2-4a0e-a676-8eb622f7ce01 sealert -l 721b07e3-e0e2-4a0e-a676-8eb622f7ce01 SELinux is preventing /usr/libexec/gdm-session-worker from read access on the directory /root. ***** Plugin catchall (100. confidence) suggests *************************** 

如果您认为gdm-session-worker默认情况下应该允许在根目录下读取访问权限。 那么你应该报告这个错误。 您可以生成本地策略模块以允许此访问。 现在通过执行:

 grep gdm-session-wor /var/log/audit/audit.log | audit2allow -M mypol semodule -i mypol.pp 

遵循sealert -l告诉你的,我认为你的问题应该被解决。 希望有所帮助。