Storing authentication keys with Figaro

suggest change

Add gem "figaro" to your Gemfile and run bundle install. Then run bundle exec figaro install. This creates config/application.yml and adds it to your .gitignore file, so the keys are not committed.

You can store your keys in application.yml in this format:

SECRET_NAME: secret_value

where SECRET_NAME and secret_value are the name and value of your API key.

You also need to name these secrets in config/secrets.yml. You can have different secrets in each environment. The file should look like this:

development:
  secret_name: <%= ENV["SECRET_NAME"] %>
test:
  secret_name: <%= ENV["SECRET_NAME"] %>
production:
  secret_name: <%= ENV["SECRET_NAME"] %>

How you use these keys varies, but say for example some_component in the development environment needs access to secret_name. In config/environments/development.rb, you’d put:

Rails.application.configure do
  config.some_component.configuration_hash = {
    :secret => Rails.application.secrets.secret_name
  }
end

Finally, let’s say you want to spin up a production environment on Heroku. This command uploads the values from config/application.yml as Heroku config vars. -e production selects the production section when that file is split by environment:

$ figaro heroku:set -e production

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents