Syl*_*lar 17 ruby-on-rails ruby-on-rails-5 ruby-on-rails-5.2
我简直无法通过这条消息
缺少
secret_key_base'生产'环境,设置此字符串为rails credentials:edit(ArgumentError)
我这里有rails 5.2.0.跑来跑去EDITOR=vim rails credentials:edit:
production:
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
保存,并在终端: RAILS_ENV=production rails c
我错过了什么吗?我重新启动了服务器和同样的问题.在开发模式中没有问题.
Eri*_*ton 16
Rails 5.2.0需要一个额外的生产环境阶段:
config.require_master_key = true # in config/environments/production.rb
Run Code Online (Sandbox Code Playgroud)
没有它,Rails仍然会退回到旧secret.yml机制(现在)。
Engine Yard的Christopher Rigor 在上面写了一个简洁的帖子。相关部分:
阅读证书
如果要在生产环境中使用凭据,请将以下内容添加到
config/environments/production.rbRun Code Online (Sandbox Code Playgroud)config.require_master_key = true
一本好书还可以看到上下两面。
注意:正如@TomDogg所发现的,Rails 5.2.1似乎又有所不同,因此此答案可能仅适用于5.2.0。
7ur*_*m3n 14
保持默认为secrets.yml文件
# config/secrets.yml
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Run Code Online (Sandbox Code Playgroud)
RAILS_ENV =生产SECRET_KEY_BASE = production_test_key导轨c
配置/凭证.yml.enc:
development:
some_username: XXXXXXXXX
some_password: YYYYYYYYY
test:
some_username: XXXXXXXXX
some_password: YYYYYYYYY
production:
some_username: XXXXXXXXX
some_password: YYYYYYYYY
secret_key_base: ZZZZZZZZZ
# `secret_key_base:` must NOT be indented !
# It must be put at the very start of a new line.
# There is also no need for it in development or test environment,
# since there are no attacks to be expected.
Run Code Online (Sandbox Code Playgroud)
还要确保您遵守所有 YAML 缩进规则(即仅 2 个空格),因为未能这样做,因此我对此文件的加载会以静默方式失败。
Secret_key_base 未正确设置。这是一个没有得到足够关注的已知问题:https ://github.com/rails/rails/issues/32947
使用以下命令生成密钥:
EDITOR=vim rails credentials:edit
Run Code Online (Sandbox Code Playgroud)
记录密钥。保存在config/master.key.
SECRET_KEY_BASE=`cat config/master.key` bin/rails assets:precompile
Run Code Online (Sandbox Code Playgroud)
这就是我想到的解决方案。我真的不喜欢我被迫将其放入环境变量中。如果有人有更多信息来提请我注意 master.key 等如何工作,请发表评论。
凭证文件中没有production: development:和test:环境标签。此 DHH 帖子中的更多信息:https : //github.com/rails/rails/pull/30067
所以直接写
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)
请不要将主密钥与秘密密钥库混淆。主密钥用于打开凭据加密文件。
切换回以前的秘密系统不应该是解决方案,也不是公认的答案。
| 归档时间: |
|
| 查看次数: |
16469 次 |
| 最近记录: |