Conjur - Kubernetes authenticator fails with "certificate verify failed"
117
Created On 11/10/26 11:00 AM - Last Modified 11/10/26 16:03 PM
Symptom
When attempting to use the k8s authenticator, the authenticator init container or sidecar fails with the following error message in the logs:
INFO: 2021/04/16 07:50:23.761324 main.go:41: CAKC040 Authenticating as user '...' ERROR: 2021/04/16 07:50:23.901930 authenticator.go:136: CAKC029 Received invalid response to certificate signing request. Reason: status code 401, ERROR: 2021/04/16 07:50:23.901971 authenticator.go:210: CAKC015 Login failed ERROR: 2021/04/16 07:50:23.901981 main.go:45: CAKC016 Failed to authenticate
And the Conjur/DAP server logs contain the following error message:
CONJ00048I Authentication Error: #<Kubeclient::HttpError: HTTP status code , SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate in certificate chain)>
Environment
- The Conjur/DAP server is running outside of Kubernetes (e.g. this does not impact a Follower running as a Kubernetes deployment in the same Kubernetes cluster).
- The Kubernetes API URL uses custom TLS certificates (not internal Kubernetes certificates) or TLS connections are terminated outside of Kubernetes (e.g. an external load balancer).
Cause
When custom certificates or an external load balancer are used for the connection from Conjur/DAP to the Kubernetes API server, both CA certificates must be configured on the Conjur Kubernetes authenticator.
To check whether you are affected by this scenario:
Obtain the internal Kubernetes CA certificate with the commands:
$ TOKEN_SECRET_NAME="$(kubectl get secrets -n <K8S_NAMESPACE> \
| grep 'conjur.*service-account-token' \
| head -n1 \
| awk '{print $1}')"
$ kubectl get secret -n <K8S_NAMESPACE> $TOKEN_SECRET_NAME -o json \
| jq -r '.data["ca.crt"]' \
| base64 --decode
---Begin Certificate---
...
--- End Certificate---
Compare this certificate value with the result of running the command:
$ echo q | openssl s_client -connect <K8S_API_URL> -servername <K8S_API_URL> -showcerts 2>/dev/null > api-chain.pem ---Begin Certificate--- ... --- End Certificate--- ... ---Begin Certificate--- ... --- End Certificate---
If the last entries in each of these outputs do not match, you should use the resolution above to resolve the certificate verification issue.
Resolution
The resolve this issue, both CAs from the commands above need to be trusted CAs for the Conjur Kubernetes Authenticator:
- Concatenate all of the certificates in the output above into a single file. If the kubectl command returns one certificate and the openssl command returns three certificates, then the concatenated file should contain four certificates.
Note: the order of certificates in this file does not matter. - Given the concatenated certificate file is called combined-k8s-ca.pem, load the contents of this file into the Conjur variable to configure the Kubernetes authenticator with the command:
$ conjur variable values add \ conjur/authn-k8s/<authenticator name>/kubernetes/ca-cert < combined-k8s-ca.pem - Redeploy the client application pod to attempt the authentication again.