使用master.key进行数据海洋部署的Rails 5.2:ActiveSupport :: MessageEncryptor :: InvalidMessage:ActiveSupport :: MessageEncryptor :: InvalidMessage

我已将我的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 `' 

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

我还在我的ubuntu服务器上的/app_name/shared/config/上添加了master.key文件,还放置了一个env变量RAILS_MASTER_KEY 。 但仍然得到这个错误,我不知道我在这里失踪了什么。

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

一个。 从连续集成部署

1.编辑deploy.rb

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

2.将RAILS_MASTER_KEY添加为变量

  • 特拉维斯CI
  • GitLab CI

湾 使用master.key

1.编辑deploy.rb

 append :linked_files, "config/master.key" 

2.使用:linked_files上传:linked_files

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