具有master.key Digital Ocean部署的Rails 5.2:ActiveSupport :: MessageEncryptor :: InvalidMessage:ActiveSupport :: MessageEncryptor :: InvalidMessage

时间:2018-06-21 08:18:48

标签: ruby-on-rails capistrano

我已将Ruby on Rails应用程序从Rails 5.1.2迁移到Rails 5.2.0,以使用加密的机密。应用程序已成功部署到Digital Ocean Ubuntu Server。但是当我进入浏览器进行访问时,它显示以下日志。

    ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:184:in `_decrypt'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:79:in `decrypt'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:42:in `read'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:21:in `read'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:33:in `config'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:38:in `options'
  /home/deploy/apps/GeekyCricket/shared/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/core_ext/module/delegation.rb:271:in `method_missing'
  (erb):12:in `<main>'

我使用rails credentials:edit添加了加密的机密,它创建了config/credentials.yml.encmaster.key

我还在我的ubuntu服务器上的/app_name/shared/config/上添加了master.key文件,还放置了一个环境变量RAILS_MASTER_KEY。但是仍然出现此错误,我不知道我在这里缺少什么。

1 个答案:

答案 0 :(得分:2)

解决方案A和B是不同的解决方案。只需选择哪个对您有益。

a。从持续集成进行部署

1。编辑deploy.rb

set :default_env, {
  "RAILS_ENV" => "production",
  "RAILS_MASTER_KEY" => ENV["RAILS_MASTER_KEY"]
}

2。将RAILS_MASTER_KEY添加为变量

b。 master.key

的用法

1。编辑deploy.rb

append :linked_files, "config/master.key"

2。使用master.key

上传:linked_files

让我们假设我们的应用程序的根路径为/home/deploy/awesome-project。我们需要做的就是将密钥文件上传到/home/deploy/awesome-project/shared/config/master.key