kubernetes - 如何通过开放策略拒绝在 openshift 中查看/获取操作?

标签 kubernetes openshift open-policy-agent rego

我们要禁用 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 中不可用目的?

我在用
  • minishift 1.24
  • openshift v3.9.0+2e78773-56
  • Kubernetes v1.9.1+a0ce1bc657
  • etcd 3.2.16
  • 最佳答案

    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/

    相关文章:

    Azure Kubernetes - Azure Monitor 和 Sidecar 日志传送?

    authentication - 用户 "system"无法列出集群中的所有服务

    java - 如何正确部署 webapp 到 openshift?

    open-policy-agent - OPA单元测试失败,如何输出响应变量?

    open-policy-agent - 即使比较结果为 false,OPA/rego 结果也为 true

    kubernetes - Minishift Kubernetes 仪表板抛出错误 : services "kubernetes-dashboard" not found

    kubernetes - 为什么 helm 需要集群端组件(tiller)?

    go - 无法加载 github.com/open-policy-agent/opa/capability : no Go source files

    amazon-web-services - 更改Kops部署样式

    Openshift在线问题: pod with persistent volume failed scheduling