【问题标题】:How to skip Kubernetes Controller requests from ValidatingWebhook如何跳过来自 ValidatingWebhook 的 Kubernetes 控制器请求
【发布时间】:2021-12-06 04:13:05
【问题描述】:

在使用Kubernetes准入控制器ValidatingWebhookConfiguration时,我想跳过对Kubernetes Controllers等内部请求的拦截。

更具体地说,我希望验证 webhook 匹配的唯一请求是用户通过 Kubctl/API 等发出的请求。

有可能吗?

【问题讨论】:

    标签: kubernetes kube-controller-manager


    【解决方案1】:

    根据Webhook request and response,您的webhook 将收到一个包含UserInfo 字段的AdmissionRequest 对象。其中有 UsernameGroups 等字段,可能对解决您的问题有用。

    ...
        "userInfo": {
          # Username of the authenticated user making the request to the API server
          "username": "admin",
          # UID of the authenticated user making the request to the API server
          "uid": "014fbff9a07c",
          # Group memberships of the authenticated user making the request to the API server
          "groups": ["system:authenticated","my-admin-group"],
          # Arbitrary extra info associated with the user making the request to the API server.
          # This is populated by the API server authentication layer and should be included
          # if any SubjectAccessReview checks are performed by the webhook.
          "extra": {
            "some-key":["some-value1", "some-value2"]
          }
        },
    ...
    

    【讨论】:

    • 是的,我知道这一点。但不幸的是,它在这里并没有真正的帮助,因为我想完全跳过这些请求,而不是通过 webhook 传递它们。类似于 objectSelector 的东西
    • 使用kubectl 或k8s 控制器对某些资源进行操作的人正在使用相同的Rest API(API 服务器)来做他们需要的事情。 API 服务器无法区分来自控制器或通过kubectl 发送的请求 - 本质上,您可以模拟来自两者的相同请求。正因为如此 - 我怀疑有没有办法像你描述的那样做。我想如果你描述一下你想通过这个实现什么会更有帮助 - 也许有人会提供更好的方法?
    • 我只想让webbook只拦截用户的策略控制请求。来自控制器的请求是系统请求,所以我不想管理它们中的任何一个。排除控制器请求的一种方法是在它们到达 webhook 服务器后跳过它们,但这只会给服务器带来不必要的开销。我仍然认为区分系统请求和用户的请求会非常有用。
    • 我明白你的意思——但我认为在 k8s 中没有办法做你想做的事。它只是没有那个功能。
    猜你喜欢
    • 2018-12-26
    • 2018-04-07
    • 1970-01-01
    • 2013-11-29
    • 2012-01-03
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    相关资源
    最近更新 更多