我尝试使用pamhook执行kubernetes webhook身份验证。但是当apiserver试图联系它时,我在webhook上收到了TLS握手错误。
以下是我遵循的步骤:
apiserver IP:192.168.20.30 pam webhook服务器IP:192.168.20.50
> openssl genrsa -out ubuntuserver.key 2048 openssl req -new -key > ubuntuserver.key -out ubuntuserver.csr -config myconf.conf openssl > x509 -req -in ubuntuserver.csr -CA ca.crt -CAkey ca.key > -CAcreateserial -out ubuntuserver.crt -days 10000
./pam_hook-master -cert-file /root/newca/ubuntuserver.crt -key-file /root/newca/ubuntuserver.key -signing-key rootroot -bind-port 6000
I1109 07:21:41.388836 3882 main.go:327] Starting pam_hook on :6000
$cat webhook-config.yaml apiVersion: v1 clusters: - cluster: certificate-authority: /etc/kubernetes/pki/ca.crt server: https://192.168.20.50:6000/authenticate name: 192.168.20.50 users: - name: root user: client-certificate: /etc/kubernetes/pki/client.crt client-key: /etc/kubernetes/pki/client.key current-context: 192.168.20.50 contexts: - context: cluster: 192.168.20.50 user: root name: 192.168.20.50
中配置的api服务器清单文件
/etc/kubernetes/manifest/kube-apiserver.yaml
> ... > - --authentication-token-webhook-config-file=/etc/kubernetes/pki/webhook-config.yaml > - --runtime-config=authorization.k8s.io/v1beta1=true ...
apiserver重新启动。
通过请求pamhook服务器获取令牌。 (我是从我的主节点做到的)
$ curl https://192.168.20.50:6000/token --cacert /etc/kubernetes/pki/ca.crt -u root Enter host password for user 'root': eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIiLCJleHAiOjE1MTAyMjY3ODksImlhdCI6MTUxMDIyNjE4OSwiaXNzIjoiIiwidXNlcm5hbWUiOiJyb290In0.3LmHBy_anjR62WNqKICCx_b8YWFpF4HSKMWLmyORU0M
使用此令牌向apiserver发出请求,该令牌又应与webhook通信以提供身份验证。但我得到401错误。
$ curl -vvv --insecure -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIiLCJleHAiOjE1MTAyMjY3ODksImlhdCI6MTUxMDIyNjE4OSwiaXNzIjoiIiwidXNlcm5hbWUiOiJyb290In0.3LmHBy_anjR62WNqKICCx_b8YWFpF4HSKMWLmyORU0M" https://192.168.20.38:6443/api/ { "kind": "Status", "apiVersion": "v1", "metadata": { }, "status": "Failure", "message": "Unauthorized", "reason": "Unauthorized", "code": 401 }
webhook服务器上的消息是:
> 2017/11/09 07:50:53 http: TLS handshake error from 192.168.20.38:49712: remote error: tls: bad certificate
Document表示api服务器在其有效负载中发送带有令牌的http请求。如果我尝试使用令牌和ca.crt在curl中重新创建相同的调用,则会对其进行身份验证。
> $ curl -X POST https://192.168.20.50:6000/authenticate --cacert /etc/kubernetes/pki/ca.crt -d '{"ApiVersion":"authentication.k8s.io/v1beta1", "Kind": "TokenReview", "Spec":{"Token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIiLCJleHAiOjE1MTAyMjY3ODksImlhdCI6MTUxMDIyNjE4OSwiaXNzIjoiIiwidXNlcm5hbWUiOiJyb290In0.3LmHBy_anjR62WNqKICCx_b8YWFpF4HSKMWLmyORU0M"}}'
{" apiVersion":" authentication.k8s.io/v1beta1","种类":" TokenReview""状态" {"验证":真,"使用者" {"用户名":"根"" UID& #34;:" 0""组":["根&#34]}}}
但是当apiserver请求时,TLS握手失败。
我的理解是,通过检查certificate-authority
中提到的webhook-config.yaml
文件来完成TLS验证吗?如果是,则应使用ca.crt
成功进行TLS验证。但它失败了。
这是否意味着api服务器正在使用其他CA执行验证?它使用哪种CA?如何成功通过此TLS验证?
答案 0 :(得分:0)
最后我解决了这个问题。我犯的错误是我使用了webhook服务器的IP(在这种情况下为192.168.20.50)。我用webhook服务器机器的FQDN取而代之,事情已经解决了。
我在以下地方将IP更改为FQDN:
-server
文件中的kubeconfig
字段
醇>
$cat webhook-config.yaml apiVersion: v1 clusters: - cluster: certificate-authority: /etc/kubernetes/pki/ca.crt server: https://ubuntuserver:6000/authenticate name: 192.168.20.50 users: - name: root user: client-certificate: /etc/kubernetes/pki/client.crt client-key: /etc/kubernetes/pki/client.key current-context: 192.168.20.50 contexts: - context: cluster: 192.168.20.50 user: root name: 192.168.20.50