在kubernetes之前添加身份验证代理

时间:2018-11-16 15:21:18

标签: proxy kubernetes kubectl

我在kubernetes API之前添加了一个代理,以便使用自制的身份验证系统对用户进行身份验证(包括其他操作)。

enter image description here

我已经修改了我的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

或指定一个auth-provider,例如

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

但是我从来没有看到我的令牌作为代理端的请求标头的一部分。转储请求,我得到的只是:

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和客户端之间添加这种身份验证层有任何经验,我可以使用一些帮助:)

1 个答案:

答案 0 :(得分:2)

令牌凭证仅通过TLS保护的连接发送。服务器必须为https:// ...