Rails credentials

Generate Rails secret

$> bundle exec rails secret

To generate/edit rails credentials

EDITOR=vim rails credentials:edit

To generate/edit rails credentials for production

EDITOR=vim rails credentials:edit --environment production

To generate/edit rails credentials for staging

EDITOR=vim rails credentials:edit --environment staging

Access these variables inside codebase

Development
$ rails c
> Rails.application.credentials.config
#=> {:aws=>{:access_key_id=>"123", :secret_access_key=>"345"} }}
> Rails.application.credentials.aws[:access_key_id]
#=> "123"
Production
$ RAILS_ENV=production rails c
> Rails.application.credentials.config
#=> {:aws=>{:access_key_id=>"123", :secret_access_key=>"456xx"}}
> Rails.application.credentials.aws[:access_key_id]
#=> "123"

In case of docker-compose

$> docker-compose run --rm -e EDITOR=vim <service-name> bin/rails credentials:edit

Rails Notes Rails Docker

This is a sapling 🌱 in my digital garden 🏡.

Notes mentioning this note


Here are all the notes in this garden, along with their links, visualized as a graph.