I searched and found some post related about this problem, espacially this one NOAUTH Authentication required. Laravel + Redis, but it doesn't solved my problem.
Redis + Rails ( with dotenv-rails ) + Ubuntu
Errors:
Redis::CommandError (NOAUTH Authentication required.)
In development the app is OK, but in production ( deploy with cap ) got this error.
In production with Redis without password the app is OK, but add password got this error.
etc/redis/redis.conf :
bind 127.0.0.1
requirepass somepassword
.env
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=somepassword
REDIS_PORT=6379
config/initializers/redis.rb
Redis.current = Redis.new(:host => ( ENV["REDIS_HOST"] || '127.0.0.1'),
:port => ( ENV["REDIS_PORT"] || '6379').to_i,
:password => (ENV["REDIS_PASSWORD"] || ''))
And I test the ENV["REDIS_HOST"] in rails console, output is 127.0.0.1.
I want to know how to enable Redis's password in this situation?
Thanks
EDIT
I run auth the_password in redis-cli, the ouput is OK and same as the value of ENV["REDIS_PASSWORD"] from the production rails console.
And now the rails log display Redis::CommandError (ERR invalid password) .
I'm very confused about it.
Edit again
I changed redis.rb to below and it worked:
Redis.current = Redis.new(:host => ( ENV["REDIS_HOST"] ),
:port => ( ENV["REDIS_PORT"] ).to_i,
:password => ( ENV["REDIS_PASSWORD"] ))
Related
We've provisioned an Azure Redis Cache server using the Premium tier. The server is clustered, with 2 shards, and the server is configured to allow public access over the public internet through a firewall--allow-listing a set of known IPs.
Deploys of our Rails application two any of these known IPs fail with the error:
Redis::CannotConnectError: Redis client could not connect to any cluster nodes
Here is our Rails config:
# application.rb
if Rails.env.test?
config.cache_store = :redis_cache_store, {
url: config.nines[:redis_url],
expires_in: 90.minutes,
namespace: ENV['TEST_ENV_NUMBER'],
}
else
config.cache_store = :redis_store, {
namespace:ENV['TEST_ENV_NUMBER'],
cluster: [ Rails.application.config.nines[:redis_url] ],
replica: true, # allow reads from replicas
compress: true,
compress_threshold: 1024,
expires_in: 90.minutes
}
end
The config.nines[:redis_url] is set like this: rediss://:<pw>#<cache-name>.redis.cache.windows.net:6380/0
Then, we initialize the Redis connection in code like this:
if Rails.env.test?
::Redis.new :url => redis_url, :db => ENV['REDIS_DB']
else
::Redis.new(cluster: [ "#{redis_url}" ], db: ENV['REDIS_DB'])
end
We're using the redis-rb gem and redis-rails gem.
If anyone can point out what we're doing wrong, please do share!
Thank you User Peter Pan - Stack Overflow. Posting your suggestion as answer to help other community members.
You can try below code:
# Import the redis library for Ruby
require "redis"
# Create a redis client instance for connecting Azure Redis Cache
# At here, for enabling SSL, set the `:ssl` symbol with the
# symbol value `:true`, see https://github.com/redis/redis-rb#ssltls-support
redis = Redis.new(
:host => '<azure redis cache name>.redis.cache.windows.net',
:port => 6380,
:db => <the db index you selected like 10>,
:password => "<access key>",
:ssl => :true)
# Then, set key `foo` with value `bar` and return `OK`
status = redis.set('foo', 'bar')
puts status # => OK
# Get the value of key `foo`
foo = redis.get('foo')
puts foo # => bar
Reference: How to setup Azure Redis cache with Rails - Stack Overflow
I've recently set up the devise gem for authentication and all is working well excluding the forgot my password function. My smtp is currently pointed towards a yahoo email address. Yet, I get a EOF end of file extension error. In development it delivers message just fine ,but to no avail in production. Also, I initialized the ENV variables for username and password with Heroku Config:set .Addtionally, I tried port 587. Any help would be much appreciated! I'm fairly new to rails and searched for similar log issues, but most varied significantly in similarity to this issue. Thank you!
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = {:host => 'https:app.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:user_name => ENV['example#yahoo.com'],
:password => ENV['examplepass'],
:domain => 'https://example.herokuapp.com/',
:address => 'smtp.mail.yahoo.com',
:port =>465,
:authentication => "plain",
:enable_starttls_auto => true,
}
My first think:
I think your file have non visible characters, try to clean your file. https://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix
Erase the file and create a new one an rewrite the config, avoid the copy paste. maybe works if you do a copy paste without format to note bloc, word something like that and then copy that back to your file.
Also read more What is an EOFError in Ruby file I/O?
https://airbrake.io/blog/ruby-exception-handling/eof-error
Continue searching i found this
EOFError in Devise::PasswordsController#create
Devise mailer EOF error
a user comment this
Ah classic. My config/secrets.yml isn't tracked in git (naturally) and >looks like it was overwritten and lost those entries for the email >provider smtp/username/password at some point. Thanks
Another one Rails EOFError (end of file reached) when saving a devise user
The resolution to my issue was two fold. I didn't have the heroku config vars properly set up and initialized.My .gitignore file didn't have the exclusions as well to prevent uploading to repository. In conclusion, I added the figaro gem, bundle exec install figaro , and it created the application.yml needed to store that actual user/pass information. https://railsapps.github.io/rails-environment-variables.html ----> quite useful in explaining the options for setting the vars.
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port =>587,
:authentication => :plain,
:enable_starttls_auto => true,
Also in the above code , I didn't have domain specified to heroku.com but my application domain on Heroku. For production.rb you do need the default url set to your applications name. If you kept the default url "heroku.com" in production.rb it would 404 error when the emailed link was clicked on.
config.action_mailer.default_url_options = {:host => 'https://exampleapp.herokuapp.com/' }
Thanks for the help! I also hope this can be of help to other new rails devs.
I just finished my ruby foundations coursework at Bloc and I'm starting to bury my head into rails development. Things were going smooth until I hit this snag with devise and confirmation emails. I tried googling and looking around at some other questions but couldn't really find any that gave me anything that I could pull from and apply to my situation.
I'm receiving the following error when signing up for an account.
Net::SMTPAuthenticationError in Devise::RegistrationsController#create
535 Authentication failed: Bad username / password
Error extracted from source around line #976
def check_auth_response(res)
unless res.success?
raise SMTPAuthenticationError, res.message
end
end
From other posts I know you'll probably want to see that I have a config/initializers/setup_mail.rb file that looks like this:
if Rails.env.development?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
authentication: :plain,
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'heroku.com',
enable_starttls_auto: true
}
end
And here's an application.yml file EXAMPLE:
SENDGRID_PASSWORD:
SENDGRID_USERNAME:
SECRET_KEY_BASE:
also I have the following in my config/environments/development.rb before anybody suggests it:
config.action_mailer.default_url_options = { host: 'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
# Override Action Mailer's 'silent errors' in development
config.action_mailer.raise_delivery_errors = true
If there's any other files that you'd like to see let me know and I'll add them to this post.
Congrats and welcome to the world of hacking on cool things.
The error you are getting means that the SendGrid server received a bad username + password combo.
Chances are your environment variables are empty and your application.yml file isn't being loaded properly with your SendGrid username + password.
You can confirm this by printing them out somewhere in your code. In a controller works.
puts "SENDGRID_USERNAME: #{ENV['SENDGRID_USERNAME']}"
puts "SENDGRID_PASSWORD: #{ENV['SENDGRID_PASSWORD']}"
I'd suspect that they are nil.
I'd recommend reading https://quickleft.com/blog/simple-rails-app-configuration-settings/ about how to get them sourced into your app.
Please let me know if you need any more help!
Two-Factor Authentication is required as of Q4 2020, and all Twilio
SendGrid API endpoints will reject new API requests and SMTP
configurations made with a username and password via Basic
Authentication.
I received a similar issue from an app I've been running for the last couple years. From now on, basic auth doesn't work, and you'll need to use an alternative auth mechanism. Heroku sendgrid auto-configuration on installation has not yet been updated to reflect this.
Source: https://sendgrid.com/docs/for-developers/sending-email/upgrade-your-authentication-method-to-api-keys/
In my case the error was to use as username the id of my apikey, but this is wrong, the correct value user_name is 'apikey', (Literally 'apikey' string), as they say in their integration example,
https://sendgrid.com/docs/for-developers/sending-email/rubyonrails/
https://app.sendgrid.com/guide/integrate/langs/smtp
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey', # This is the string literal 'apikey', NOT the ID of your API key
:password => '<SENDGRID_API_KEY>', # This is the secret sendgrid API key which was issued during API key creation
:domain => 'yourdomain.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
hy
i try to connect in the new server by ruby script
> 1.9.2p320 :038 > Net::SSH.start('192.168.10.80', 'root', :password => 'xxxxx')
> Net::SSH::AuthenticationFailed: root
> from /home/zyriuse/.rvm/gems/ruby-1.9.2-p320/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in > `start'
> from (irb):38
> from /home/zyriuse/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'
i dont understand why i get this error because when i try manually everything it's working
i try a lot of thing
require 'net/ssh'
require 'logger'
Net::SSH.start(
'localhost', 'zyriuse',
:keys => [ "~/.ssh/id_dsa.pub" ],
) do |session|
puts "hello "
end
~
zyriuse (Net::SSH::AuthenticationFailed)
Net::SSH.start( 'host',
:password=>'passord',
:port=>22,
:username=>'zyriuse',
... ) do |session|
puts "hello wordl"
end
`start': Net::SSH::AuthenticationFailed
i dont understand why i get all the time the same error
Make sure:
The account is correct
The password is correct
The IP is correct
that ssh root#192.168.10.80 works from your machine, typing the password
The error AuthenticationFailed means just that.
I'm trying to setup discourse, which is a rails3 webapp, but have some problems configuring smtp with gmail smtp server.
I have registered a new gmail account yesterday, and I can logged in browser and email-client software.
Then I configure discourse, in the file config/environments/production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:user_name => "smtp4shuzu#gmail.com",
:password => "12345678",
:authentication => :plain,
:domain => "shuzhu.org",
:enable_starttls_auto => true
}
Start the sidekiq which is used to sending the mails in the background:
nohup bundle exec sidekiq > log/sidekiq.log 2>&1 &
Then start discourse in production mode:
rails server -e production -d
But it doesn't work. I can see some errors in sidekiq.log:
2013-03-01T03:06:02Z 30687 TID-qib28 WARN: {"retry"=>true, "queue"=>"default", "class"=>"Jobs::UserEmail", "args"=>[{"type"=>"signup", "user_id"=>42, "email_token"=>"b40a21ece2b14586e346abfd96685975", "current_site_id"=>"default"}], "jid"=>"558bb6bd5aa36cfc8d3d1e91", "error_message"=>"Connection refused - connect(2)", "error_class"=>"Errno::ECONNREFUSED", "failed_at"=>2013-03-01 03:06:02 UTC, "retry_count"=>0}
2013-03-01T03:06:02Z 30687 TID-qib28 WARN: Connection refused - connect(2)
2013-03-01T03:06:02Z 30687 TID-qib28 WARN: /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in initialize'
/home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:inopen'
/home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'
I have tried all kinds of smtp settings, but none of them works.
UPDATE:
Per #Basil's answer, I just tried:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "smtp4shuzu",
:password => "12345678",
:authentication => "plain",
:enable_starttls_auto => true
}
But it has the same error. The domain shuzu.org is the domain of my site, I was thinking I should passing it to smtp. Now I removed it, but still not working.
At last, I found the (stupid) reason.
I should start sidekiq in production mode:
nohup bundle exec sidekiq -e production > log/sidekiq.log 2>&1 &
Try removing the quotes around the port
:port => 587,
Also, I don't understand why your email address is #gmail but your domain is #shuhzu... smtp settings should show the domain for your email account. If you have a custom gmail, i.e me#custom.com then domain would be custom.com. Here is an example of what smtp settings for your domain should be if you have a custom email address:
{
:address => "smtp.gmail.com",
:port => 587 ,
:domain => "custom.com",
:user_name => "some_email#custom.com",
:password => "some_password",
:authentication => "plain",
:enable_starttls_auto => true
}
Sometimes it is useful to uncomment the following line in /var/discourse/containers/app.yml:
## If you want to set the 'From' email address for your first registration, uncomment and change:
## After getting the first signup email, re-comment the line. It only needs to run once.
- exec: rails r "SiteSetting.notification_email='noreply#YOURDOMAIN.com'"
You should put here the address on behalf of which all Discourse's emails should come. By default Discourse will try to use your forum's domain name, but it may not be allowed by your SMTP. For example, your forum is at forum.example.com, while your Gmail SMTP only allows emails from example.com.
For SMTP without authentication just leave the auth fields like this:
DISCOURSE_SMTP_USER_NAME:
DISCOURSE_SMTP_PASSWORD:
and after everything is saved:
./launcher rebuild app
Once emails are working, you can re-comment this line (with SiteSetting).
You can even just set this SiteSetting via console, but it's more difficult than uncommenting/re-commenting a single line and re-build the container, so I'll not elaborate on this.
On my install, which is one of those pre-made image thingies (Bitnami), I just had to run this:
/opt/discourse-0.9.5-0/ctlscript.sh start discourse_sidekiq
Anyone know how I can automate this so that it happens on startup?
I just set up a new discourse instance in a docker container on my own ubuntu physical on site server and edited the app.yml to contain:
DISCOURSE_SMTP_ADDRESS: 'smtp.gmail.com'
DISCOURSE_SMTP_AUTHENTICATION: 'plain'
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: 'my.name#gmail.com'
DISCOURSE_SMTP_PASSWORD: 'myPa$$word'
DISCOURSE_SMTP_ENABLE_START_TLS: true
and it worked. Half the battle was knowing where to put single inverted commas (') and where not to.
Another way was available to me also - my ISP provides a relay smtp for it's static IP customers so I used this in app.yam:
DISCOURSE_SMTP_ADDRESS: mail.myisp.tld
DISCOURSE_SMTP_AUTHENTICATION: none
DISCOURSE_SMTP_PORT: 25
and it works for me also.