linux - Vagrant:设置同步文件夹的上下文以防止 SELinux 抱怨
问题描述
Vagrant 2.1.1
主机操作系统:Windows 7 Pro
客户操作系统: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", type: "nfs"
我尝试使用fcontext
and以正常方式更改文件上下文restorecon
,但restorecon
只是默默地失败了。
如何设置同步文件/文件夹的上下文以避免 SELinux 错误?
我试过使用:mount_options
,但它们被忽略了。
例子:
config.vm.synced_folder "./www", "/var/www", type: "nfs", create: true, id: "sites", mount_options: ['vers=3', :udp, :nolock, :noatime, 'context=system_u:object_r:httpd_sys_content_t:s0']
也许我以错误的方式在挂载选项中添加上下文?
解决方案
您必须将 rsync 用于 vagrant 同步文件夹,因为不支持通过 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'"]
此解决方法假定您已根据本文使用 semanage 和 restorecon 持久且递归地设置httpd_sys_content_t。
已编辑:11/3/2018 遗憾的是,上述解决方案实际上并未同步文件,因为 rsync 并不能真正与寡妇主机一起使用。以下是我对解决方法的发现和结论:
https://github.com/hashicorp/vagrant/issues/9827#issuecomment-435622888
推荐阅读
- css - 图像中的图像(徽章) css woocommerce 存档
- google-assistant-sdk - 有什么方法可以在我的项目中使用谷歌双工/或者有任何可用的 Api
- c++ - MSVC 和 g++ 中的不同行尾
- javascript - 使用 React-Testing-Library 模拟 ArrowRight 事件
- flutter - Flutter RootRestorationScope 不恢复最后一个根
- sql - 如何使用窗口函数来引用较新的记录?
- go - 导入尚未推送的文件
- cobol - COBOL 语法的含义:行首的哈希和点
- android - 模拟器错误:AdbHostServer.cpp:83:android studio 4.1.1 中的 adb 协议错误(无法读取状态长度)
- python - 与 Dropbox 集成的家庭监控