1

我们要禁用oc get/describeforsecrets以防止令牌登录

当前政策禁止创建、更新、删除但不禁止查看机密

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\": \"\ ",\"资源\":\"秘密\",\"版本\":\"v1\"},\"uid\":\"748cdab2-1c1d-11ea-8b11-080027f8814d\",\"用户信息\": {\"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中的示例使用了resource.spec对象,但我认为它在我的input/AdmissionReview对象中不可用?

我在用

  • 迷你换档 1.24
  • openshift v3.9.0+2e78773-56
  • Kubernetes v1.9.1+a0ce1bc657
  • etcd 3.2.16
4

1 回答 1

3

Kubernetes 中的准入控制不允许您控制get. 它只允许您控制createupdatedeleteconnect验证 webhook及其后代 RuleWithOperations(没有方便的链接)的 API 文档并没有说明这一点,但引入 API 访问的文档明确说明了这一点。

要控制get,您需要使用授权。您可以使用RBAC来限制谁可以使用get任何Secrets. 要使用 OPA 进行授权,您需要授权 webhook 模式

在您链接到的 Andrew 的代码中,他使用的是授权 webhook,而不是准入控制 webhook。这就是为什么他使用的某些数据input与您从准入控制 webhook 中看到的数据不同的原因。快速查看他的文章,您似乎需要按照他的指示启用授权

于 2019-12-17T01:10:16.133 回答