From: https://medium.com/@zhimin.wen/https-client-certificate-authentication-with-sidecar-9b07d82a6389 ![]() This paper is a continuous exploration of enabling HTTPS for the app without https implemented. (The first paper can be reached here.) Here we will enable client certificate authentication for a non-https app using the sidecar pattern. When client certificate authentication is turned on, the client HTTPS connection must submit with a valid cert that signed by the CA. Otherwise, the connection will be rejected. In the last part of the paper, we examine the Prometheus in IBM Cloud Private which is using the same https sidecar pattern. Steps to setup client certificate authenticationFirst, we enable the client certificate authentication by adding the following lines in the nginx.conf file as what we have in the first paper. ... When ssl_verify_client is set on, the ssl_client_certificate need to be set as the CA cert that is used to sign the server and client cert. If a client doesn’t use a cert signed by this CA, the https connection will be rejected. Secondly, we create the K8s secret with all the certs required, kubectl create secret generic hello-sidecar-nginx-certs --from-file=hello-server-cert=./hello-server.pem --from-file=hello-server-key=./hello-server-key.pem --from-file=hello-server-ca-cert=./myca.pem Then update the K8s deployment file, to mount the CA to the Nginx container. ... Apply the updated yaml file. Now the application is HTTPS client certificate authentication enabled. Positive and Negative TestTest without the valid cert. curl -k https://192.168.64.244:31463/date To test with the valid cert, let’s generate the cert signed by the CA first. Create a json file as below, save it as “clientRequest.json” { Generate the client cert with the client profile (as defined in the first paper). cd certscfssl gencert -ca=myca.pem -ca-key=myca-key.pem -config=ca-config.json -profile=client -hostname="127.0.0.1" clientRequest.json | cfssljson -bare hello-client You will have
Test with these keys, curl -k --cert certs\hello-client.pem --key certs\hello-client-key.pem https://192.168.64.244:31463/date At this point, we implemented the HTTPS with client cert authentication for the non-https application using the K8s sidecar pattern. ICP PrometheusBy default, Prometheus doesn’t provide any HTTP/TLS capability. IBM Cloud Private, ICP, uses the sidecar technique to enable the HTTPS/TLS and client certificate authentication. Attached is part of the result of The sidecar container, router, in the pods router: The nginx.conf can be found by running The server block excerpt is listed as below, server { Because of the ssl_verify_client setting, the client which needs to contact to Prometheus must, therefore, use the certificate signed by the CA cert. The location block, which redirects the traffic to the Prometheus, is shown below, location /federate { The API call to Prometheus will be redirected to the Prometheus container in the same pod. ConclusionThese two papers explore the sidecar pattern for HTTPS and client certificate authentication. With the knowledge, it is useful to understand the ICP Prometheus and to further extend Prometheus functionality. |
System Tools >