aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorMauro George <maurogot@gmail.com>2015-07-04 16:53:46 -0300
committerMauro George <maurogot@gmail.com>2015-07-06 09:21:15 -0300
commit35373fd54bb11e5ced6d5d0389414567f0eb1bed (patch)
treedd2d53488d47ccc05dd3d44b8dac8a44f63d9561 /guides
parentf09678b7b1442d70636a60edb6be138614cf789f (diff)
downloadrails-35373fd54bb11e5ced6d5d0389414567f0eb1bed.tar.gz
rails-35373fd54bb11e5ced6d5d0389414567f0eb1bed.tar.bz2
rails-35373fd54bb11e5ced6d5d0389414567f0eb1bed.zip
Add to Security guides the secrets.yml
[ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/security.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/guides/source/security.md b/guides/source/security.md
index 93580d4d4e..485b108d12 100644
--- a/guides/source/security.md
+++ b/guides/source/security.md
@@ -1026,6 +1026,29 @@ Environmental Security
It is beyond the scope of this guide to inform you on how to secure your application code and environments. However, please secure your database configuration, e.g. `config/database.yml`, and your server-side secret, e.g. stored in `config/secrets.yml`. You may want to further restrict access, using environment-specific versions of these files and any others that may contain sensitive information.
+### Custom secrets
+
+Rails generates a `config/secrets.yml`. By default, this file contains the
+application's `secret_key_base`, but it could also be used to store other
+secrets such as access keys for external APIs.
+
+The secrets added to this file are accessible via `Rails.application.secrets`.
+For example, with the following `config/secrets.yml`:
+
+ development:
+ secret_key_base: 3b7cd727ee24e8444053437c36cc66c3
+ some_api_key: SOMEKEY
+
+`Rails.application.secrets.some_api_key` returns `SOMEKEY` in the development
+environment.
+
+If you want an exception to be raised when some key is blank, use the bang
+version:
+
+```ruby
+Rails.application.secrets.some_api_key! # => raises KeyError
+```
+
Additional Resources
--------------------