Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSLError not always translated to KubeException #240

Open
cben opened this issue Mar 27, 2017 · 8 comments
Open

SSLError not always translated to KubeException #240

cben opened this issue Mar 27, 2017 · 8 comments

Comments

@cben
Copy link
Collaborator

cben commented Mar 27, 2017

There is a specific test that it should be (and #195 will add a second test):
https://github.com/abonas/kubeclient/blob/f489a35027a7/test/test_kubeclient.rb#L95-L105
but in reality I'm seeing an SSLError escaping:
https://gist.github.com/cben/faf8a9f7f104561c0b36c88ae02f2509
That makes sense, handle_exception only rescues RestClient::Exception.
Why does the test pass?

Aha. RestClient has its own http://www.rubydoc.info/github/rest-client/rest-client/RestClient/SSLCertificateNotVerified, wraps some SSLErrors:
https://github.com/rest-client/rest-client/blob/8874463a4/lib/restclient/request.rb#L742-L761

      # TODO: deprecate and remove RestClient::SSLCertificateNotVerified and just
      # pass through OpenSSL::SSL::SSLError directly.
    ...
      if error.message.include?("certificate verify failed")
        raise SSLCertificateNotVerified.new(error.message)

In above gist the message was "hostname ... does not match the server certificate", not "certificate verify failed", so it isn't wrapped.

  • Looks unwise to depend on SSLCertificateNotVerified wrapping or not wrapping.
  • Would Kubeclient always wrapping SSLError be desired behavior?
  • Another alternative would be never wrapping. This would require re-raising SSLCertificateNotVerified, and users having to expect either SSLError or SSLCertificateNotVerified. IMO less nice and unexpected.

I think either change would be slightly backward-incompatible.

@simon3z
Copy link
Collaborator

simon3z commented Mar 28, 2017

@cben what's the final impact here. Does this deserve a bug to be tracked in MIQ?
Update: ah I see this was as result of https://bugzilla.redhat.com/show_bug.cgi?id=1436221

@moolitayer
Copy link
Collaborator

Based on the link @cben posted I think we should catch OpenSSL::SSL::SSLError to keep the behavior we have (or thought we had). Introducing a new subclass sound good but I'd like to see this resolved first.

@cben do you plan to send a PR for this? I have some time to do that, let me know
(I think you have a lot on your plate ATM and this is high priority)

@moolitayer
Copy link
Collaborator

Some test code and different exceptions I got

test code

require 'kubeclient'

cert_store = OpenSSL::X509::Store.new
cert_store.add_cert(OpenSSL::X509::Certificate.new(IO.read('ca_bad.crt')))

ssl_options = {
    cert_store: cert_store,
    verify_ssl: OpenSSL::SSL::VERIFY_PEER
}
client = Kubeclient::Client.new(
  'https://vm-48-131.eng.lab.tlv.redhat.com:8443',
  'v1',
  :ssl_options  => ssl_options,
  :auth_options => {:bearer_token => token}
)
puts client.get_nodes
/home/mtayer/.gem/ruby/2.3.1/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:107:in `rescue in handle_exception': SSL_connect returned=1 errno=0 state=error: certificate verify failed (KubeException)
	from /home/mtayer/.gem/ruby/2.3.1/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:99:in `handle_exception'
	from /home/mtayer/.gem/ruby/2.3.1/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:433:in `fetch_entities'
	from /home/mtayer/.gem/ruby/2.3.1/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:423:in `load_entities'
	from /home/mtayer/.gem/ruby/2.3.1/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:111:in `discover'
	from /home/mtayer/.gem/ruby/2.3.1/gems/kubeclient-2.3.0/lib/kubeclient/common.rb:78:in `method_missing'
	from /home/mtayer/.local/bin/kubeclient-local-ssl.rb:17:in `<main>'
/home/mtayer/.local/bin/kubeclient-local-ssl.rb:5:in `initialize': header too long (OpenSSL::X509::CertificateError)
	from /home/mtayer/.local/bin/kubeclient-local-ssl.rb:5:in `new'
	from /home/mtayer/.local/bin/kubeclient-local-ssl.rb:5:in `<main>'
/home/mtayer/.local/bin/kubeclient-local-ssl.rb:5:in `initialize': nested asn1 error (OpenSSL::X509::CertificateError)
	from /home/mtayer/.local/bin/kubeclient-local-ssl.rb:5:in `new'
	from /home/mtayer/.local/bin/kubeclient-local-ssl.rb:5:in `<main>'

I'm not sure we should catch & wrap, what rest client is doing is silly. It should be fix in rest client. Also It would break backward compatibility as @cben mentioned. So I'm favor of not changing anything in kubeclient

@simon3z @abonas What do you think?

@abonas
Copy link
Member

abonas commented Mar 29, 2017

Is there an issue reported on this to rest client repo?

@moolitayer
Copy link
Collaborator

Is there an issue reported on this to rest client repo?

rest-client/rest-client#168 (from 2013)
This might also be related: rest-client/rest-client#286

cben added a commit to cben/manageiq-ui-classic that referenced this issue Apr 9, 2017
Expands ManageIQ#314.
KubeException already covers the common "certificate verify failed" SSL
errors but not rarer ones like "does not match the server certificate".
This might be resolved in Kubeclient or RestClient one day
(ManageIQ/kubeclient#240) but it's blocked
on backward compatibility concerns so let's catch it here for now.

get_hostname_from_routes is best-effort, should never crash UI.
Any SSL error will probably fail both get_hostname_from_routes and the
main validation code; the error from validation will then be displayed
in a red flash.
https://bugzilla.redhat.com/show_bug.cgi?id=1436221
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
grosser added a commit to zendesk/samson that referenced this issue Nov 21, 2017
ssl errors and a few others are not retried atm leading to failing deploys
ManageIQ/kubeclient#240
@cben
Copy link
Collaborator Author

cben commented Jan 23, 2018

I propose for kubeclient 3, we solve this by adding Kubeclient::SSLError which will wrap both OpenSSL::SSL::SSLError and RestClient::SSLCertificateNotVerified.
There is a tradeoff with wrapping exceptions — makes easier to recognize errors that passed through us, but harder to know what exactly they were — but IMHO this would make kubeclient nicer to use on the balance.

  • Should the new Kubeclient::SSLError subclass Kubeclient::HttpError? Technically, SSL errors may happen before HTTP even comes into the picture. But if it doesn't subclass, we may want a new parent Kubeclient::Error for both — or again users would need to remember one common and one rare class to rescue. I think pragmatically, we can subclass, keeping HttpError as our top error.

@cben
Copy link
Collaborator Author

cben commented Jan 23, 2018

@grosser any opinion/advice? I see we can learn from your workarounds...

@grosser
Copy link
Contributor

grosser commented Jan 23, 2018 via email

@cben cben added the bug label Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants