[英]Rails: ActiveSupport::MessageEncryptor::InvalidMessage
[英]Rails 5.2 with master.key Digital Ocean deployment: 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 `<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
作為變量
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
。
我遇到了同樣的問題,當我第一次在我的 DigitalOcean Droplet 上部署時,每次我運行RAILS_ENV=production cap production deploy:initial
它都失敗了,抱怨這個錯誤 - ActiveSupport::MessageEncryptor::InvalidMessage
我嘗試了以下選項,但都失敗了 -
master.key
和credential.yml.enc
文件,然后再次部署。 最后一個解決方案奏效了,我只是添加了master.key
,刪除了credentials.yml.enc
文件,提交並重新部署,並且它在不更改我的deploy.rb
文件的情況下工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.