In Rails 5.2, encrypted credentails are stored in the file
This is a single flat file which is encrypted by the key located in
Rails 5.2 does not support storing credentials of different environments with different encryption keys. If we want environment specific encrypted credentials, we’ll have to follow this workaround.
Rails 6 has added support for Multi Environment credentials. With this change, credentials that belong to different environments can be stored in separate files with their own encryption key.
Let’s see how this works in Rails 6.0.0.beta3
If we want to add credentials to be used in staging environment, we can run
This will create the credentials file
a staging specific encryption key
open the credentials file in your text editor.
Let’s add our AWS access key id here.
We can then access the access_key_id in staging environment.
Which takes precedence: Global or Environment Specific credentials?
Credentials added to global file
will not be loaded
in environments which have their own
environment specific credentials file (
So if we decide to add the following to the global credentials file, these credentials will not be available in staging. Since we already have a environment specific credentials file for staging.
Here is the relevant pull request