我想拒绝所有码头注册,除了我自己的一个。我正在寻找一个码头注册和他们的形象某种政策。
例如,我的注册表名是registry.my.com
。我想让kubernetes只从registry.my.com
拉/运行映像,所以:
image: prometheus:2.6.1
或任何其他应被拒绝,而:
image: registry.my.com/prometheus:2.6.1
不应该。
有办法做到吗?
我想拒绝所有码头注册,除了我自己的一个。我正在寻找一个码头注册和他们的形象某种政策。
例如,我的注册表名是registry.my.com
。我想让kubernetes只从registry.my.com
拉/运行映像,所以:
image: prometheus:2.6.1
或任何其他应被拒绝,而:
image: registry.my.com/prometheus:2.6.1
不应该。
有办法做到吗?
3条答案
按热度按时间8nuwlpux1#
Admission Controllers是你要找的。
准入控制器拦截操作以验证在api服务器提交操作之前应该发生什么。
一个例子是ImagePolicyWebhook,它是一个准入控制器,用于拦截Image操作以验证它是应该被允许还是拒绝。
它将使用如下有效负载调用REST端点:
API回答为允许:
或拒绝:
端点可以是Lambda函数或在集群中运行的容器。
这个github repo github.com/flavio/kube-image-bouncer实现了一个示例,使用ImagePolicyWebhook拒绝使用标签“Latest”的容器。
还有一个选项是在启动时使用标志
registry-whitelist
来传递一个逗号分隔的允许注册表列表,ValidatingAdmissionWebhook将使用该列表来验证注册表是否被列入白名单。。
另一个备选方案是项目Open Policy Agent [OPA]。
OPA是一个灵活的引擎,用于根据规则创建策略以匹配资源,并根据这些表达式的结果做出决策。它是一个变异和验证webhook,上面提到的准入控制器会调用它来匹配Kubernetes API服务器请求。总之,操作的工作方式与上面描述的类似。唯一的区别是规则是作为配置而不是代码来编写的。2上面的重写器使用OPA的例子类似于:
上述内容可转化为:* 拒绝容器映像与以下注册表不匹配的任何pod
registry.acmecorp.com
*vuktfyat2#
目前还不能用一个命令来启用或禁用,但有一些准入控制器可以使用。
如果您使用的是redhat平台,并且只在RHEL上运行docker或kubernetes节点,并将RHEL docker作为容器运行时,则可以将那里的注册表列入白名单。
将Docker注册表列入白名单
您可以指定Docker注册中心的白名单,以便精心设计一组可供OpenShift容器平台用户下载的映像和模板。您可以将这组经过精心设计的映像和模板放置在一个或多个Docker注册中心中,然后添加到白名单中。使用白名单时,OpenShift容器平台中仅可访问指定的注册中心,默认情况下,所有其他注册中心将被拒绝访问。
要配置白名单:
编辑
/etc/sysconfig/docker
文件以阻止所有注册表:您可能需要取消注解BLOCK_REGISTRY行。
在同一文件中,添加要允许访问的注册表:
还有一个github项目:
https://github.com/flavio/kube-image-bouncer
你可以用它来列出注册表白名单。我认为注册表白名单已经在它里面实现了,你只需要在你要运行二进制文件的时候给它提供白名单。
b1uwtaje3#
如果你正在处理Azure管理的AKS集群,你可以使用Azure策略。这里是一个总结。我在我的博客文章中写了更详细的内容,可以在here中找到。
激活订阅上的Policy Insights资源提供程序
启用AKS Azure策略加载项
分配一个仅允许该使用情形的内置策略
有几件事值得注意:
playground
,仅用于演示