我知道这个问题被问过很多次,但是关于docker的一切,这次是crio。

CentOS Linux release 7.6
CRI-O Version: 1.16.1
Kubernetes: v1.16.3
KubeAdm: v1.16.3

CoreDNS Pod处于Error / CrashLoopBackOff状态,并且audit.log显示selinux阻止CoreDNS从/ var / lib / kubelet / container_id / volumes /中读取
type=AVC msg=audit(1576203392.727:1431): avc: denied { read } for pid=15866 comm="coredns" name="Corefile" dev="dm-0" ino=35369330 scontext=system_u:system_r:container_t:s0:c307,c586 tcontext=system_u:object_r:var_lib_t:s0 tclass=file permissive=1

type=AVC msg=audit(1576203392.727:1431): avc: denied { open } for pid=15866 comm="coredns" path="/etc/coredns/..2019_12_13_02_13_30.965446608/Corefile" dev="dm-0" ino=35369330 scontext=system_u:system_r:container_t:s0:c307,c586 tcontext=system_u:object_r:var_lib_t:s0 tclass=file permissive=1

type=AVC msg=audit(1576203393.049:1432): avc: denied { open } for pid=15866 comm="coredns" path="/var/run/secrets/kubernetes.io/serviceaccount/..2019_12_13_02_13_30.605147375/token" dev="tmpfs" ino=124481 scontext=system_u:system_r:container_t:s0:c307,c586 tcontext=system_u:object_r:tmpfs_t:s0 tclass=file permissive=1

如果我使用的Docker早于1.7,则可以正常工作,我认为这可能与使用z / Z选项安装卷的补丁有关。

我可以在下面添加策略,但这会损害安全性。
module coredns 0.1;

require {
  type tmpfs_t;
  type container_t;
  type var_lib_t;

  class file { open read };
}

allow container_t tmpfs_t:file open;
allow container_t var_lib_t:file { open read };

有更好的解决方案吗?就像docker,只要付出一点努力,就不会损害安全性。

最佳答案

在主机上执行以下操作

chcon -R -t container_file_t
/ var / lib / kubelet / container_id / volumes

这将更改主机卷上的标签,以供容器SELinux标签访问。

我不知道处理 secret 传递的好方法。但是添加

允许container_t tmpfs_t:文件打开;

可能是最好的。

我相信,在OpenShift中,这些都是自动处理的。虽然我不在那个级别的堆栈上工作。

关于kubernetes - 使用crio并启用selinux时,coredns无法启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59463038/

10-15 20:19