Apache使用SELinux在CentOS 7上执行MATLAB二进制文件

时间:2017-07-13 15:26:50

标签: linux apache matlab selinux

我试图在Apache上下文中的CentOS 7服务器表单上触发预编译的MATLAB程序。系统允许用户上传一些文件。然后进行一些健全性检查。然后调用MATLAB程序并执行一些MATLAB魔术。

我安装了MATLAB环境:

    unzip -d mcr_unzipped MCR_R2015b_glnxa64_installer.zip
    sudo mcr_unzipped/install -glnx86 -tmpdir ~/tmp -mode silent -agreeToLicense yes    

我将LD_LIBRARY_PATH添加到http.conf文件中:

    SetEnv LD_LIBRARY_PATH /usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/v90/sys/opengl/lib/glnxa64

我尝试给我的webapplication文件夹类型为httpd_sys_rw_content_t,MATLAB环境的类型为httpd_fastcgi_script_exec_t:

    chcon -R -t httpd_sys_rw_content_t /var/www/webapp
    #allow exec:
    setsebool -P httpd_ssi_exec 1
    #context:
    chcon -Rv --type=httpd_fastcgi_script_exec_t /usr/local/MATLAB/

当我用“setenforce 0”禁用SELinux时,设置工作正常。 Apache运行MATLAB二进制文件,我的所有绘图和内容都可用。

我通过添加audit.log中的策略修复了一些问题:

    audit2allow -a -M mypolicy
    semodule -i mypolicy.pp

将路径添加到/etc/ld.so.conf.d/,如下所示:

    echo "/usr/local/MATLAB/MATLAB_Runtime/v90/runtime/glnxa64" > /etc/ld.so.conf.d/matlab.runtime.conf

然后调用ldconfig。

我的问题:

当SELinux强制执行时,无法加载MATLAB运行时环境。这是特定时间的/ var / log / httpd / error_log:

[Thu Jul 13 15:54:28.676588 2017] [:error] [pid 1382] [client 10.0.2.2:50377] PHP Notice: ... some warning or notice
Error:Could not find version 9.0 of the MATLAB Runtime.
Attempting to load libmwmclmcrrt.so.9.0.
Please install the correct version of the MATLAB Runtime.
Contact your vendor if you do not have an installer for the MATLAB Runtime.
[Thu Jul 13 15:54:29.056179 2017] [:error] [pid 1382] [client 10.0.2.2:50377] PHP Warning: ... some warning or notice

正如您所看到的那样,执行失败,就好像没有设置MATLAB环境的路径一样。

  • 我尝试调用MATLAB C编译器生成的run_binary.sh脚本,而不是二进制文件,但无效。
  • 我为MATLAB * .so和我的二进制文件尝试了“chcon -t textrel_shlib_t”。
  • 我尝试了SELinux的不同甚至所有bool(虚拟机开发环境FTW)
  • 我安装了setroubleshoot + setroubleshoot-server
  • 调用PHP文件时,/ var / log / message和/var/log/audit/audit.log中没有任何条目

有没有人知道我能做些什么,除了贬低SELinux?

1 个答案:

答案 0 :(得分:0)

解决方案是更多事情的组合:

#since MATLAB is JAVA based:
sudo setsebool -P httpd_execmem 1

#allow exec tempfiles for httpd service
sudo setsebool -P httpd_tmp_exec 1

#flag MATLAB runtime lib as such an executable:
semanage fcontext -a -t systemd_tmpfiles_exec_t '/usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64/libgcc_s.so.1'
restorecon -v /usr/local/MATLAB/MATLAB_Runtime/v90/sys/os/glnxa64/libgcc_s.so.1

#flag my own binary as shell executable:
semanage fcontext -a -t shell_exec_t '/var/www/html/myMatlabCompiledBinary'
restorecon -v /var/www/html/myMatlabCompiledBinary