我们要禁用 oc get/describe
对于 secrets
防止 token 登录
当前政策禁止创建、更新、删除但不禁止查看 secret
package admission
import data.k8s.matches
# Deny all user for doing secret ops except policyadmin
deny[query] {
matches[[resource]]
not "policyadmin" == resource.userInfo.username
"Secret" == resource.kind.kind
msg := sprintf("Custom Unauthorized user: %v", [resource.userInfo.username])
query = {
"id": "policy-admin-for-secret-only",
"resource": {
"kind": kind,
"namespace": namespace,
"name": name
},
"resolution": {
"message": msg
},
}
}
资源对象中的数据只是:
{\"kind\": {\"group\": \"\", \"kind\": \"Secret\", \"version\": \"v1\"}, \"name\": \"s5-token-n6v6q\", \"namespace\": \"demo\", \"operation\": \"DELETE\", \"resource\": {\"group\": \"\", \"resource\": \"secrets\", \"version\": \"v1\"}, \"uid\": \"748cdab2-1c1d-11ea-8b11-080027f8814d\", \"userInfo\": {\"groups\": [\"system:cluster-admins\", \"system:masters\", \"system:authenticated\"], \"username\": \"system:admin\"}
https://github.com/raffaelespazzoli/openshift-opa/blob/master/examples/authorization-webhooks/unreadable_secrets.rego 中的示例使用 资源.spec 对象,但我认为它在我的
input/AdmissionReview
中不可用目的?我在用
最佳答案
Kubernetes 中的准入控制不允许您控制 get
.它只让你控制create
, update
, delete
, 和 connect
. validating webhook 的 API 文档及其后代 RuleWithOperations(没有方便的链接)并没有说明这一点,但是 docs introducing API access明确说明。
控制get
, 你需要使用 authorization .您可以使用 RBAC限制谁可以get
Secret
中的任何一个s。要使用 OPA 进行授权,您需要 authorization webhook mode .
在您链接到的 Andrew 的代码中,他使用的是授权 webhook,而不是准入控制 webhook。这就是为什么他使用来自input
的一些数据的原因。与您从准入控制 webhook 中看到的不同。快速浏览一下他的文章,看来您需要按照他的指示来 Enable Authorization .
关于kubernetes - 如何通过开放策略拒绝在 openshift 中查看/获取操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59332049/