Last active
November 13, 2023 16:14
-
-
Save alexishida/adbdc9110915ef8b07e59f304a5f50dc to your computer and use it in GitHub Desktop.
Rails 5.2 Credentials Secrets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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