Dovecot lxc apparmor 被拒絕 (Buster)

Dovecot lxc apparmor 被拒絕 (Buster)

我無法在 Buster 上的 lxc 中運行 dovecot。我關閉 PrivateTmp,但這還不夠......仍然:

[ 4850.883141] audit: type=1400 audit(1563803461.322:34): apparmor="DENIED" operation="mount" info="failed flags match" error=-13 profile="lxc-container-default-cgns" name="/" pid=23810 comm="(dovecot)" flags="rw, rslave"

答案1

您是否嘗試過使用無限制的 AppArmor 值?

lxc.apparmor.profile: unconfined

將其設定到 /etc/pve/lxc/CTID.conf 中

答案2

遺憾的是,如果不透過主機上的 AppArmor 授予必要的權限,則更新服務單元以避免 PrivateTmp 在 LXC 中不起作用。

在探索了這些選項之後,似乎不再有一種方法可以完全在容器內完成這項工作。

為了使其工作,我刪除了容器中的所有編輯(因此擺脫了 PrivateTmp 配置)並開始修改 AppArmor 策略,如下所示:

  1. 在主機上,建立一個新的 AppArmor 策略/etc/apparmor.d/lxc/lxc-dovecot並使用以下內容填充它:

    # Do not load this file. Rather, load /etc/apparmor.d/lxc-containers, which
    # will source all profiles under /etc/apparmor.d/lxc
    profile lxc-container-dovecot flags=(attach_disconnected,mediate_deleted) {
      #include <abstractions/lxc/container-base>
      #include <abstractions/lxc/start-container>
      deny mount fstype=devpts,
      mount fstype=cgroup -> /sys/fs/cgroup/**,
      mount fstype=cgroup2 -> /sys/fs/cgroup/**,
      mount options=(rw,bind),
      mount options=(rw,rbind),
      mount options=(rw,rshared),
      mount options=(ro,nosuid,noexec,remount,bind,strictatime),
    }
    
  2. 重新載入 AppArmor

    $ systemctl restart apparmor.service
    
  3. 透過將以下行新增至 LXC 容器配置中,將容器設定為使用新設定文件,通常位於/var/lib/lxc/$container/config

    # Add or edit the following line to set the apparmor profile used
    lxc.apparmor.profile = lxc-container-dovecot
    
  4. 重新啟動您的容器:

    $ lxc-stop -n $container && sleep 1 && lxc-start -d -n $container
    

相關內容