LoginSignup
1
0

More than 5 years have passed since last update.

encrypted_secretsの設定の順番には気をつける

Last updated at Posted at 2017-11-24

Rails 5.1のEncrypted secretsの設定に関して

config.read_encrypted_secrets=true の設定とパラメータを取得する順番は気をつける必要がある

例えば、application.rb は production.rb より前に読まれるので、 config.read_encrypted_secrets=true を production.rb で記述していて、かつ、application.rb 内で Rails.application.secrets.***** 等と呼んだ場合、
その設定値は反映されない。

また、それ以外のパラメータも secrets.yml.enc から読み込まれなくなるので、必ず config.read_encrypted_secrets=true 後に Rails.application.secrets.* を呼ぶようにすること

https://github.com/rails/rails/issues/28618
The application.rb is read before production.rb. Therefore, can not read encrypted secrets because try to read before setting config.read_encrypted_secrets to true in production.rb.
If you want to use encrypted secrets in application.rb, you need to add config.read_encrypted_secrets = true to application.rb. As following:

config.read_encrypted_secrets = true

config.action_mailer.smtp_settings = {
  address:              'smtp.sendgrid.net',
  port:                 587,
  user_name:            'apikey',
  password:             Rails.application.secrets.sendgrid_api_key,
  enable_starttls_auto: true
}

rails 5.1のEncrypted secretsについては

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0