【发布时间】:2021-12-06 04:13:05
【问题描述】:
在使用Kubernetes准入控制器ValidatingWebhookConfiguration时,我想跳过对Kubernetes Controllers等内部请求的拦截。
更具体地说,我希望验证 webhook 匹配的唯一请求是用户通过 Kubctl/API 等发出的请求。
有可能吗?
【问题讨论】:
标签: kubernetes kube-controller-manager
在使用Kubernetes准入控制器ValidatingWebhookConfiguration时,我想跳过对Kubernetes Controllers等内部请求的拦截。
更具体地说,我希望验证 webhook 匹配的唯一请求是用户通过 Kubctl/API 等发出的请求。
有可能吗?
【问题讨论】:
标签: kubernetes kube-controller-manager
根据Webhook request and response,您的webhook 将收到一个包含UserInfo 字段的AdmissionRequest 对象。其中有 Username、Groups 等字段,可能对解决您的问题有用。
...
"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"]
}
},
...
【讨论】:
kubectl 或k8s 控制器对某些资源进行操作的人正在使用相同的Rest API(API 服务器)来做他们需要的事情。 API 服务器无法区分来自控制器或通过kubectl 发送的请求 - 本质上,您可以模拟来自两者的相同请求。正因为如此 - 我怀疑有没有办法像你描述的那样做。我想如果你描述一下你想通过这个实现什么会更有帮助 - 也许有人会提供更好的方法?