1

我正在使用带有 lxc-container-default-with-nesting 配置文件的嵌套 LXC,如下所示。

profile lxc-container-default-with-nesting flags=(attach_disconnected,mediate_deleted) {
  #include <abstractions/lxc/container-base>
  #include <abstractions/lxc/start-container>

#  Uncomment the line below if you are not using cgmanager
#  mount fstype=cgroup -> /sys/fs/cgroup/**,

  deny /dev/.lxc/proc/** rw,
  deny /dev/.lxc/sys/** rw,
  mount fstype=proc -> /var/cache/lxc/**,
  mount fstype=sysfs -> /var/cache/lxc/**,
  mount options=(rw,bind),
}

我对以下行有两个问题。

  mount fstype=proc -> /var/cache/lxc/**,
  1. 为什么允许容器挂载 /proc 是安全的?

  2. 为什么容器需要在 /var/cache/lxc 下挂载 /proc ?

4

1 回答 1

2

嵌套容器配置

该配置文件允许您创建嵌套的LXC 容器,一个在另一个内部。默认情况下,这是禁用的,因为它绕过了一些默认的 cgroup 限制(更多信息在这里)。

通常,它会更改 apparmor 规则以允许 lxc 在容器内重新挂载某些系统资源(具有某些限制)。

lxc.container.conf

如果您查看man lxc.container.conf,本节将说明您可以编辑的proc安装方式设置。我认为proc:mixed默认使用(但我还没有证实这一点!)

  lxc.mount.auto
          specify which standard kernel file systems should be
          automatically mounted. This may dramatically simplify
          the configuration. The file systems are:

          · proc:mixed (or proc):
            mount /proc as read-write, but
            remount /proc/sys and
            /proc/sysrq-trigger read-only
            for security / container isolation purposes.

          · proc:rw: mount
            /proc as read-write

非特权 LXC

顺便说一句,如果您不使用非特权 LXC,则应该使用。认真的。它增加了一个额外的保护层,限制root容器中的用户可以做什么(它实际上将它映射到容器外的非 root 用户)。这提供了额外的保护层,/proc以防万一发生某些事情违反了apparmour规则。

至于它为什么使用/var/cache/lxc,我不知道。猜测是它与不冲突有关cgmanager。如果您对推理感兴趣,查看源代码可能是一个不错的起点。

于 2016-11-05T22:55:28.553 回答