Skip to content

Instantly share code, notes, and snippets.

@alexishida
Last active November 13, 2023 16:14
Show Gist options
  • Save alexishida/adbdc9110915ef8b07e59f304a5f50dc to your computer and use it in GitHub Desktop.
Save alexishida/adbdc9110915ef8b07e59f304a5f50dc to your computer and use it in GitHub Desktop.
Rails 5.2 Credentials Secrets
# Edit credentials
EDITOR=nano rails credentials:edit
# Generate Random key
rails secret
# Use Example on Devise
development:
devise_key: <dev-key>
production:
devise_key: <prod-key>
config.secret_key = Rails.application.credentials[Rails.env.to_sym][:devise_key]
Rails.application.credentials.aws[:access_key_id] # => "123"
Rails.application.credentials.aws[:secret_access_key] # => "345"
Rails.application.credentials.secret_key_base # => "2fdea...
or
<%= Rails.application.credentials.dig(:development, :db_password) %>
# Uncomment in environments/production.rb this line:
config.require_master_key = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
config.require_master_key = true
# If lost the master.key just delete credentials.yml.enc and execute EDITOR=nano rails credentials:edit the Rails will generate anothers files.
# References
https://medium.com/cedarcode/rails-5-2-credentials-9b3324851336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment