stcho
stcho

Reputation: 2139

Rails environment variables vs Rails 5.2 credentials

I just wanted to know what the specific differentiation is between

environment variables ENV[SOME_VARIABLE]

vs.

Rails 5.2 credentials Rails.application.credentials.some_variable

When should I use one vs. the other? Did the credentials replace the env variables?

Upvotes: 14

Views: 1877

Answers (2)

When should you use env:

  • When you have fixed no variables in your project
  • When you don't need environment-specific keys

When should you use credentials:

  • When you need to update keys frequently and you want to update it locally to test and also wish to maintain it securely ( since every environment has its own credential file and own key to access it
  • When you want environment-specific key values to isolate environment-wise service access. for example, you wish to maintain different fcm service channel at staging and on production to prevent information leak while testing internally

Upvotes: 0

Brandon
Brandon

Reputation: 1875

Credentials are stored in an encrypted file and are checked into your repository. There is a master key file that acts as the key in development, and you set the value of the master key file as an environment variable in production and both environments have access to the credentials. environment variables, on the other hand, should be used for values which are not secrets. Environment variables are generally not checked into your repository though still.

Upvotes: 2

Related Questions