【发布时间】:2022-12-17 17:39:26
【问题描述】:
我正在将 OPA Gatekeeper 与 Kubernetes 一起使用,并试图定义一个模板和一个约束,以阻止具有某些字段的请求。我这样做的方法是阻止模板中该字段的路径,但是我似乎在设置此设置时遇到了一些问题。 我的模板如下:
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: test-template
spec:
crd:
spec:
names:
kind: Test-Template
validation:
openAPIV3Schema:
properties:
errorPath:
type: object
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package testtemplate
violation[{"msg": msg}] {
input.parameters.errorPath == "error"
msg := sprintf("The name %v is not allowed", [input.parameters.errorPath])
}
而约束是:
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: Test-Template
metadata:
name: test-constraint
spec:
parameters:
invalidPath: input.review.object.spec.resourceRef
部署约束错误:
body 中的 spec.parameters.invalidPath 必须是对象类型:“string”
如果输入 spec.resoureRef 设置为错误,我的目标是让它失败。
【问题讨论】:
标签: opa open-policy-agent rego