sensu-plugins / sensu-plugins-kubernetes

Sensu plugins for Kubernetes
http://sensu-plugins.io
MIT License
28 stars 36 forks source link

client cert authentication doesn't work with intermediate CAs #41

Open geekofalltrades opened 7 years ago

geekofalltrades commented 7 years ago

If your client certificate is issued from an intermediate CA, rather than from the Root CA, then it seems this plugin doesn't send the intermediate with the request, which causes a 401 from Kubernetes. I tested this with check-kube-nodes-ready.rb; I'm unsure if it affects the other plugins, as well.

Steps to reproduce:

If you instead send the INT cert and key, you are able to authenticate.

This makes me suspect that the plugin isn't sending the full chain from the client cert.

geekofalltrades commented 7 years ago

From https://github.com/sensu-plugins/sensu-plugins-kubernetes/blob/2.0.0/lib/sensu-plugins-kubernetes/client.rb#L84

Experimenting a little, it looks like OpenSSL::X509::Certificate just skims the first cert out of the file and discards the rest of the chain.

certtest.rb:

require 'openssl';

cert = OpenSSL::X509::Certificate.new(File.read('my-cert-with-chain.crt'))
print cert
$ /opt/sensu/embedded/bin/ruby certtest.rb 
-----BEGIN CERTIFICATE-----
<my client cert...>
-----END CERTIFICATE-----
# No chain is printed!

I don't know Ruby, so I don't know how to fix it.