Rails 5.2 与 master.key 数字海洋部署:ActiveSupport::MessageEncryptor::InvalidMessage:ActiveSupport::MessageEncryptor::InvalidMessage
Rails 5.2 with master.key Digital Ocean deployment: ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
我已将 Rails 上的 Ruby 应用程序从 Rails 5.1.2 迁移到 Rails 5.2.0 以使用加密的秘密。应用程序已成功部署到 Digital Ocean Ubuntu 服务器。但是当我进入浏览器访问时,它显示以下日志。
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.enc
和 master.key
。
我还在我的 ubuntu 服务器上的 /app_name/shared/config/
上添加了 master.key 文件,还放置了一个环境变量 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
作为变量
b。 master.key
的用法
1。编辑 deploy.rb
append :linked_files, "config/master.key"
2。使用 :linked_files
上传 master.key
让我们假设我们的应用程序的根路径是 /home/deploy/awesome-project
。我们需要做的就是将密钥文件上传到 /home/deploy/awesome-project/shared/config/master.key
.
我遇到了同样的问题,当我第一次在我的 DigitalOcean Droplet 上部署时,每次我 运行 RAILS_ENV=production cap production deploy:initial
它都失败并抱怨这个错误 - ActiveSupport::MessageEncryptor::InvalidMessage
我尝试了以下选项,但都失败了 -
- 正在删除
master.key
和 credential.yml.enc
文件,然后再次部署。
- 再次添加这两个文件并部署。
最后一个解决方案奏效了,我只是添加了 master.key
, 删除了 credentials.yml.enc
文件,提交并重新部署,它在不改变我的 deploy.rb
文件
我已将 Rails 上的 Ruby 应用程序从 Rails 5.1.2 迁移到 Rails 5.2.0 以使用加密的秘密。应用程序已成功部署到 Digital Ocean Ubuntu 服务器。但是当我进入浏览器访问时,它显示以下日志。
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.enc
和 master.key
。
我还在我的 ubuntu 服务器上的 /app_name/shared/config/
上添加了 master.key 文件,还放置了一个环境变量 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
作为变量
b。 master.key
的用法
1。编辑 deploy.rb
append :linked_files, "config/master.key"
2。使用 :linked_files
master.key
让我们假设我们的应用程序的根路径是 /home/deploy/awesome-project
。我们需要做的就是将密钥文件上传到 /home/deploy/awesome-project/shared/config/master.key
.
我遇到了同样的问题,当我第一次在我的 DigitalOcean Droplet 上部署时,每次我 运行 RAILS_ENV=production cap production deploy:initial
它都失败并抱怨这个错误 - ActiveSupport::MessageEncryptor::InvalidMessage
我尝试了以下选项,但都失败了 -
- 正在删除
master.key
和credential.yml.enc
文件,然后再次部署。 - 再次添加这两个文件并部署。
最后一个解决方案奏效了,我只是添加了 master.key
, 删除了 credentials.yml.enc
文件,提交并重新部署,它在不改变我的 deploy.rb
文件