2014-11-05 61 views
0

我正面临以下情况。为了Web开发的目的,我设法使用VirtualBox设置了一个CentOS 7虚拟机。我已经安装了一个LAMP堆栈并配置了Apache(vhost,添加了vboxsf的apache成员,添加了防火墙规则)以访问VirtualBox共享文件夹。无法更改VirtualBox共享文件夹的SELinux安全上下文

Virtual machine hostname: dickwan.dev 
Shared Folders: 
    Name | Read-only | Auto-mount 
    ------------------------------------ 
    dickwan | no   | yes 
    ------------------------------------ 


Networking: NAT (with port forwarding rules) 
Port Forwarding Rules: 
    Name | Protocol | Host IP  | Host Port | Guest IP | Guest Port 
    -------------------------------------------------------------------------------------- 
    HTTP | TCP   | . . .  | 8080  | . . .  | 80 
    -------------------------------------------------------------------------------------- 
    MariaDB | TCP   | . . .  | 9306  | . . .  | 3306 
    -------------------------------------------------------------------------------------- 
    SSH  | TCP   | . . .  | 2222  | . . .  | 22 

现在,当我的主机,我打开浏览器,然后导航到(让我们说):

http://dickwan.dev:8080/server-status 

我客人的CentOS 7 VM客户机的

配置设置得到消息:

Forbidden 

You don't have permission to access /server-status on this server. 

我已经找到了SELinux安全上下文类型问题的问题。 当SELinux被禁用时,所有的工作都很好(好吧...好啊)。

但对我来说,就像关闭安全功能的一种不好的做法。我试图更改共享文件夹的上下文,但我无法执行操作

有没有机会通过Apache访问共享文件夹而不关闭SELinux?

回答

1

我有一个类似的问题(Fedora 20作为主机和客户操作系统除外)。我做了什么:

须藤安装-t vboxsf shared_folder /媒体/ shared_folder

须藤LN -s /媒体/ shared_folder /在/ var/WWW/

须藤chcon这个-R - 基准=在/ var/WWW的/ var/WWW/shared_folder

这对我的作品:)

之前我已经尝试设置安全上下文自动安装的共享文件夹(VirtualBox的),但没有成功,因此,我手动安装

1

由于垂直框的安全上下文中的共享文件夹无法改变,你可以修改SELinux安全政策允许Apache与上下文一起工作。它类似于在防火墙中打开端口以将某个端口暴露给应用程序。

首先,确保你的apache用户是拥有共享文件夹的组的一部分,如果不是,你可以添加一个看起来像这样的命令(用户/组名可以不同于你的系统):

usermod -aG vboxsf apache 

然后,您可以使用audit2allow生成一个新的安全策略来解决你的问题。 Here is a good tutorial

如果您懒惰,只想让Apache读取您的VBox共享文件夹,则可以调整以下​​策略文件,并使用包含的命令将其应用于您的系统。

module my_httpd_t 1.0; 

require { 
     type httpd_t; 
     type vmblock_t; 
     class dir read; 
     class file { read getattr open }; 
} 

#============= httpd_t ============== 
allow httpd_t vmblock_t:dir read; 
allow httpd_t vmblock_t:file { getattr open read }; 

# Generated by audit2allow 

# To apply this policy: 
## checkmodule -M -m -o my_httpd_t.mod my_httpd_t.te 
## semodule_package -o my_httpd_t.pp -m my_httpd_t.mod 
## semodule -i my_httpd_t.pp 
## systemctl restart httpd 
相关问题