When I try to launch a Rails app that I brought locally with git clone with rails s
or rails c
, the following error occurs.
$ rails s
=> Booting Puma
=> Rails 6.1.0 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/Users/jnito/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/activesupport-6.1.0/lib/active_support/message_encryptor.rb:203:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)
Rails won't start with an exception because the key for config/master.key
doesn't match the key for config/credentials.yml.enc
.
config/master.key
is usually a file that is added to .gitignore
and is not subject to source code control. Therefore, git clone does not copy config/master.key
locally.
In that state, if you want to edit credentials.yml.enc
and execute a command like EDITOR = "vi" bin/rails credentials: edit
, you will see the following message and config/master. .key
is newly created. (In addition, you cannot edit credentials.yml.enc
)
$ EDITOR="vi" bin/rails credentials:edit
Adding config/master.key to store the encryption key: 6eb4ad(The following is omitted)
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
Couldn't decrypt config/credentials.yml.enc. Perhaps you passed the wrong key?
However, the newly created config/master.key
is not the key of the config/credentials.yml.enc
that has been git cloned, so decryption fails when Rails starts and an exception (ActiveSupport :: MessageEncryptor: : InvalidMessage) occurs.
How to deal with it depends on the situation.
Since the key sharing method should be decided within the development team, place the appropriate config/master.key
locally according to the operation rules.
If you delete the automatically created config/master.key
, Rails will start.
If you don't want to use credentials.yml.enc
in the future, you can delete the whole config/credentials.yml.enc
.
Conversely, if you plan to use credentials.yml.enc
(= you will be the first user in your team), recreate config/credentials.yml.enc
and then credentials /master.key
needs to be properly managed and shared within the team.
(However, if you can get the appropriate config/master.key
from somewhere, you don't need to recreate it.)
#Existing credentials.yml.Remove enc
$ rm config/credentials.yml.enc
# credentials.yml.enc and master.Create a new key and edit it
$ EDITOR="vi" bin/rails credentials:edit
Adding config/master.key to store the encryption key: 917c31e316061bcdd909754a56897f61
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
File encrypted and saved.
Recommended Posts