sumoheavy / jira-ruby

A Ruby gem for the JIRA REST API
MIT License
654 stars 412 forks source link

net/protocol.rb:227:in `rbuf_fill' - Error while connecting to JIRA using token #398

Closed Sachin796 closed 1 year ago

Sachin796 commented 1 year ago

Hi, I am currently trying to connect to JIRA using the JIRA token. I am currently facing some issues connecting and below are the details along with the code that I am trying to use to connect to JIRA.

I am currently trying to refer to the documentation here

Below are the code snippets and the error that I am facing while getting a specific project from JIRA.

Code -

image

Error -

image

The following ENV variables are currently set to connect

I also did verify if the token is working fine and I am able to connect to the JIRA and get the project by its name as below using POSTMAN

image

Please let me know if there is anything that I am missing in the configuration that needs to be done or any enhancements that needs to be made, also if there is any other details that is required to look at the issue.

Thanks.

d-hansen commented 1 year ago

I'm about 99.99% sure that Atlassian will not respond on a non-SSL request and/or if it does, it will be with a redirect to the https URL. So, I really don't understand why you have set :use_ssl => false. IMO, that will surely not work correctly.

Sachin796 commented 1 year ago

Ok.. I understand.. I did remove the :use_ssl => false and I can confirm it did default to :use_ssl => true . I am still facing some issues related to ssl_connect. Do you have any idea if this will require to set up any system certificates OR any environment variables that are required for it to proceed..?

Screenshot for error as below..

image

Thank you.

d-hansen commented 1 year ago

This makes me wonder what type of Jira installation you are using (you didn't mention this) and what the URL is that you are using for Jira. We also don't know what additional path you might have on your JIRA_URL env that you are then transferring into the context_path parameter.

If you are using Jira Cloud, then the URL has to be something of the form https://<yourdomainprefix>.atlassian.net. The domain part would be the same as when you connect to the Jira Dashboard. Also, you would use an empty context_path (eg, context_path: ''). But, I would be really surprised if you are on Jira Cloud and assuming the domain is properly set to <yourdomainprefix>.atlassian.net that this would lead to the self-signed certificate error your are getting, so instead it makes me think you must have a local Jira Server installation.

If you are using a local Jira Server installation, and since we don't know what path you've got in your JIRA_URL, then it's hard to know if maybe that wasn't part of your original issue. Of course, it could also be that the httpd server on the local Jira Server installation is not setup correctly even for non-encrypted HTTP (non-ssl) traffic. Though, you did say you successfully tested with Postman.

Note: if you do want to continue to use ssl with a local Jira Server installation (and I highly recommend this), then you will need to install a SSL certificate from a known root authority (this is where the error you are now getting is coming from). You can get a free signed SSL certificate from letsencrypt.org (they just require re-issuance on a regular short basis). You can not use a self-signed certificate for any HTTP traffic - this is more of a baked in client-side requirement in just about all browsers these days (including the openssl client request library underneath Jira Ruby). You could go through a bunch of configuration gyrations to find the right setup to pass to the client openssl library to get it to accept your server's self-signed certificate chain, but it's probably much simpler and more secure to just get a root authority based SSL certificate.

However, since you did mention that you were able to connect to your original non-SSL HTTP URL using postman, then I am thinking your original problem is more likely with your context_path. For that, you will need to better understand how your Jira Server installation is configured. I have not setup a local Jira Server installation, so I am of no help on that.

d-hansen commented 1 year ago

Note: I was just reviewing the code and you could try setting the JIRA::Client option ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE and it should then ignore the self-signed certificate problem you have (as that tells the openssl layer to not verify the authenticity of the server's certificate).

Sachin796 commented 1 year ago

Thanks David for the detailed explanation. Just wanted to provide some details on what happened after your recommedations were followed.

  1. I am pretty sure we are not using JIRA cloud as our link has something like this.. https://jira.xxx.<domain_name>.ca , so I am pretty sure I have to look into the workaround that you provided me to generate the SSL certificate and then proceed accordingly.
  2. You are correct about JIRA::Client option ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, it solved me the error that I was facing in the image above .. so thank you for that.
  3. For my code above, I have done the testing and it seems that the context_path field is '' for now. The error that I am facing right now with the updated code below with my own jira server is as below.. which I think I might need to setup some headers or so to resolve that.

Also just found out the issue over here - I think the client is not found as per the documentation here

image

Thank you.

Sachin796 commented 1 year ago

This issue was solve from the conversation above.