I am trying to set up a rails app with actioncable, where it's using a redis database hosted on app.redislabs.com. I am having trouble getting the connection to successfully initiate, even though I can connect to a localhost redis server fine.
If I use the url redis://myredisurl, I get the following errors: Connection reset by peer (Errno::ECONNRESET) followed by Connection lost (ECONNRESET) (Redis::ConnectionError).
From a google search, the only thing I could find was possibly that the redis server wants an ssl connection. So I tried the url rediss://myredisurl, and that gives an SSL error: SSL_connect returned=1 errno=0 state=error: wrong version number (OpenSSL::SSL::SSLError)
The development section of cable.yml looks like this:
development: &development
adapter: redis
password: <%= ENV['REDIS_PASSWORD'] || '' %>
db: <%= ENV['REDIS_DB'] || '' %>
url: <%= ENV['REDIS_HOST'] || 'redis://127.0.0.1' %>
port: <%= ENV['REDIS_PORT'] || '6379' %>
ssl: true
ssl_params:
verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>
I tried with & without ssl: true. With & without ssl_params. I'm still unable to get the connection to work, and I don't know what I'm missing.
Of note, I am able to connect to the hosted redis with redis-cli, so I know it's reachable.
I am using Rails 5.2.7, and it is not possible to upgrade.
This turned out to be a corporate network firewall issue - not an issue with our app setup.
Related
I have a rails app that I have deployed to AWS Elastic Beanstalk. The app uses devise to handle user authentication, and its set to be able to invite users.
My issue is that when I try to invite a user, I get the following error:
Net::SMTPFatalError (554 secureserver.net ESMTP No Relay Access Allowed From <my_eb_assigned_ip>
(I am hosting the domain on GoDaddy).
In development, the mailer functionality works fine; my smtp settings are set to (common to all environments):
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtpout.secureserver.net",
:port => 80,
:domain => "www.my_domain.com",
:authentication => :plain,
:user_name => "do-not-reply#my_domain.com",
:password => my_pass,
}
And in my production.rb config file:
config.action_mailer.default_url_options = { :host => 'aws_sb.elasticbeanstalk.com' }
Is there another setting I have to enable in Elasticbeanstalk to allow relay access? Or am I missing a production specific setting from my rails configuration?
I figured out it was the port value that I was setting....when I switched the port to 25, it works in production. However, for development, port 25 wasn't working; it would only work in dev when the port was 80.
So I ended up moving the entire smtp mailer settings into the environment specific settings (from the config/environment.rb file), and setting the production port to 25, and the development port to 80, and that appeared to make both environments work.
Edit: After another push, I was seeing the same issue, and none of the ports I tried were resolving the issue. So I ended up switching all my mail functionality to be sent through Amazon SES, and that appears to be functioning great so far.
I'm having an error with gmail gem while trying to send a mail, this is working fine on local, and was working fine on heroku, but now im moving this app to a VPS server. This is the error:
e = g.compose do
to 'test#gmail.com'
subject 'testasea'
body 'test'
end
=> #<Mail::Message:25450040, Multipart: false, Headers: <From: .......>
e.deliver!
=> OpenSSL::SSL::SSLError: hostname does not match the server certificate
I've added this into an initializer file, without any luck:
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:openssl_verify_mode => 'none' # I've tested with 0 and false,
}
I tried to monkey path the class
OpenSSL::SSL::SSLSocket.class_eval do
def post_connection_check(hostname)
return true
end
end
with no luck, when I do that i receive a 535 Incorrect authentication data, however I know data is ok because i can do
g.inbox.count :read
And it returns me the right number.
I would like to know:
the incorrect certificate is the one my server (smtp client) is sending? or the one that is received by gmail smtp server?
why it works in local?
Why if i monkey path the class I received an authentication error?
Is there any workaround? i dont care if is not safe, is just a tenting application,.
This is only a guess, but if you are in a WHM VPS there is a function that restricts outgoing SMTP connections, you can find it in Tweak Settings.
Restrict outgoing SMTP to root, exim, and mailman (FKA SMTP Tweak)
It redirects all SMTP connections, If this is enabled you will receive your server self-signed ssl certificate, and if you bypass it using the monkey patch or setting configuration to dont check ssl certificate you will probably found an authentication error as you are in fact connecting to the LOCAL SMTP server.
Just disable it and test again.
I'm using ZXing to decode my qr codes, it works fine on development, but on production after deploy it just works for five minutes or so and only if I restart the server, after that it just doesn't work, going through the log, this is what comes out:
ActionView::Template::Error (druby://127.0.0.1:51876 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>):
1: <% provide(:title, "Updating...") %>
2: <input />
3: <% if (ZXing.decode "public/assets/#{current_user.user_name.downcase}_bdd.jpg").nil? %>
4: <% flash.now[:notice] = "BDD invalid, change it!" %>
5: <div class="actions_cambiar_bdd">
app/views/users/change_folios.html.erb:3:in
`_app_views_users_change_folios_html_erb___206747123981808960_69821004639000'
I don't know what is going on, looking at it, I think that it cannot works its way out to my server that's why the connection refused, but the weird thing is that it works fine for a couple of minutes after the server is restarted, after that, nothing, I hope anyone can help me out. Thanks for your time.
EDIT:
Apparently after a while the port gets blocked or busy, i guess that is something to do with how zxing manage the port assign, here are some files of it:
EDIT 2
client.rb
require 'socket'
require 'drb'
module ZXing
BIN = File.expand_path('../../../bin/zxing', __FILE__)
class Client
def self.new
port = ENV['ZXING_PORT'] || find_available_port
setup_drb_server(port) unless ENV['ZXING_PORT'] && responsive?(port)
DRbObject.new_with_uri("druby://127.0.0.1:#{port}")
end
private
def self.setup_drb_server(port)
remote_client = IO.popen("#{ZXing::BIN} #{port}")
sleep 0.5 until responsive?(port)
at_exit { Process.kill(:INT, remote_client.pid) }
end
def self.responsive?(port)
socket = TCPSocket.open('127.0.0.1', port)
true
rescue Errno::ECONNREFUSED
false
ensure
socket.close if socket
end
def self.find_available_port
server = TCPServer.new('127.0.0.1', 0)
server.addr[1]
ensure
server.close if server
end
end
end
I kind of get answered on github by one of the guys in the zxing project:
https://github.com/ecin/zxing.rb/issues/6
Shortly he gave me the advice to export from my code the ZXING_PORT const, but it did not solve it, the number on the ZXING_PORT gets the same treatment, it works for a couple of minutes, and then the same mistake, only this time with the ZXING_PORT
ActionView::Template::Error (druby://127.0.0.1:ZXING_PORT - #<Errno::ECONNREFUSED: Connection refused - connect(2)>):
I'm considering the options to either somehow "reserve" the port or socket so no process can take it or find a way to reload the gem on the production environment on every request.
Which option should i take? Which one is the more appropied or the more plausible?
Ok, so i finally got it to work, i put the code on boot.rb, just before the gems are loaded
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['PORT_NUMBER'] = "4333"
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
I am trying to establish a connection using the SOAP gem, called Savon. I can't make sense from the documentation on the website, I have this URL: "https://www.example.com/loginWeb/rvu.aspx", and this credentials username: "user", password: "pass".
My code is this (rails console):
client = Savon::Client.new("https://www.example.com/loginWeb/rvu.aspx")
client.wsse.credentials 'user', 'pass'
I get this: (event trying with "digest")
HTTPI executes HTTP GET using the net_http adapter
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
I downloaded SoapUI and I get this error when I try to connect to the URL:
Error loading [http://www.example.com/loginWeb/rvu.aspx?WSDL]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: Unexpected character encountered (lex state 3): '&
So what is going on ? Any help?
I suppose it's the same issue as here: you're trying to access a site with self-signed SSL certificate.
One way to fix it is to prevent Savon checking it:
client = Savon::Client.new("https://www.example.com/loginWeb/rvu.aspx")
client.http.auth.ssl.verify_mode = :none
client.wsse.credentials 'user', 'pass'
My company has a simple oauth server at https://auth.vitalvu.com
I'm developing a rails app that needs to make requests to that server (via the omniauth-oauth2 gem). When I try to run the app on Heroku I get the error:
Faraday::Error::ConnectionFailed: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
I've tested it as described here.
From the app's rails console on my local machine
connection = Faraday::Connection.new 'https://auth.vitalvu.com'
connection.get '/ping.json'
works just fine.
However, after pushing the app to Heroku, heroku run rails console
connection = Faraday::Connection.new 'https://auth.vitalvu.com'
connection.get '/ping.json'
results in the faraday error and
connection = Faraday::Connection.new 'https://auth.vitalvu.com', :ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}
connection.get '/ping.json'
results in the faraday error and
connection = Faraday::Connection.new 'https://auth.vitalvu.com', :ssl => {:ca_path => "/etc/ssl/certs"}
connection.get '/ping.json'
results in the faraday error
I'm not sure what else to try. Suggestions?
I run heroku restart three times - and than finally is starts to work.