AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 728801
Accepted
mnj
mnj
Asked: 2022-12-18 08:06:47 +0800 CST2022-12-18 08:06:47 +0800 CST 2022-12-18 08:06:47 +0800 CST

在容器绑定挂载上设置 SELinux z/Z 选项的主机范围后果

  • 772

在运行带有卷挂载的 podman 容器时,通常需要将:z(或:Z)参数添加到挂载路径。这是由于 SELinux 及其类型强制。该参数的作用是改变挂载文件的类型。我认为这实际上是一个非常危险的操作,如果我们挂载一些需要应用其他 SELinux 类型的文件,它可能会导致一些问题。让我们考虑一个 apache httpd 服务器的例子。据我所知,httpd 只能从标有适当标签(例如httpd_file_t或其他无关紧要)的目录中提供文件。如果我启动一个 podman 容器并将 httpd 的www目录挂载到它(使用:z)会发生什么?上下文将更改为container_file_t键入,我相信服务器将停止工作(它将无法访问 中的文件www)。

我的理解正确吗?

docker
  • 1 1 个回答
  • 14 Views

1 个回答

  • Voted
  1. Best Answer
    Edward
    2022-12-19T04:17:16+08:002022-12-19T04:17:16+08:00

    你的理解是正确的。来自 Docker 手册(与 podman 基本相同):

    Configure the selinux label
    
    If you use selinux you can add the z or Z options to modify the selinux label of the host file or directory being mounted into the container. This affects the file or directory on the host machine itself and can have consequences outside of the scope of Docker.
    
        The z option indicates that the bind mount content is shared among multiple containers.
        The Z option indicates that the bind mount content is private and unshared.
    
    Use extreme caution with these options. Bind-mounting a system directory such as /home or /usr with the Z option renders your host machine inoperable and you may need to relabel the host machine files by hand.
    

    这意味着如果您将某个主机目录绑定挂载到 Docker,SELinux 上下文标签将被更改以确保该特定目录只能从该特定容器 ( :Z) 或所有容器 ( :z) 访问。

    因为这些操作是在主机文件系统本身上执行的,所以它们会在容器虚拟化范围之外产生影响。您的示例很好:当绑定安装主机 webroot 时,标准httpd_sys_(rw_)content_t将被替换。然后主机上的 Apache 将拒绝为该 webroot 提供服务。

    幸运的是,使用自定义策略模块可以轻松解决这个问题。

    使用:zor:Z并启动 Docker/podman。确保它有效。现在将 SELinux 设置为允许使用setenforce 0. 然后启动 Apache。它会工作(因为 SELinux 是允许的),但 AVC 拒绝将记录在审计日志中。

    # use the output of ausearch to create a policy that allows this. This is the dry-run version
    ausearch -m avc -ts recent | audit2allow -a
    # If you're satisfied that this is indeed a module you want to add to the SELinux system,
    # pick a policyname (use a custom prefix like mnj-) and run
    ausearch -m avc -ts recent | audit2allow -a -M mnj-[policyname]
    

    这会在/etc/selinux/targeted/modules/active/modules.

    要安装和激活此模块,请运行:

    semodule -i mnj-[policyname].pp

    现在重新启用 SELinux setenforce 1:。Apache 现在将能够再次为 webroot 提供服务。

    • 1

相关问题

  • 无法从私有注册表中提取 kubernetes 中的图像

  • 连接到 docker 主机!

  • Dockerfile 中 VOLUME 指令的目的是什么?

  • 如何在 RHEL 7 上离线安装 docker?

  • 我只需要运行这个脚本文件一次吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve