bigwolk
bigwolk

Reputation: 418

Missing secret_key_base in Rails.application.secrets on test environment

I've generated simple rails api application and I've got problem with Rails.application.secrets.secret_key_base - it's nil. I'm launching it on my local machine. According to this article everything should be fine. I've got proper app/config/credentials.yml.enc. When I try to edit it with rails credentials:edit it edits properly. Actual content of it is

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: 47ba27802a354b44c1cd0d0c624fcde2dced69ccfe62d274e9ecfc98d9e6671c4cf31a29aaf77af555d9553811a3ff15f22ab060e5ec5ffc0d29f77241368272

In all configuration files (/app/config/environments/*.rb) I've added config.require_master_key = true - it doesn't help. My actual Rails.application.secrets content is {:secret_key_base=>nil, :secret_token=>nil}. I've dumped it in my custom class and application_controller.rb - this same result in both places.

Any ideas what I've missed?

PS. Before You flag this question with duplicate - note that I'm using rails 5.2 where credentials storing has changed.

Upvotes: 3

Views: 3523

Answers (2)

Denny Mueller
Denny Mueller

Reputation: 3615

Try

Rails.application.credentials.secret_key_base 

secret_base_key is different than credentials When you add the secret_base_key to credentials its just available as credential and not as secret.

Upvotes: 7

Hesham Youssef
Hesham Youssef

Reputation: 198

I had a kind of the same problem, and at the end I found out that rails credentials:edit was not really saving because of the editor (I was using VS code). When I tried it with vim, it saved and everything worked as it should be. So try to set the editor to vim when you run the command as follows:

EDITOR=vi bin/rails credentials:edit

Then save with :wq, and try again.

Hopefully this should solve the issue :)

Upvotes: 1

Related Questions