Rudi Thiel
Rudi Thiel

Reputation: 2551

How to get rails master.key after upgrading to rails 5.2

So I've upgraded an app I'm working on to rails 5.2 and it's crashing on Heroku. I think it's because I don't have a master.key file in my /config folder. I still have the secrets.yml file from the previous rails version. What do I have to do to resolve this issue? Thanks!

error in heroku logs:

2019-01-28T21:07:46.922561+00:00 app[web.1]: /app/vendor/bundle/ruby/2.5.0/gems/aws-sdk-s3-1.30.1/lib/aws-sdk-s3/bucket.rb:684:in `extract_name': Cannot load `Rails.config.active_storage.service`: (ArgumentError)
2019-01-28T21:07:46.922573+00:00 app[web.1]: missing required option :name

Upvotes: 4

Views: 9130

Answers (3)

barmic
barmic

Reputation: 1097

You have to generate master.key and credentials.yml.enc. To do this, just run the command:

run EDITOR=vim rails credentials:edit

(As editor you can use something else, for example atom or nano).

In opening editor, you can type credentials, and save it. Rails use master.key to encrypt credentials. More you can find here: https://medium.com/cedarcode/rails-5-2-credentials-9b3324851336

To make encrypted credentials work on Heroku, you can copy key from master.key and use it to set up RAILS_MASTER_KEY environemnt variable. You can achieve this by Heroku Dashboard or Heroku CLI, as below:

$ heroku config:set RAILS_MASTER_KEY=`cat config/master.key`

Upvotes: 6

Hardik Kanjariya ツ
Hardik Kanjariya ツ

Reputation: 636

You'll be able to generate master.key file by using following command:

$ EDITOR=vim rails credentials:edit

It's sample output will be as follows:

Adding config/master.key to store the master encryption key: <YOUR_MASTER_KEY>

Save this in a password manager your team can access.

If you lose the key, no one, including you, can access anything encrypted with it.

      create  config/master.key

Ignoring config/master.key so it won't end up in Git history:

      append  .gitignore

Please check official documentation: https://github.com/rails/rails/blob/master/railties/lib/rails/commands/credentials/USAGE

Upvotes: 0

danielricecodes
danielricecodes

Reputation: 3586

A couple of things. Speaking from my own personal experience, I've upgraded several Rails apps to 5.2 and I have been able to deploy to Heroku just fine without this feature. So I don't think its that necessarily.

If you could run heroku logs --tail --app <your app name> and show us a stack trace of why your app is failing, that would definitely help.

Upvotes: 1

Related Questions