Rails PR: rails/rails#33521
This patch makes it possible to use per-environment credentials (i.e., config/credentials/staging.yml.enc
) in Rails 5.2.
- Drop
backport_rails_six_credentials.rb
andbackport_rails_six_credentials_command.rb
somewhere, for example, into thelib/
folder - Add this line to
config/application.rb
:
# Right after `require "rails"`
require_relative "../lib/backport_rails_six_credentials"
- Add this line to
config/boot.rb
:
# Right after `require 'bundler/setup'`
require_relative "../lib/backport_rails_six_credentials_command"
Now you can call:
$ bundle exec rails credentials:edit -e staging
create config/credentials/staging.key
...
And Rails.application.credentials
now uses env-specific credentials if they're present and master/root credentials otherwise.
Hi @palkan! We ran into an issue in which the
RAILS_MASTER_KEY
environment variable was being used to decrypt the environment-specific credentials. We modifiedbackport_rails_six_credentials.rb
to do something similar to whatbackport_rails_six_credentials_command.rb
uses theenv_key
method for.backport_rails_six_credentials.rb
Was there any intentional reason not to do it this way?