linux - Vagrant:设置同步文件夹的上下文以防止 SELinux 报错

标签 linux vagrant selinux vagrant-windows

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"

我尝试使用 fcontextrestorecon 以正常方式更改文件上下文,但是 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/

相关文章:

linux - zabbix 监控自定义脚本值

linux - 如何在 bash shell 脚本中添加另一个 "for"循环?

vagrant - 是否可以重新启动或重置由 test-kitchen 创建的 vagrant 实例?

python - 以编程方式在 Vagrant 中获取 vm 的 IP 地址

linux - selinux context_new 返回值

node.js - 从 .desktop 文件运行 Node

docker - vmware中 Vagrant 中的docker中的uwsgi-未创建套接字

android - Android 系统服务 : how to setup? 的 SELinux 策略定义

linux - SELINUX 阻止 php-fpm 和 nginx 一起工作?

python - 是否可以使用来自非登录 shell 的单行命令从 bash 登录 shell 执行 python 脚本?