【问题标题】:Vagrant: Set context of synced folder to prevent SELinux from complainingVagrant:设置同步文件夹的上下文以防止 SELinux 抱怨
【发布时间】:2018-10-21 20:25:11
【问题描述】:

流浪者 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"

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

也许我以错误的方式在挂载选项中添加上下文??

【问题讨论】:

    标签: linux vagrant selinux vagrant-windows


    【解决方案1】:

    您必须对 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

    【讨论】:

      猜你喜欢
      • 2016-02-08
      • 1970-01-01
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 2016-06-18
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多