Vagrant 2.1.1
主机操作系统:Windows 7 Pro
guest 操作系统:Centos 7.4
使用默认的 Vagrant 同步文件夹或 nfs vagrant 同步文件夹,我不断收到 SELinux 错误,告诉我需要将上下文更改为 httpd_sys_content_t
。默认同步文件夹中的所有文件都设置为 default_t
上下文,所有使用 nfs 同步的文件都设置为 nft_t
。
文件总是default_t上下文
config.vm.synced_folder '.', '/vagrant'
文件总是 nfs_t 上下文
config.vm.synced_folder ".", "/vagrant", 类型:"nfs"
我尝试使用 fcontext
和 restorecon
以正常方式更改文件上下文,但是 restorecon
只是默默地失败了。
如何设置同步文件/文件夹的上下文以避免 SELinux 错误?
我试过使用 :mount_options
,但它们被忽略了。
示例:
config.vm.synced_folder“./www”,“/var/www”,类型:“nfs”,创建:true,id:“sites”,mount_options:['vers = 3',:udp,: nolock, :noatime, 'context=system_u:object_r:httpd_sys_content_t:s0']
也许我在挂载选项中以错误的方式添加了上下文??
最佳答案
您必须对 vagrant 同步文件夹使用 rsync,因为不支持通过 sync_folders 设置 SELContext,因为它是 vboxfs 的限制。所以在你的 vagrantfile 中做这样的事情:
config.vm.synced_folder "guest/sync/location", "/host/sync/location", :owner => "root", :group => "root", type: "rsync", rsync__exclude: [".git", ".DS_Store"], rsync__args:["-avz", "--rsync-path='sudo rsync'"]
此解决方法假定您已根据此 post 使用 semanage 和 restorecon 持续递归地设置 httpd_sys_content_t .
编辑:2018 年 11 月 3 日 遗憾的是,上述解决方案实际上并没有同步文件,因为 rsync 并不真正适用于寡妇主机。以下是我对解决方法的发现和结论:
https://github.com/hashicorp/vagrant/issues/9827#issuecomment-435622888
关于linux - Vagrant:设置同步文件夹的上下文以防止 SELinux 报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50291981/