今天会来实作OPA的配置,由於之前有透过rancher管理了k8s环境,所以就可以从rancher的套件管理项目中找到OPA的套件,透过rancher安装好OPA後可以在rancher的介面上操作OPA的yaml如下
预设rancher提供了两个范例(repo来源限制、需要label才能布署),也可以自己在constraints和template中撰写需要的规则和要受影响的对象,我这边额外做一个image不可以为latest的范例来demo OPA
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
annotations:
meta.helm.sh/release-name: rancher-gatekeeper
meta.helm.sh/release-namespace: cattle-gatekeeper-system
generation: 5
labels:
app.kubernetes.io/managed-by: Helm
name: imagetag
spec:
crd:
spec:
names:
kind: k8sallowedimagetag
validation:
openAPIV3Schema:
properties:
repos:
items:
type: string
type: array
targets:
- rego: |
package k8sblocklatesttag
violation[{"msg": msg, "details": {}}]{
input.review.object.kind == "Pod"
imagename := input.review.object.spec.containers[_].image
endswith(imagename,"latest")
msg := "Images with tag the tag \"latest\" is prohibited"
}
target: admission.k8s.gatekeeper.sh
配置完成後布署服务会发现pod会失败(一直是0个起不来)
describe deployment後就会发现被webhook阻挡并且原因是image tag不可以为latest的讯息唷(Images with tag the tag "latest" is prohibited),其实主要就是要在rego内撰写要怎麽检核yaml,通常常用的规则会是repo来源限制、image tag 和禁止latest、不允许privileged权限,撰写上其实网路上也有许多范例可以参考。
>>: 30-14 之 Domain Layer - Service
-什麽是风险? ISO 31000:2018 提供了有关管理组织面临的风险的指南。这些指南的应用可...
Github 连结 VSCode Marketplace Playground 推荐程度:⭐⭐⭐ ...
前言 昨天介绍了用grid-template-areas 来填格子 grid-template-ar...
前言 今天这个章节将要来实作 Deploying PHP Guestbook application...
各位中秋节连假愉快,我今天坐客运,还包车了呢,司机先生只载我一个人,运气不错,好啦今天也要继续努力解...