为什么 "violation" 和 "deny" 之间的确切区别在 OPA/Rego 中?
Why is the exact difference between "violation" and "deny" in OPA/Rego?
在打开策略代理中 (https://www.openpolicyagent.org/)
关于 Kubernetes,取决于使用的引擎:
或
- 带有 kube-mgmt 的普通 OPA:https://www.openpolicyagent.org/docs/latest/kubernetes-introduction/#how-does-it-work-with-plain-opa-and-kube-mgmt
有多种定义验证规则的方法:
在 Gatekeeper 中使用 violation
。请在此处查看示例规则:https://github.com/open-policy-agent/gatekeeper-library/tree/master/library/general
在普通 OPA 示例中,deny
规则,请参见此处的示例:
https://www.openpolicyagent.org/docs/latest/kubernetes-introduction/#how-does-it-work-with-plain-opa-and-kube-mgmt
好像是OPA约束框架定义的violation
:
https://github.com/open-policy-agent/frameworks/tree/master/constraint#rule-schema
那么这背后的确切“故事”是什么,为什么不同引擎之间不一致?
备注:
本文档反映了这一点:https://www.openshift.com/blog/better-kubernetes-security-with-open-policy-agent-opa-part-2
这里提到了如何在脚本中支持互操作性:https://github.com/open-policy-agent/gatekeeper/issues/1168#issuecomment-794759747
https://github.com/open-policy-agent/gatekeeper/issues/168这个issue中提到的迁移,只是因为“干运行”的支持吗?
普通 OPA 对您选择如何命名规则没有意见。使用 deny
只是教程中的约定。真正的 Kubernetes 准入审查响应看起来像这样:
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"response": {
"allowed": false,
"status": {
"reason": "container image refers to illegal registry (must be hooli.com)"
}
}
}
因此,无论您选择为规则命名,在将响应发送回 Kubernetes API 服务器之前,都需要将其转换为类似上述的响应。如果您向下滚动 Kubernetes 入门文档的 Detailed Admission Control Flow 部分,您将看到这种转换是如何在 system.main
规则中完成的:
package system
import data.kubernetes.admission
main = {
"apiVersion": "admission.k8s.io/v1beta1",
"kind": "AdmissionReview",
"response": response,
}
default response = {"allowed": true}
response = {
"allowed": false,
"status": {
"reason": reason,
},
} {
reason = concat(", ", admission.deny)
reason != ""
}
请特别注意“原因”属性是如何通过连接 admission.deny
:
中找到的所有字符串来构建的
reason = concat(", ", admission.deny)
如果您更愿意使用 violation
或使用普通 OPA 的其他规则名称,您可以在此处进行更改。
在打开策略代理中 (https://www.openpolicyagent.org/)
关于 Kubernetes,取决于使用的引擎:
或
- 带有 kube-mgmt 的普通 OPA:https://www.openpolicyagent.org/docs/latest/kubernetes-introduction/#how-does-it-work-with-plain-opa-and-kube-mgmt
有多种定义验证规则的方法:
在 Gatekeeper 中使用
violation
。请在此处查看示例规则:https://github.com/open-policy-agent/gatekeeper-library/tree/master/library/general在普通 OPA 示例中,
deny
规则,请参见此处的示例: https://www.openpolicyagent.org/docs/latest/kubernetes-introduction/#how-does-it-work-with-plain-opa-and-kube-mgmt
好像是OPA约束框架定义的violation
:
https://github.com/open-policy-agent/frameworks/tree/master/constraint#rule-schema
那么这背后的确切“故事”是什么,为什么不同引擎之间不一致?
备注:
本文档反映了这一点:https://www.openshift.com/blog/better-kubernetes-security-with-open-policy-agent-opa-part-2
这里提到了如何在脚本中支持互操作性:https://github.com/open-policy-agent/gatekeeper/issues/1168#issuecomment-794759747
https://github.com/open-policy-agent/gatekeeper/issues/168这个issue中提到的迁移,只是因为“干运行”的支持吗?
普通 OPA 对您选择如何命名规则没有意见。使用 deny
只是教程中的约定。真正的 Kubernetes 准入审查响应看起来像这样:
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"response": {
"allowed": false,
"status": {
"reason": "container image refers to illegal registry (must be hooli.com)"
}
}
}
因此,无论您选择为规则命名,在将响应发送回 Kubernetes API 服务器之前,都需要将其转换为类似上述的响应。如果您向下滚动 Kubernetes 入门文档的 Detailed Admission Control Flow 部分,您将看到这种转换是如何在 system.main
规则中完成的:
package system
import data.kubernetes.admission
main = {
"apiVersion": "admission.k8s.io/v1beta1",
"kind": "AdmissionReview",
"response": response,
}
default response = {"allowed": true}
response = {
"allowed": false,
"status": {
"reason": reason,
},
} {
reason = concat(", ", admission.deny)
reason != ""
}
请特别注意“原因”属性是如何通过连接 admission.deny
:
reason = concat(", ", admission.deny)
如果您更愿意使用 violation
或使用普通 OPA 的其他规则名称,您可以在此处进行更改。