Rails Generate New Master.key
If your master.key has been compromised, you might want to regenerate it.
Rails Generate Master Key
It seems that bin/rails credentials:edit ignores the Rails master key if it's set via ENV var rather than config/master.key. Steps to reproduce Generate a new Rails app cd newapp && cat config/master.key prints 8fe10c494a635b461cfe23b. Railsコマンド(rails) - Railsドキュメント はじめに 全てのrailsコマンドは-h (or -help)オプションでヘルプが見れる $ rails -h $ rails generate -h $ rails generate scaffold -hgenerateのショートカットはg $ rails g scaffoldgenerateは-p, -pretendでドライランできる $ rails generate scaffold AdminU. Ruby on Rails 5.2 Release NotesHighlights in Rails 5.2: Active Storage Redis Cache Store HTTP/2 Early Hints Credentials Content Security Policy These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the change logs or check out the list of commits in the main Rails repository on GitHub.
Ruby on Rails 5.2 Release NotesHighlights in Rails 5.2: Active Storage Redis Cache Store HTTP/2 Early Hints Credentials Content Security Policy These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the change logs or check out the list of commits in the main Rails repository on GitHub. On a new project create I get the credentials.yml.enc file but no master.key. I have deleted that file and edited again creating a new one and no master.key. I also edited the original one and saved and no master key gets generated.
No key regeneration feature at the moment.We have to do it manually.
- Copy content of original credentials
rails credentials:show
somewhere temporarily. - Remove
config/master.key
andconfig/credentials.yml.enc
- Run
EDITOR=vim rails credentials:edit
in the terminal: This command will create a newmaster.key
andcredentials.yml.enc
if they do not exist. - Paste the original credentials you copied (step 1) in the new credentials file (and save + quit vim)
- Add and Commit the file
config/credentials.yml.enc
Rails Generate New Master.key Card
Important
Rails Generate Secret
- Make sure
config/master.key
is listed in.gitignore
and NOT tracked by git. - The command
EDITOR=vim rails credentials:edit
might not work if you require credential value in some file (initializers
ordatabase.yml
).I had the problem withdevise.rb
. I just uncommented the linesecret_key = ..
just the time to run the command to regenerate the credentials file, and then commented the line out again. - If you want to use Sublime to edit the credentials, you can replace the command
EDITOR=vim rails credentials:edit
byEDITOR='/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl -w' rails credentials:edit
source: https://blog.eq8.eu/til/rails-52-credentials-tricks.html