Webhook模式
浏览 0
扫码
分享
2019-10-27 17:16:53
origin_last_modified:2018-10-01 15:59(#9696) 译文原文 英文原文
版权声明:本文为 码农文档 原创译文,遵循 CC 4.0 BY-NC-SA 版权协议,转载请附上原文出处链接和本声明。
公告:如果您也想加入翻译队伍,或者您有相关中文文档想要贡献给大家,请联系 ,谢谢!
WebHook是一个HTTP回调:当事情发生时发送一个HTTP POST请求;通过HTTP POST发送一个简单的事件通知。当某些事情发生时,实现webhook的web应用程序将向URL发送一条消息。
当指定时,Webhook模式将吏Kubernetes在确定用户权限时查询外部REST服务。
配置文件格式
Webhook模式需要一个HTTP配置文件,由–authorization-webhook-config-file=SOME_FILENAME 选项指定。
配置文件使用kubeconfig文件格式。在文件中,users指的是API服务器webhook,clusters指的是远程服务。
一个使用HTTPS客户端认证的配置示例:

# Kubernetes API version
apiVersion: v1
# kind of the API object
kind: Config
# clusters refers to the remote service.
clusters:
– name: name-of-remote-authz-service
cluster:
# CA for verifying the remote service.
certificate-authority: /path/to/ca.pem
# URL of remote service to query. Must use ‘https’. May not include parameters.
server: https://authz.example.com/authorize
# users refers to the API Server’s webhook configuration.
users:
– name: name-of-api-server
user:
client-certificate: /path/to/cert.pem # cert for the webhook plugin to use
client-key: /path/to/key.pem # key matching the cert
# kubeconfig files require a context. Provide one for the API Server.
current-context: webhook
contexts:
– context:
cluster: name-of-remote-authz-service
user: name-of-api-server
name: webhook
请求载荷
当面临授权决策时,API服务器会POST一个JSON序列化的authorization.k8s.io/v1beta1 SubjectAccessReview 对象。此对象包含描述用户请求的字段,以及有关正在访问的资源或请求属性的详细信息。
注意,webhook API对象与其他Kubernetes API对象遵循相同的版本控制兼容性规则。实现者应该意识到beta对象更松散的兼容性承诺,并检查请求的apiVersion字段,以确保正确反序列化。另外,API服务器必须启用 authorization.k8s.io/v1beta1 API扩展组(–runtime-config=authorization.k8s.io/v1beta1=true)。
一个示例请求体:

{
“apiVersion”: “authorization.k8s.io/v1beta1”,
“kind”: “SubjectAccessReview”,
“spec”: {
“resourceAttributes”: {
“namespace”: “kittensandponies”,
“verb”: “get”,
“group”: “unicorn.example.org”,
“resource”: “pods”
},
“user”: “jane”,
“group”: [
“group1”,
“group2”
]
}
}
远程服务将填充请求的status字段,并响应允许或不允许访问。响应体的spec字段将被忽略,并且可以忽略。允许访问的响应将返回如下内容:

{
“apiVersion”: “authorization.k8s.io/v1beta1”,
“kind”: “SubjectAccessReview”,
“status”: {
“allowed”: true
}
}
若要禁止访问,远程服务将返回:

{
“apiVersion”: “authorization.k8s.io/v1beta1”,
“kind”: “SubjectAccessReview”,
“status”: {
“allowed”: false,
“reason”: “user does not have read access to the namespace”
}
}
访问非资源路径的方式如下:

{
“apiVersion”: “authorization.k8s.io/v1beta1”,
“kind”: “SubjectAccessReview”,
“spec”: {
“nonResourceAttributes”: {
“path”: “/debug”,
“verb”: “get”
},
“user”: “jane”,
“group”: [
“group1”,
“group2”
]
}
}
非资源路径包括: /api、 /apis、 /metrics、 /resetMetrics、 /logs、 /debug、 /healthz、 /swagger-ui/、 /swaggerapi/、 /ui和 /version。客户端需要访问/api、/api/*、/apis、/apis/*和/version来发现服务器上有哪些资源和版本。在不限制对REST API的访问的情况下,可以禁止访问其他非资源路径。
有关进一步的文档,请参阅authorization.v1beta1 API对象和webhook.go。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/211306.html原文链接:https://javaforall.net
