我需要为Kubernetes实现自定义身份验证和授权模块。这将必须通过网络挂钩来完成。
authentication和authorisation Webhooks的文档描述了启动API Server所需的配置文件。
对于身份验证和授权,配置文件看起来相同,如下所示:
# clusters refers to the remote service.
clusters:
- name: name-of-remote-authn-service
cluster:
certificate-authority: /path/to/ca.pem # CA for verifying the remote service.
server: https://authn.example.com/authenticate # URL of remote service to query. Must use 'https'.
# 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-authn-service
user: name-of-api-sever
name: webhook
我可以看到
clusters
部分引用了远程服务,即它正在定义webhook,从而回答了API Server需要回答的问题:“当需要authn / authz决定时,何时击中URL端点是什么?我通过HTTPS连接,HTTP是Webhook的TLS证书的CA权威,因此我知道我可以信任远程Webhook?”我不确定
users
部分。 client-certificate
和client-key
字段的目的是什么?该文件中的注释显示为“供webhook插件使用的证书”,但是由于此配置文件是提供给API服务器而不是Web钩子(Hook)的,因此我不明白这是什么意思。这是一个证书,该证书将允许webhook服务验证API服务器将由此发起的连接吗?即客户端证书需要进入Webhook服务器的信任库?这两个假设是否正确?
最佳答案
Kubernetes Webhook使用的是two-way SSL authentication,因此users
部分中的字段用于配置用于“客户端身份验证”的证书。clusters
部分的配置仅能以一种正常的SSL身份验证正常工作,即服务器(这是您的webhook模块)将使用配置的证书来验证客户端(这是Kubernetes)的请求。
只要您在users
部分中配置了证书,客户端(Kubernetes)就可以验证服务器(webhook模块)的响应,就像单向SSL的反向CA身份验证一样。