【发布时间】:2019-04-19 19:26:23
【问题描述】:
我在 kubernetes API 前面添加了一个代理,以便使用自制的身份验证系统对用户进行身份验证(以及其他操作)。
我已经修改了我的 kube 配置,让 kubectl 访问代理。代理有自己的 kubeconfig 和有效的证书授权数据,所以我不需要任何凭据。
到目前为止一切正常,这是我在本地需要的最低配置:
clusters:
- cluster:
server: http://localhost:8080
name: proxy
contexts:
- context:
cluster: proxy
name: proxy
current-context: proxy
现在身份验证应该基于令牌,我希望能够作为 kubectl 请求标头的一部分传递。
我尝试了多种配置,在kubeconfig中添加了一个带有令牌的用户,例如
clusters:
- cluster:
server: http://localhost:8080
name: proxy
contexts:
- context:
cluster: proxy
user: robin
name: proxy
current-context: proxy
users:
- name: robin
user:
token: my-token
或指定身份验证提供者,例如
clusters:
- cluster:
server: http://localhost:8080
name: proxy
contexts:
- context:
cluster: proxy
user: robin
name: proxy
current-context: proxy
users:
- name: robin
user:
auth-provider:
config:
access-token: my-token
我什至在没有任何用户的情况下尝试过,只需将我的令牌添加为首选项的一部分,因为我只想在标题中包含令牌
clusters:
- cluster:
server: http://localhost:8080
name: proxy
contexts:
- context:
cluster: proxy
name: proxy
current-context: proxy
preferences:
token: my-token
但我从来没有看到 my-token 作为代理端请求标头的一部分。转储请求,我得到的只是:
GET /api/v1/namespaces/default/pods?limit=500 HTTP/1.1
Host: localhost:8080
Accept: application/json;as=Table;v=v1beta1;g=meta.k8s.io, application/json
Accept-Encoding: gzip
User-Agent: kubectl/v1.11.0 (darwin/amd64) kubernetes/91e7b4f
我显然在这里遗漏了一些东西,kubectl 怎么能不在其标头中传递用户信息?假设我没有代理,“kubectl -> kubernetes”令牌身份验证如何工作?
如果有人在 kubernetes 和客户端之间添加这种身份验证层有任何经验,我可以使用一些帮助:)
【问题讨论】:
标签: proxy kubernetes kubectl