我知道这个问题被问了很多次,但都是关于 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 

如果我使用比 1.7 新的 docker,它工作正常,我认为这可能与使用 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 容器文件_t /var/lib/kubelet/container_id/volumes

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

我不知道有什么好方法来处理 secret 的传递。但添加

允许container_t tmpfs_t:文件打开;

可能是最好的。

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


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!